Commit Graph

1876 Commits

Author SHA1 Message Date
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
smonteiro2
684e9ebf0c [cxx-interop] Implements CxxMutableSpan, created from an UnsafeMutableBufferPointer
* Added tests for generic functions
* Add some tests for mutable spans
* Initialize ConstSpan from UnsafeMutableBufferPointer
* Change hardening flag
2024-07-19 10:38:52 +01:00
smonteiro2
24fc755024 Add _const to Swift declaration names of const types
This change is necessary to differentiate between C++ const and non-const types in Swift.
For instance, `const int` and `int` would both be printed as `CInt` in Swift.
After this change, `const int` is stored as `CInt_const`
2024-07-18 14:13:57 +01:00
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
535ea9720f Merge pull request #75065 from swiftlang/egorzhdan/rebranch-concepts-test
[cxx-interop] Adjust a concepts test for rebranch
2024-07-09 14:51:10 +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
2c00ae939b [cxx-interop] Adjust a concepts test for rebranch
Clang now includes concepts in the mangled names of C++ functions: 4b163e343c

This adjusts the test to verify that we don't transitively emit the symbols referenced from the requires expression. Those symbols shouldn't be emitted because they are not executed.

rdar://127263407
2024-07-08 17:59:21 +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
b7fc492b14 [cxx-interop] Conditionally re-enable a test for std::function, pt 3
This also disables the test on Fedora.

rdar://125816354
2024-07-05 16:12:40 +01:00
Susana Monteiro
bb16e50237 Merge pull request #74970 from swiftlang/susmonteiro/cxx-span-class-tests
[cxx-interop] Add tests for std::span inside struct
2024-07-05 12:13:46 +01:00
Egor Zhdan
3961729463 Merge pull request #74936 from swiftlang/egorzhdan/default-dtor-inst-test
[cxx-interop] Add a test for instantiation of a default destructor
2024-07-04 23:52:17 +01:00
Egor Zhdan
e34992537e Merge pull request #74968 from swiftlang/egorzhdan/std-function-test-reenable-pt2
[cxx-interop] Conditionally re-enable a test for `std::function`, pt 2
2024-07-04 18:37:04 +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
smonteiro2
f75a2f596f Add tests for span inside struct 2024-07-04 16:02:27 +01:00
Egor Zhdan
6c17565bd3 [cxx-interop] Conditionally re-enable a test for std::function, pt 2
The post-commit CI uses a slightly different version of UBI.

rdar://125816354
2024-07-04 15:28:49 +01:00
Egor Zhdan
b6844f52ac Merge pull request #74790 from swiftlang/egorzhdan/objcbool-template-param
[cxx-interop] Ban ObjCBool from being substituted into C++ templates
2024-07-04 14:19:24 +01:00
Egor Zhdan
af311ff003 [cxx-interop] Conditionally re-enable a test for std::function
Let's re-enable the test on all platforms except Ubuntu 22.04 and UBI 9, which are shipped with libstdc++11.

rdar://125816354
2024-07-03 12:36:13 +01:00
Susana Monteiro
686d1b4c30 Merge pull request #74783 from susmonteiro/susmonteiro/cxx-span-from-ubpointer
[cxx-interop] Implements constructor for std::span from UnsafeBufferPointer
2024-07-01 19:02:05 +01:00
susmonteiro
e86099c26d [cxx-interop] Implements constructor for std::span from UnsafeBufferPointer
Tests: init span from UnsafeBufferPointer, for loop, map, filter, init Array from span, span of strings
2024-07-01 16:07:28 +01:00
Egor Zhdan
39f826c9b8 Merge pull request #74822 from swiftlang/egorzhdan/frt-safety-heuristic-test
[cxx-interop] Add tests for methods of reference types returning reference types
2024-07-01 12:44:34 +01:00
Akira Hatanaka
1b38ca929d Remove reference to attribute group in test (#74816)
rdar://130759216
2024-06-28 16:18:23 -07:00
Egor Zhdan
deea1e8b02 [cxx-interop] Add tests for methods of reference types returning reference types
rdar://130686970 / resolves https://github.com/swiftlang/swift/issues/64315
2024-06-28 18:32:17 +01:00
susmonteiro
9aa132bd71 [cxx-interop] Enable hardening when running tests for std::span
Add tests that receive std::span as param
2024-06-28 15:01:23 +01:00
Pavel Yaskevich
0987555a9c [Tests] NFC: Temporarily disable test/Interop/Cxx/stdlib/use-std-function.swift
The test is blocking nightly toolchains.
2024-06-27 21:12:40 -07:00
Egor Zhdan
fe5b0097bc [cxx-interop] Ban ObjCBool from being substituted into C++ templates
This fixes a compiler crash when calling a templated C++ function with a parameter of type `ObjCBool` from Swift. The compiler now emits an error for this.

Previously the following would happen:
1. Swift starts to emit SILGen for a call expression `takeTAsConstRef(ObjCBool(true))`.
2. `takeTAsConstRef` is a templated C++ function, so Swift asks Clang to instantiate a `takeTAsConstRef` with a built-in Obj-C boolean type.
3. Swift gets an instantiated function template back that looks like this: `void takeTAsConstRef(_Bool t) { ... }`.
4. Swift's ClangImporter begins to import that instantiated function.
5. Since the parameter type is not spelled as `BOOL`, the parameter is not imported as `ObjCBool`. Instead, it's imported as regular Swift `Bool`.
6. Swift realizes that the types don't match (`ObjCBool` vs `Bool`), tries to apply any of the known implicit conversions, fails to do so, crashes.

rdar://130424969
2024-06-27 19:48:57 +01: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
Egor Zhdan
9d6e36b512 Merge pull request #74771 from susmonteiro/susmonteiro/cxx-span-fix-failing-test
[cxx-interop] Add requirement executable_test
2024-06-27 17:33:36 +01: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
susmonteiro
b3107586f6 [cxx-interop] Add requirement executable_test
rdar://130527435
2024-06-26 12:32:09 +01:00
Alex Lorenz
466ae71e75 Merge pull request #74494 from hyp/eng/android-memcpy-nonnull-me-timbers
[cxx-interop] Builtin functions should ignore return type nullability…
2024-06-25 23:39:47 -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
Alex Lorenz
6a402a106e fix windows test 2024-06-25 16:24:02 -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
fahadnayyar
0d59587eba Merge pull request #73559 from fahadnayyar/attribute-operator-star
[cxx-interop] Import the attributes from clang decl for synthesized s…
2024-06-25 10:39:55 -07:00
Alex Lorenz
0c7621d282 Merge pull request #74541 from hyp/eng/lookup-imported-member-operator-cxx
[cxx-interop][serialization] resolve x-refs to instantiated/synthesiz…
2024-06-25 08:45:02 -07:00
fahadnayyar
1d8ddc2697 [cxx-interop] Import the attributes from Clang decl for synthesized Swift decl for pointee and successor 2024-06-24 13:53:54 -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
Alex Lorenz
015838ecfb attempt windows CI fix 2024-06-21 15:31:13 -07:00
Egor Zhdan
4610537e35 Merge pull request #74296 from swiftlang/egorzhdan/old-runtime-test-pt2
[cxx-interop] Only run tests for reference types against a recent Swift runtime, pt 2
2024-06-21 20:04:51 +01:00
Alex Lorenz
e4ad3c19c7 [cxx-interop] C library builtin functions from 'string.h' should ignore return type nullability to be compatible with C interop
In C interop mode, the return type of builtin functions like 'memcpy' from headers like 'string.h' drops any nullability
specifiers from their return type, and preserves it on the declared return type. Thus, in C
mode the imported return type of such functions is always optional. However, in C++ interop mode, the
return type of builtin functions can preseve the nullability specifiers on their return type,
and thus the imported return type of such functions can be non-optional, if the type is annotated with
`_Nonnull`. The difference between these two modes can break cross-module Swift serialization, as
Swift will no longer be able to resolve an x-ref such as 'memcpy' from a Swift module that uses
C interop, within a Swift context that uses C++ interop. In order to avoid the x-ref resolution
failure, normalize the return type's nullability for builtin functions in C++ interop mode, to
match the imported type in C interop mode.

This fixed an issue when using 'memcpy' from the Android NDK in a x-module context, like
between Foundation (that inlines it) and another user module.
2024-06-21 11:04:57 -07:00
Alex Lorenz
983fb8025a [cxx-interop][serialization] resolve x-refs to instantiated/synthesized C++ iterator conformance operators
These x-refs might not be resolvable using regular lookup from the 'std' module as they could be instantiated/synthesized
by the clang importer. Augment the lookup logic in that case to try clang importer lookup logic that is used during
the conformance to the C++ iterator protocol.
2024-06-20 14:51:34 -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
Susana Monteiro
823e809db5 Merge pull request #74426 from apple/susmonteiro/cxx-span
[cxx-interop] Add `std::span` tests
2024-06-18 17:58:03 +01:00