Skip to content

Commit 4c3c612

Browse files
authored
Merge pull request #75692 from swiftlang/gaborh/reverse-interop-c-structs
[cxx-interop] Support reexposing C structs from Swift to C++
2 parents e867c08 + c4649ed commit 4c3c612

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/PrintAsClang/PrintClangFunction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ class ClangTypeHandler {
134134
if (auto *record = dyn_cast<clang::CXXRecordDecl>(typeDecl))
135135
return record->isTrivial();
136136

137-
// FIXME: If we can get plain clang::RecordDecls here, we need to figure out
138-
// how nontrivial (i.e. ARC) fields work.
139-
assert(!isa<clang::RecordDecl>(typeDecl));
137+
// Structs with ARC members are not considered trivial.
138+
if (auto *record = dyn_cast<clang::RecordDecl>(typeDecl))
139+
return !record->hasObjectMember();
140140

141141
// C-family enums are always trivial.
142142
return isa<clang::EnumDecl>(typeDecl);

test/Interop/SwiftToCxx/stdlib/core-foundation-types-in-cxx.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
// REQUIRES: objc_interop
77

88
import CoreFoundation
9+
import Foundation
910

1011
public func foobar(_ a: CFData) -> Bool {
1112
true
1213
}
1314

15+
public func networkThing() -> in_addr? {
16+
return nil
17+
}
18+
1419
// CHECK: SWIFT_EXTERN bool $s17UseCoreFoundation6foobarySbSo9CFDataRefaF(CFDataRef _Nonnull a) SWIFT_NOEXCEPT SWIFT_CALL; // foobar(_:)
20+
// CHECK: SWIFT_INLINE_THUNK swift::Optional<in_addr> networkThing() noexcept SWIFT_SYMBOL("s:17UseCoreFoundation12networkThingSo7in_addrVSgyF") SWIFT_WARN_UNUSED_RESULT {

0 commit comments

Comments
 (0)