Commit Graph

18 Commits

Author SHA1 Message Date
Egor Zhdan
46f86f0870 [cxx-interop] Import custom NS_OPTIONS correctly
This changes the heuristic that we use to detect `CF_OPTIONS`/`NS_OPTIONS` instantiations in C++ language mode.

Since libraries sometimes declare custom option types that break the assumptions about the names of such types, this lifts the requirements on the type name.

rdar://113524090
rdar://113279214
2023-08-18 15:41:50 +01:00
Egor Zhdan
4eb9c3be37 [cxx-interop] Make sure to create empty initializers for C++ structs
The existing synthesis mechanism had a bug: `cxxRecordDecl->hasDefaultConstructor()` returns true for C++ types with an implicit default constructor, for instance, `pthread_mutexattr_t`.

rdar://113708880
2023-08-14 17:46:57 +01:00
Egor Zhdan
6edde292f1 [cxx-interop] Import NSStreamDelegate.stream correctly
This Objective-C method
```
- (void)stream:(NSStream *)aStream
   handleEvent:(NSStreamEvent)eventCode;
```
should be imported as
```
optional func stream(
    _ aStream: Stream,
    handle eventCode: Stream.Event)
```
and not
```
optional func stream(
    _ aStream: Stream,
    handleEvent eventCode: Stream.Event)
```
in order to stay compatible with Objective-C interop mode.

rdar://113208675
2023-08-02 17:54:58 +01:00
Egor Zhdan
9edb752ac5 Merge pull request #67301 from apple/egorzhdan/foundation-linker-errors
[cxx-interop] Import CF_OPTIONS types such as `Foundation.NSTextCheckingType` correctly
2023-07-14 20:32:16 +01:00
Egor Zhdan
e6b830b640 [cxx-interop] Import CF_OPTIONS types such as Foundation.NSTextCheckingType correctly
This fixes linker errors which occurred when using Foundation extensions to `Swift.String`, such as `func replacingOccurrences`.

After the last rebranch, Clang started wrapping certain types in `clang::ElaboratedType`. This caused CF_OPTIONS types such as `Foundation.NSTextCheckingType` to be imported incorrectly in C++ language mode (`NSTextCheckingType` was imported as `uint64_t` without getting the special treatment of a CF type), which was causing deserialization errors when Swift tried reading `Foundation.swiftmodule`. Those deserialization errors were silenced by default. The IR for those functions was not emitted, which caused linker errors later.

rdar://109830032
2023-07-14 17:51:49 +01:00
Alex Lorenz
54c49db854 [cxx-interop] NFC, test, drop extern_c from a test module 2023-07-12 09:44:27 -07:00
Egor Zhdan
5a6203251c [cxx-interop] Import OS_OBJECT_DECL consistently with and without C++ interop enabled
Previously ClangImporter was not able to lookup `NSObject` when C++ interop is enabled, which caused types such as `xpc_object_t` from system module XPC to be imported differently: `any OS_xpc_object` without C++ interop vs `any NSObject & OS_xpc_object` with C++ interop enabled.

rdar://110000787
2023-07-04 21:32:17 +01:00
zoecarver
2114833e2e [nfc] Fix notification test 2023-06-23 12:05:11 -07:00
zoecarver
7964918cb2 [cxx-interop] Fix sema lookup scope so we find NSNotification interface even in C++ mode. 2023-06-22 12:21:10 -07:00
Alex Lorenz
4590aa1ede Merge pull request #65813 from hyp/eng/passInRegs
[cxx-interop] Itanium ABI C++ records should have address-only layout when they can't be passed in registers
2023-06-16 07:47:48 -07:00
Alex Lorenz
988f373055 [test] fix objcxx-arc-field-in-struct-type-layout-execution.swift test failure on macOS 2023-06-15 12:48:13 -07:00
Puyan Lotfi
fe6ccd7a29 [cxx-interop] Add fix for corner case where NS_OPTIONS typedef has to be desugared
This patch is an add-on to https://github.com/apple/swift/pull/64043.
Essentially when encountering NS_OPTIONS enums, in C++-Interop mode
if they are not specially handled then they can mangle differently than
they do without C++-Interop. This patch adds logic to handle when a
typedef and enum have additional clang::ElaboratedType sugar, but
otherwise it does the same as the existing 64043 patch.

The test case provided was encountered in a real app build. The problem
came from when two modules are each compiled one with and one without
C++-Interop. For the test case code provided the mangling of the
protocol conformance is not consistent and the code in
SILGenLazyConformance.cpp crashes on an invalid conformance with reason
"Invalid conformance in type-checked AST".
2023-06-15 11:17:25 -07:00
Alex Lorenz
49d7e041de [cxx-interop] C++ records should have address-only layout when they can't be passed in registers
This ensures that a C++ record with only ObjC ARC pointers with trivial other members is passed by value in SIL

Fixes https://github.com/apple/swift/issues/61929
2023-05-09 16:23:35 -07:00
Puyan Lotfi
6180387a05 [cxx-interop] Adding std.string initializer for UnsafePointer<CChar>?
Currently without an initializer for the unsafe char pointer type swiftc
hits an assert around not being able to handle conversions of unsafe
pointers with Any type. This patch adds the ability to convert to a
std::string.

This is to address issue https://github.com/apple/swift/issues/61218
2023-04-12 22:03:57 -04:00
Alex Lorenz
9feb76419b [interop] ignore exceptions in existing interop tests 2023-02-22 11:00:51 -08:00
Puyan Lotfi
4f2f348356 [C++-Interop] Allow for calling automatically synthesized ctors of arc types
When instantiating C++ types who contain ARC types in the past either
their default constructors are skipped or they are synthesized with
Unmanged<> wrappers. This has made it more cumbersome to instantiate
these from Swift and often requires a static C++ build method to
manually shim the synthesized constructor. The following change drops
the Unmanaged<> so that for the time being these types can be
instantiated directly even if types like Swift -> NSString are not
bridged completely.

(cherry picked from commit accdace5f0438860a0d6760d9598402a9998a324)
(cherry picked from commit 567763c9ec76e14b0d6af5707e50b1674b2c2cbf)
2023-02-15 18:01:04 -05:00
Daniel Rodríguez Troitiño
691dcc9bb3 Test case for const T& in Obj-C++ methods
Add a test case that checks the behaviour introduced during the refactor
of `importFunctionParameterList` and `importMethodParamsAndReturnType`.

The test checks that both Obj-C++ methods and C++ functions treat `const
T&` parameters in the same way.
2022-09-02 11:51:15 -07:00
Alex Langford
9babd8fa8b [cxx-interop][ClangImporter] Fix protocol renaming issue with objc++ interop enabled
When constructing SwiftLookupTable at clang module creation time, calls
to `clang::Sema::LookupName` will fail in C++ mode (including ObjC++).
The specific reason is that `clangSema.TUScope` (which we are passing in
as a Scope) is `nullptr` as we have no active Parser. The C++ path in
`clang::Sema::LookupName` is set to fail early and hard when the Scope
passed in is nullptr. In most, if not all, calls to `LookupName`, we
care about ObjC symbols and not C++ names. For example, the motivation
behind this issue is that ObjC protocols are not being renamed when
there is an ObjC class with the same name, leading to compilation
failures.
2022-04-20 11:52:08 -07:00