Commit Graph

597 Commits

Author SHA1 Message Date
Alex Lorenz
af36238004 Merge pull request #74640 from hyp/eng/virtual-destructor-vtable-ref-irgen-linux-android
[cxx-interop] ensure that the body of implicit virtual destructor is …
2024-06-26 10:32:51 -07:00
Alex Lorenz
9c4232c89d Merge pull request #74722 from hyp/eng/destructor-cxx-interop-exc-cleanup
[cxx-interop] ensure destructors referenced only by the exception cle…
2024-06-26 10:32:27 -07:00
Alex Lorenz
781a9fc1aa [cxx-interop] ensure destructors referenced only by the exception cleanup landing pad in the constructor's initializer are picked up to be candidates for potential emission into one LLVM IR module
A C++ record destructor that is called implicitly in the landing pad cleanup code of a constructor after a field is initialized might only be referenced there, so the Clang decl finder should pick it up when scanning the AST for interesting Decls that might have to be emitted into one LLVM IR module.
2024-06-25 22:13:19 -07:00
Alex Lorenz
f4949bd8dc fix 2024-06-25 18:22:40 -07:00
Akira Hatanaka
11696cd452 [SILGen] Fix assertion failure when opaque value is enabled (#74676)
emitManagedParameter assumes the passed value has an address type and
calls forBorrowedAddressRValue when the parameter convention is
Indirect_In_Guaranteed.

Call forBorrowedObjectRValue instead when the type isn't an address
type.

rdar://130456931
2024-06-25 11:49:34 -07:00
Alex Lorenz
cd1ca50c63 [cxx-interop] ensure that the body of implicit virtual destructor is defined before emitting the clang decl for it
This ensures that the destructor definition is emitted into the module's LLVM IR, fixing a linker error.
2024-06-21 17:00:15 -07:00
Gábor Horváth
2fb164b13f Merge pull request #74334 from apple/gaborh/name-collision-tests
[cxx-interop] Fix inadvertently renaming static method to Mutating
2024-06-19 12:29:00 +02:00
Akira Hatanaka
1b0df4eefe [SILGen] Fix a crash when a closure is converted to a pointer to a function returning a non-trivial C++ type (#73561)
When emitting a native-to-foreign thunk, pass the thunk's result address parameter to the native function if both the thunk and the native function return their results indirectly and the thunk is not for an async function.

Also, remove an outdated assertion.

rdar://124501345
2024-06-18 15:03:44 -07:00
Gabor Horvath
d17d17e96e [cxx-interop] Fix inadvertently renaming static method to Mutating
When we have both const and non-const version of a function, we import
the non-cont version with the "Mutating" suffix. This logic, however, is
redundant for static member functions as those can never be marked as
"const" since they don't have a "self" or "this" to mutate.

rdar://120858502
2024-06-18 16:19:23 +01:00
Egor Zhdan
d79c87638d Merge pull request #74435 from apple/egorzhdan/inherited-move-only-test
[cxx-interop] Fix a test for move-only types
2024-06-15 02:42:47 +01:00
Egor Zhdan
71d02efcec [cxx-interop] Fix a test for move-only types
rdar://128424443
2024-06-14 20:23:33 +01:00
Alex Lorenz
2039b8d254 [cxx-interop] import static operator call from C++23 as member callAsFunction functions in Swift to preserve source compatibility 2024-06-12 09:11:15 -07:00
Egor Zhdan
6637eb9ec1 Merge pull request #73942 from apple/egorzhdan/const-ref-borrow-test
[cxx-interop] Re-enable a test for borrowing const ref
2024-05-31 15:04:00 +01:00
Egor Zhdan
7ce9cada2d [cxx-interop] Re-enable a test for borrowing const ref
We were trying to run an execution test in a non-executable CI job.

rdar://111065819
2024-05-30 16:54:52 +01:00
Akira Hatanaka
b5cc5615bd [SILGen] Fix a crash when a closure is converted to a block returning a value indirectly (#73520) 2024-05-23 21:22:32 -07:00
Andrew Trick
51e272f251 Disable test/Interop/Cxx/class/move-only/inherited-field-access-silgen.swift
This test does not produce consistent SIL across various test
configurations. We have a discrepancy on whether an argument is
@in_guaranteed vs. @guaranteed.

Tracked in rdar://128424443.
2024-05-20 16:01:30 -07:00
Kavon Farvardin
090f48f6f3 CxxInterop: resolve GH#70246
https://github.com/apple/swift/issues/70246
2024-05-14 17:45:44 -07:00
Kavon Farvardin
5ae2f6bd25 CxxInterop: use Unsafe*Pointer for move-only 2024-05-14 17:44:22 -07:00
Kavon Farvardin
21d147d3d0 Revert "CxxInterop: use workaround unconditionally"
This reverts commit 1036031d06.
2024-05-14 16:43:05 -07:00
Kavon Farvardin
1036031d06 CxxInterop: use workaround unconditionally
We haven't yet solved the underlying issue in rdar://128013193 and the
workaround to make it conditionally use the better importing strategy of
Unsafe{Mutable}Pointer no longer will apply, since NoncopyableGenerics
is here.
2024-05-13 13:08:25 -07:00
Kavon Farvardin
7a83af6925 Revert "CxxInterop: remove checks for NoncopyableGenerics"
This reverts commit b04be89dce.
2024-05-13 10:46:30 -07:00
Kavon Farvardin
b04be89dce CxxInterop: remove checks for NoncopyableGenerics
It will always evaluate to true now; it's not experimental. This change
effectively reverts the following:
 - 6140ba1079
 - 78eee32467
2024-05-08 10:49:12 -07:00
Kavon Farvardin
0420310623 NCGenerics: it's no longer "experimental"
resolves rdar://127701059
2024-05-08 10:49:12 -07:00
Akira Hatanaka
428fe21855 [SILGen] Fix a bug where the wrong convention was being used for computing the type of a closure thunk (#73299)
The ObjC selector family convention was being used instead of the C
function type convention.

rdar://127090209
2024-04-29 18:03:59 -07:00
Egor Zhdan
b330376a43 [cxx-interop] Pull changes from swift-6 compat mode into swift-5.9
This gives projects using C++ interop compat mode 5.9 access to the new features such as virtual methods and move-only types.

rdar://126485814
2024-04-24 11:53:31 +01:00
Egor Zhdan
70c3e432f6 Merge pull request #73055 from apple/egorzhdan/ncg-unsafepointer
[cxx-interop] Import `NonCopyable*` as `OpaquePointer` if noncopyable generics are disabled
2024-04-24 00:45:25 +01:00
Egor Zhdan
6140ba1079 [cxx-interop] Do not try to use UnsafePointer<T> for non-copyable T when adding base member accessors 2024-04-23 18:47:55 +01:00
Egor Zhdan
78eee32467 [cxx-interop] Import NonCopyable* as OpaquePointer if noncopyable generics are disabled
C++ pointer type `T*` is generally imported as `Unsafe(Mutable)Pointer<T>`. However, if `T` is non-copyable in Swift (e.g. it has a deleted C++ copy constructor), using `UnsafePointer<T>` type requires noncopyable generics to be enabled.

This was causing assertion failures when building SwiftCompilerSources in https://github.com/apple/swift/pull/72912.
2024-04-23 18:47:55 +01:00
Egor Zhdan
5fce3f9d5b Merge pull request #71715 from eltociear/patch-50
Fix typo in runtime-polymorphism.swift
2024-04-22 12:36:41 +02:00
Egor Zhdan
cfe27287da Merge pull request #72903 from apple/egorzhdan/zero-init
[cxx-interop] Zero-initialize C++ structs when calling their default constructors
2024-04-17 13:39:21 +01:00
Akira Hatanaka
d76dbb1a64 [SILGen] Fix a bug where the wrong convention was being used for lowering a closure to a C++ function pointer (#73039)
Use the C function pointer convention instead of the block convention.

rdar://122977380
2024-04-16 15:18:50 -07:00
Egor Zhdan
bac5d0e9a1 [cxx-interop] Zero-initialize C++ structs when calling their default constructors
When Swift imports C structs, it synthesizes an initializer that takes no arguments and zero-initializes the C struct.

When C++ interop is enabled, Clang treats all C structs as if they were C++ structs. This means that some of the C structs will get a default constructor implicitly generated by Clang. This implicit default constructor will not zero-initialize trivial fields of the struct.

This is a common source of confusion and subtle bugs for developers who try to enable C++ interop in existing projects that use C interop and rely on zero-initialization of C structs.

rdar://115909532
2024-04-16 13:42:02 +01:00
Egor Zhdan
802f20ec00 [cxx-interop][IRGen] Assign Clang function types to copy constructors
This fixes an assertion failure when building certain projects for arm64e with `-use-clang-function-types` Swift compiler flag:
```
Expected non-null Clang type for @convention(c)/@convention(block) function but found nullptr
```

rdar://121227452
2024-04-03 19:26:32 +01:00
Egor Zhdan
1be7230876 [cxx-interop] Use C++17 standard by default
Clang is using C++17 standard version by default since Clang 16.

Swift’s ClangImporter should do the same, to make sure that clients who run clang and then swiftc without explicit std version see consistent behavior.

rdar://125777068
2024-04-02 16:23:32 +01:00
Karoy Lorentey
9725b892cc [test] More test updates 2024-03-18 13:27:46 -07:00
Kavon Farvardin
2951162527 Test: disable move-only-cxx-value-type.swift
The test was relying on UnsafeMutablePointer (UMP) not having a Copyable
 requirement. Those Copyable requirements are more prominent when using
the new infrastructure for noncopyable types. Since UMP is planned to
have `~Copyable` on its generic parameter quite soon, this shouldn't
remain broken for too long.
2024-03-14 23:10:44 -07:00
Egor Zhdan
2c6cc4a6e5 Merge pull request #72186 from apple/egorzhdan/swift-bridging-modulemap
[cxx-interop] Refer to `SwiftBridging` module from `usr/include/module.modulemap`
2024-03-11 19:01:33 +00:00
Nate Chandler
dff0b2efaa [SILGen] Allocs for VDs are var_decl.
Annotate alloc_stack instructions that correspond to VarDecls with the
var_decl flag.
2024-03-08 22:28:22 -08:00
Egor Zhdan
d494632e98 [cxx-interop] Refactor: move swift/bridging source elsewhere for better testability
rdar://123334601
2024-03-08 20:13:27 +00:00
Doug Gregor
59d1846b59 De-XFAIL a test that now works with noncopyable generics 2024-03-07 15:32:13 -08:00
Egor Zhdan
b19ca43a43 [cxx-interop] Fix virtual method tests on non-macOS 2024-03-03 00:49:45 +00:00
Egor Zhdan
8ead7224b7 [cxx-interop] Overhaul virtual method support
This adds a new implementation of virtual method dispatch that handles reference types correctly.

Previously, for all C++ types an invocation of a virtual method would actually get dispatched statically. For value types this is expected and matches what C++ does because of slicing. For reference types, however, this is incorrect, we should do dynamic dispatch.

rdar://123852577
2024-03-01 19:45:58 +00:00
Egor Zhdan
d3a0bf4ea8 Merge pull request #71836 from apple/egorzhdan/cxx-tests-swift-6
[cxx-interop] Run tests with `swift-6` compat mode
2024-02-26 10:52:03 +00:00
Doug Gregor
0c9c734f7e Merge pull request #71722 from DougGregor/diagnostic-style-swift-default 2024-02-24 14:42:38 -10:00
Egor Zhdan
78b9de1391 [cxx-interop] Run tests with swift-6 compat mode 2024-02-23 16:24:14 +00:00
Akira Hatanaka
b3f302b96b [IRGen] Fix a bug where an argument wasn't annotated with sret (#71459)
Fix a bug in expandExternalSignatureTypes where it wasn't annotating a function call parameter type with sret when the result was being returned indirectly.

The bug was causing calls to ObjC methods that return their results indirectly to crash.

Additionally, fix the return type for C++ constructors computed in expandExternalSignatureTypes. Previously, the return type was always void even on targets that require constructors to return this (e.g., Apple arm64), which was causing C++ constructor thunks to be emitted needlessly.

Resolves rdar://121618707
2024-02-22 14:14:47 -08:00
Akira Hatanaka
97a814805a [IRGen] Make sure a C++ constructor thunk is called when it's needed (#71790)
This fixes a bug where the thunk for a C++ constructor call wasn't being
called when the constructor was called the second time.
2024-02-22 07:05:07 -08:00
Alex Lorenz
6312fc05cc [interop] adopt a swift-6 interoperability mode for new features in the next release 2024-02-21 09:27:45 -08:00
Kavon Farvardin
f296d8e158 NCGenerics: mass XFAIL tests
It's easier to get a handle on regressions while working through
failures if the tests that are known to not pass are XFAIL'd for
NoncopyableGenerics.
2024-02-20 18:26:05 -05:00
Doug Gregor
8cd2f34654 Generalize tests for both diagnostic styles, or force the LLVM style
These tests are using FileCheck to check the result of diagnostic
formatting in ways that don't match the new formatter. Force the old
formatter or, where possible, generalize so that they match both
formatters.
2024-02-19 02:48:37 -10:00