Commit Graph

617 Commits

Author SHA1 Message Date
Akira Hatanaka
5bd7a27e96 [cxx-interop] Do not over-release objects returned by synthesized C++ methods (#76139)
Call Sema::BuildReturnStmt instead of ReturnStmt::Create so that an
implicit cast of kind ARCProduceObject is inserted in the AST.

rdar://133731973
2024-08-29 20:45:16 -07:00
swift-ci
4d062ca332 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-28 09:53:27 -07:00
Alexander Cyon
db0b5db54e [test/Interop] Fix typos (#75032) 2024-08-28 09:41:09 -07:00
Egor Zhdan
fc4f6480a8 [cxx-interop][rebranch] Do not crash for static operator()
This fixes an assertion failure:
```
Assertion failed: (isInstance() && "No 'this' for static methods!"), function getThisType, file DeclCXX.cpp, line 2636.
```

Clang changed it's handling of member call expressions in af4751738d causing the assertion to fail when synthesizing a forwarding function declaration for `static operator()`.

rdar://133257179
2024-08-15 16:31:17 +01:00
Ben Barham
df81d0a450 [Tests] XFAIL the remaining test failures on rebranch
Only a few tests remaining. XFAIL so we can test the rest of the
toolchain.
2024-08-08 14:47:18 -07:00
Alex Hoppen
66104395d7 [Sema/SourceKit] Emit same diagnostics for missing protocol requirements on the command line and in SourceKit
Some editors use diagnostics from SourceKit to replace build issues. This causes issues if the diagnostics from SourceKit are formatted differently than the build issues. Make sure they are rendered the same way, removing most uses of `DiagnosticsEditorMode`.

To do so, always emit the `add stubs for conformance` note (which previously was only emitted in editor mode) and remove all `; add <something>` suffixes from notes that state which requirements are missing.

rdar://129283608
2024-08-07 14:01:30 -07:00
Akira Hatanaka
658de4ae65 Fix a test that was failing on arm64e (#75550)
rdar://130759216
2024-07-29 20:39:24 -07:00
Andrew Trick
030f2b8e90 Merge pull request #75050 from atrick/vardecl_lifetime
[SILGen] Create SIL variable declaration scopes for trivial values.
2024-07-26 16:23:07 -07:00
Andrew Trick
a1fe258692 Update tests for new trivial moves and extend_lifetimes. 2024-07-26 08:27:48 -07:00
Finagolfin
15e1c73969 [android][test] Enable several C++ Interop and other tests
Also, fix lit.cfg for running the test suite natively in Android and mark one
SILOptimizer executable_test as such.
2024-07-20 17:56:51 +05:30
Gábor Horváth
e836e2caeb Merge pull request #75176 from swiftlang/gaborh/inheritance-2
[cxx-interop] Fix wrong field offsets with value types using inheritance
2024-07-18 03:59:47 -07:00
Gabor Horvath
d0e6d2f426 [cxx-interop] Fix input header paths in a test
rdar://131629163
2024-07-15 12:00:17 +01:00
Gabor Horvath
ce3fa734ce [cxx-interop] Fix wrong field offsets with value types using inheritance
Instead of adding opaque fields for the base subobjects this patch
introduces a recursive walk to add all the base fields to the generated
Swift struct.

rdar://126754931
2024-07-11 17:20:18 +01:00
Egor Zhdan
14f39beca0 Merge pull request #75058 from swiftlang/egorzhdan/attrs-clone
[cxx-interop] Clone all of the attributes from base method correctly
2024-07-09 11:47:18 +01:00
Egor Zhdan
b50955144e [cxx-interop] Clone all of the attributes from base method correctly
If a C++ `struct Base` declares a method with a Clang attribute that Swift is able to import, and `struct Derived` inherits from `Base`, the method should get cloned from `Base` to `Derived` with its attributes.

Previously we were only cloning one attribute at most due to a bug in `cloneImportedAttributes`. DeclAttributes is an intrusively linked list, and it was being made invalid while iterating over it: `otherDecl->getAttrs().add(attrs)` iterates over the list and calls `otherDecl->add(eachElement)`, which invalidates the iterator after the first iteration.
2024-07-08 15:48:20 +01:00
Egor Zhdan
daaec01d29 [cxx-interop] Adjust another IRGen test for rebranch
This fixes `Interop/Cxx/class/method/methods-this-and-indirect-return-irgen-itanium.swift` by adjusting the expected function signature.

On rebranch, the actual signature is:
```
define linkonce_odr void @_ZN10HasMethods28nonConstPassThroughAsWrapperEi(ptr dead_on_unwind noalias writable sret(%struct.NonTrivialInWrapper) align 4 %agg.result, ptr noundef nonnull align 1 dereferenceable(1) %this, i32 noundef %a)
```

rdar://127263407
2024-07-08 13:51:33 +01:00
Egor Zhdan
d8e8216895 [cxx-interop] Adjust an IRGen test for rebranch
This fixes `Interop/Cxx/class/returns-large-class-irgen.swift` by adjusting the expected function signature.

On rebranch, the actual signature is:
```
define void @_Z21funcReturnsLargeClassv(ptr dead_on_unwind noalias writable sret(%struct.LargeClass) align 8 %agg.result)
```

rdar://127263407
2024-07-08 13:44:23 +01:00
Egor Zhdan
34c796d100 [cxx-interop] Add a test for instantiation of a default destructor
This is a follow-up to f56fa41.

rdar://124061505
2024-07-04 17:35:01 +01:00
Akira Hatanaka
1b38ca929d Remove reference to attribute group in test (#74816)
rdar://130759216
2024-06-28 16:18:23 -07:00
Akira Hatanaka
42bc49d3fe Add a new parameter convention @in_cxx for non-trivial C++ classes that are passed indirectly and destructed by the caller (#73019)
This corresponds to the parameter-passing convention of the Itanium C++
ABI, in which the argument is passed indirectly and possibly modified,
but not destroyed, by the callee.

@in_cxx is handled the same way as @in in callers and @in_guaranteed in
callees. OwnershipModelEliminator emits the call to destroy_addr that is
needed to destroy the argument in the caller.

rdar://122707697
2024-06-27 09:44:04 -07:00
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