Commit Graph

6 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
Egor Zhdan
c30c400676 [cxx-interop] Fix test for reference types on armv7k
This adjusts the test to be correct on 32-bit platforms.

rdar://128673814
2024-05-28 12:47:56 +01:00
Egor Zhdan
5fbb07f3a6 [cxx-interop] Fix test for reference types on armv7k, part 2
This adjusts the test to be correct on 32-bit platforms.

rdar://127795392
2024-05-16 16:53:47 +01:00
Egor Zhdan
fd04cc3a4e [cxx-interop][Runtime] Initialize metadata of a Swift array of C++ references correctly
This fixes a crash at runtime when destroying a Swift array of values of a C++ foreign reference type.

Swift optimizes the amount of metadata emitted for `_ContiguousArrayStorage<Element>` by reusing `_ContiguousArrayStorage<AnyObject>` whenever possible (see `getContiguousArrayStorageType`). However, C++ foreign reference types are not `AnyObject`s, since they have custom retain/release operations.

This change disables the `_ContiguousArrayStorage` metadata optimization for C++ reference types, which makes sure that `swift_arrayDestroy` will call the correct release operation for elements of `[MyCxxRefType]`.

rdar://127154770
2024-05-15 19:20:44 +01:00
Egor Zhdan
d84cbace14 [cxx-interop] Fix test for reference types on armv7k
This adjusts the test to be correct on 32-bit platforms.

rdar://127795392
2024-05-09 12:56:07 +01:00
Egor Zhdan
bd6da5dc64 [cxx-interop][IRGen] Do not try to retain/release a null pointer
This teaches IRGen to only emit a lifetime operation (retain or release) for a C++ foreign reference type if the pointer is not `nullptr`.

Previously the compiler would in some cases emit a release call for `nullptr`, which breaks the assumption that the argument to a custom release function is `_Nonnull`. For instance:
```
var globalOptional: MyRefType? = nil
func foo() { globalOptional = MyRefType.create() }
```
When emitting IR for the assignment operation to `globalOptional`, the compiler would emit code to first retrieve the existing value of `globalOptional` and release it. If the value is `nil`, it does not need to be released.

rdar://97532642
2024-05-07 20:20:45 +01:00