Commit Graph

617 Commits

Author SHA1 Message Date
zoecarver
c0416b1450 [cxx-interop] Tests for the recent diganostics and fix-its. 2023-02-20 15:58:38 -08:00
Egor Zhdan
fc5215f0f8 [cxx-interop] Treat C++ structs that store iterators as unsafe
C++ types that store pointers as fields are treated as unsafe in Swift. Types that store other types that in turn store pointers are also treated as unsafe.

Types that store raw C++ iterators are also treated as unsafe in Swift. However, a type that stores another type that stores a raw iterator was previously imported as safe. This change fixes that.

rdar://105493479
2023-02-15 13:50:35 +00:00
Zoe Carver
c1a50cf00c Merge pull request #63506 from zoecarver/runtime-crash-ref-in-ctor 2023-02-12 10:04:17 -08:00
zoecarver
c00c762146 [tests] Fix SILGen tests to have Windows mangling 2023-02-10 09:27:11 -08:00
zoecarver
4f72147279 [cxx-interop] Use "c function conventions" for static methods and ctors (not "cxx method conventions").
Otherwise we will incorrectly use the "self" type's conventions when lowering the parameters (off-by-one).
2023-02-09 17:10:16 -08:00
Egor Zhdan
9e35a175e9 [cxx-interop] Members of private base classes should not be exposed
Trying to use members of C++ private base classes from Swift causes an assertion failure in ClangImporter:

```
<build dir>/swift/lib/swift/macosx/arm64/libcxxshim.h:2:66: error: cannot cast 'A' to its private base class 'B'
To __swift_interopStaticCast(From from) { return static_cast<To>(from); }
                                                                 ^
```

Such members should not be exposed.

rdar://103871000
2023-01-04 13:41:50 +00:00
Egor Zhdan
745d92d9cb [cxx-interop] Allow instantiated operator methods to serve as protocol conformance witnesses
If a templated C++ class declares an operator as a member function, and is instantiated using a typedef or a using-decl on the C++ side, it previously could not be conformed to a Swift protocol that requires the operator function despite matching signatures.

This was due to a Swift name lookup issue: operators, unlike regular member functions, are found by doing an unqualified lookup. Since C++ class template specializations and their members are not added to `SwiftLookupTable`, when doing qualified lookup members are searched by looking at all of the members of the specialization and choosing the ones with matching names. With unqualified lookup, we cannot rely on knowing the right specialization and need to search for all the operators in a given module.

This change adds synthesized operator thunks to `SwiftLookupTable` to make them discoverable by unqualified lookup.
2023-01-03 13:57:08 +00:00
Egor Zhdan
abfd790bb4 Merge pull request #62575 from apple/egorzhdan/cxx-disambiguate
[cxx-interop] Disambiguate const and non-const methods consistently
2022-12-19 17:36:03 +00:00
Egor Zhdan
168ef490af [cxx-interop] Disambiguate const and non-const methods consistently
When importing a C++ struct that contains two methods that only differ in const-ness, we append `Mutating` to the name of the non-const method to make it possible to call from Swift unambiguously.

Unfortunately that logic was dependent on the order in which we import methods of a class: the `Mutating` suffix was added when another method with the same name was already imported.

This caused lookup failures, and the behavior was incorrect when the pair of methods return instances of an unsafe type: the const overload was renamed as `Unsafe` properly, but the non-const overload was not renamed.
2022-12-19 15:03:04 +00:00
Mike Pinkerton
742d47893d Failing tests for runtime polymorphism. 2022-12-15 16:14:13 -05:00
Zoe Carver
9850906570 Merge pull request #62330 from zoecarver/conforms-to-attr
[cxx-interop] Add ability to specify protocol conformance on C++ side.
2022-12-13 16:28:31 -08:00
Butta
dc06fc0160 [android][test] Disable new C++ Interop test
Also, add flag and comment from `build-script-util` that was missed in the
recent Python translation, #38507.
2022-12-12 01:11:46 +05:30
Alex Lorenz
934183f854 [cxx-interop] Emit IR for std::get in structured bindings declaration 2022-12-07 15:54:11 -08:00
zoecarver
665d3e1db4 [cxx-interop] Add diagnostics for explicit protocol conformance on the C++ side. 2022-12-02 10:04:48 -08:00
zoecarver
5eb7c7a6cf [cxx-interop] Add ability to specify protocol conformance on C++ side. 2022-11-30 17:26:15 -07:00
Egor Zhdan
c307ccc37f [cxx-interop] Emit IR for custom operator new
Fixes https://github.com/apple/swift/issues/62182
2022-11-23 13:15:50 +00:00
Saleem Abdulrasool
2ed5bdf01e test: enable C++ class inheritance test on Windows
Now that this test builds on Windows, we can finally unmark it as
UNSUPPORTED on windows.
2022-11-09 08:20:56 -08:00
Butta
4b22ca1550 [android][test] Fix two C++ Interop tests that were split off for Android, enable two more new ones, and set an executable_test
Also, make some related changes, like updating a path in the Android doc, making sure the
`unknown` vendor is always used, and using `CPU` instead of `CODEGENERATOR`.
2022-11-08 22:13:36 +05:30
Egor Zhdan
6ca60b075e [cxx-interop] Emit IR for virtual methods
Even if a virtual method is not used directly from Swift, it might get emitted into the vtable, and in that case the IR for it should be emitted to avoid linker errors.

Fixes https://github.com/apple/swift/issues/61730.
2022-11-01 13:10:44 -07:00
Allan Shortlidge
0fd7e24724 Tests: Add REQUIRES: CPU=x86_64 in a few Interop tests.
These tests fail when run locally on Apple Silicon Macs because they specify `-target x86_64-apple-macosx10.9` instead of `%target-cpu-apple-macosx10.9`. Tests that have architecture specific output should require that architecture.
2022-10-29 14:20:17 -07:00
Nate Chandler
ed623d7b64 [NFC] Shortened SIL [init] flag.
Instead of writing out [initalization] for some instructions, use [init]
everywhere.
2022-10-27 10:38:54 -07:00
Mike Pinkerton
5c6348c6ce Test various nodiscard return cases. 2022-10-25 11:03:06 -04:00
Egor Zhdan
49405aaedb Merge pull request #61638 from apple/egorzhdan/cxx-destructor-irgen
[cxx-interop] Emit IR for destructors of temporary C++ values
2022-10-21 18:23:52 +01:00
Egor Zhdan
93e7427ed2 [cxx-interop] Emit IR for destructors of temporary C++ values
This fixes the "undefined reference" linker errors.

rdar://101092732
2022-10-21 15:34:04 +01:00
Egor Zhdan
5a3bb14d83 [cxx-interop] Fix tests that passed -module-name Swift
`Swift` is the name of the Swift standard library module. Creating another module with this name breaks assumptions in the compiler and caused these two tests to fail.
2022-10-19 15:00:50 +01:00
zoecarver
001033763a Fix tests. 2022-10-14 13:33:21 -07:00
Saleem Abdulrasool
5d832bf946 Merge pull request #61524 from compnerd/import
test: add `CxxShim` import for test
2022-10-11 08:10:19 -07:00
Saleem Abdulrasool
6519524e0a Merge pull request #61500 from compnerd/mutable
ClangImporter: simplify logic for mutability attribute
2022-10-10 09:55:10 -07:00
Saleem Abdulrasool
79ad745c9c test: add CxxShim import for test
This test would fail on windows when built with assertions as the
`CxxShim` module was not imported.  Add the missing import which is
required to enable this test on Windows.
2022-10-09 16:58:50 -07:00
Saleem Abdulrasool
642bffbe7d Merge pull request #61512 from etcwilde/ewilde/unblock-windows-bot
Unblock mutability-annotations-typechecker failing test
2022-10-09 15:54:33 -07:00
Evan Wilde
af126e577f Unblock mutability-annotations-typechecker failing test
Failing test info:

******************** TEST 'Swift(windows-x86_64) :: Interop/Cxx/class/mutability-annotations-typechecker.swift' FAILED ********************
Script:
--
: 'RUN: at line 1';   't:\\swift\\bin\\swift-frontend.exe' -target x86_64-unknown-windows-msvc  -module-cache-path T:\swift\swift-test-results\x86_64-unknown-windows-msvc\clang-module-cache -swift-version 4  -define-availability 'SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -define-availability 'SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2' -define-availability 'SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0' -define-availability 'SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4' -define-availability 'SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0' -define-availability 'SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5' -define-availability 'SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0' -define-availability 'SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4' -define-availability 'SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0' -define-availability 'SwiftStdlib 5.8:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999' -typo-correction-limit 10   -enable-source-import -sdk 'C:\\Users\\swift-ci\\jenkins\\workspace\\swift-PR-windows\\swift\\test\\Inputs\\clang-importer-sdk' -I 'C:\\Users\\swift-ci\\jenkins\\workspace\\swift-PR-windows\\swift\\test\\Inputs\\clang-importer-sdk\\swift-modules'   -typecheck -I C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class/Inputs C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class\mutability-annotations-typechecker.swift -enable-experimental-cxx-interop -verify -verify-additional-file C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class/Inputs/mutability-annotations.h
--
Exit Code: 1

Command Output (stdout):
--
$ ":" "RUN: at line 1"
$ "t:\\swift\\bin\\swift-frontend.exe" "-target" "x86_64-unknown-windows-msvc" "-module-cache-path" "T:\swift\swift-test-results\x86_64-unknown-windows-msvc\clang-module-cache" "-swift-version" "4" "-define-availability" "SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" "-define-availability" "SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2" "-define-availability" "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0" "-define-availability" "SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4" "-define-availability" "SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0" "-define-availability" "SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5" "-define-availability" "SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0" "-define-availability" "SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4" "-define-availability" "SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0" "-define-availability" "SwiftStdlib 5.8:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" "-typo-correction-limit" "10" "-enable-source-import" "-sdk" "C:\\Users\\swift-ci\\jenkins\\workspace\\swift-PR-windows\\swift\\test\\Inputs\\clang-importer-sdk" "-I" "C:\\Users\\swift-ci\\jenkins\\workspace\\swift-PR-windows\\swift\\test\\Inputs\\clang-importer-sdk\\swift-modules" "-typecheck" "-I" "C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class/Inputs" "C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class\mutability-annotations-typechecker.swift" "-enable-experimental-cxx-interop" "-verify" "-verify-additional-file" "C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class/Inputs/mutability-annotations.h"
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class/Inputs/mutability-annotations.h:28:6: error: expected warning not produced
  // expected-warning@+1 {{attribute 'nonmutating' is ignored when combined with attribute 'mutating'}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class/Inputs/mutability-annotations.h:41:6: error: expected warning not produced
  // expected-warning@+1 {{attribute 'nonmutating' has no effect without any mutable fields}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class/Inputs/mutability-annotations.h:46:6: error: expected warning not produced
  // expected-warning@+2 {{attribute 'nonmutating' has no effect without any mutable fields}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\swift-ci\jenkins\workspace\swift-PR-windows\swift\test\Interop\Cxx\class/Inputs/mutability-annotations.h:47:6: error: expected warning not produced
  // expected-warning@+1 {{attribute 'nonmutating' has no effect on non-const method}}
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: command failed with exit status: 1

--

********************
2022-10-09 11:34:08 -07:00
Saleem Abdulrasool
ad1bd8e685 Update mutability-annotations.h 2022-10-08 20:33:17 -07:00
Saleem Abdulrasool
7efe37f4c1 Update functions.swift 2022-10-08 19:44:01 -07:00
Butta
561f03a0fe [android][test] Tweaks to get the new failing C++ Interop tests working 2022-09-25 13:51:17 +05:30
Zoe Carver
762e0baa50 Merge pull request #61217 from zoecarver/base-classes-as-fields
[cxx-interop] Add base classes as opaque fields when lowering in IRGen.
2022-09-21 09:22:12 -07:00
zoecarver
63c4758dad [cxx-interop] Add base classes as opaque fields when lowering in IRGen.
Much of IRGen is built around fields (example: enum packing/unpacking). This is a simpler/less bug-prone way to do it.
2022-09-20 20:20:46 -07:00
Evan Wilde
b0180c3804 Add generator requirements to cxx interop tests
The constructors-copy-irgen and constructors-irgen tests check code
generated by the X86 and ARM backends and will fail spectacularly if we
don't have the backend enabled. Adding the necessary codegenerator
requirements to those tests.
2022-09-17 18:22:43 -07:00
Nate Chandler
af6749e84c [TypeLowering] Mark lexical when marking non-trivial.
In addition to starting all RecursiveProperties values which are
NonTrivial as Lexical, also mark instances of the structs which are
modified to become NonTrivial to simultaneously become Lexical.
2022-09-11 16:11:09 -07:00
Anthony Latsis
a65f1a161e Gardening: Migrate test suite to GH issues: Interop 2022-08-31 05:20:25 +03:00
Nate Chandler
3c78a0bb90 [SILGen] Only lexical types get lexical lifetimes.
Only emit `begin_borrow [lexical]` and only mark `alloc_stack`s
`[lexical]` when the variable in question's lifetime is lexical, not
eager move.
2022-08-22 15:28:00 -07:00
Mishal Shah
91b2abe996 Merge pull request #60531 from apple/pull-request-rebranch
Merge `rebranch` into  `main` to support llvm-project `stable/20220421`
2022-08-15 17:10:56 -07:00
zoecarver
39af79f491 [cxx-interop] Re-enable debug mangling. 2022-08-12 15:57:56 -07:00
swift-ci
41366ebccd Merge remote-tracking branch 'origin/main' into rebranch 2022-08-12 03:54:16 -07:00
Egor Zhdan
4245bd582c Merge pull request #60389 from apple/egorzhdan/cxx-record-lookup-ext
[cxx-interop] Clang member lookup should not look into Swift extensions
2022-08-12 11:43:36 +01:00
Egor Zhdan
51a1176d90 [cxx-interop] Clang member lookup should not look into Swift extensions
Calling `NominalTypeDecl::lookupDirect` triggers deserialization of Swift extensions for the type. `ClangRecordMemberLookup` shouldn't assume it is allowed to deserialize Swift extensions for the given C++ type: there might be extensions which reference the module that is currently being imported, which causes circular request dependency errors.
2022-08-08 17:05:25 +01:00
swift-ci
d81ba4efc7 Merge remote-tracking branch 'origin/main' into rebranch 2022-08-05 05:33:06 -07:00
Ehud Adler
f11e2afe07 [cxx-interop] Always import cxx shim when cxx-interop is enabled (#60336) 2022-08-05 08:28:47 -04:00
swift-ci
cbe82b6bfb Merge remote-tracking branch 'origin/main' into rebranch 2022-08-02 06:14:04 -07:00
Ehud Adler
379fc1f0a4 [cxx-interop] Fix issue where multiple records in a module containing the same meth… (#60338) 2022-08-02 09:01:56 -04:00
swift-ci
30a3db1769 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-25 08:34:12 -07:00