Skip to content

Commit 37c4198

Browse files
authored
Merge pull request #40760 from CodaFi/field-of-dreams
Always Import FieldDecls from Records
2 parents 61d35f0 + 0b4641d commit 37c4198

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9866,13 +9866,21 @@ void ClangImporter::Implementation::loadAllMembersOfRecordDecl(
98669866
llvm::SmallVector<Decl *, 16> members;
98679867
for (const clang::Decl *m : clangRecord->decls()) {
98689868
auto nd = dyn_cast<clang::NamedDecl>(m);
9869+
if (!nd)
9870+
continue;
9871+
98699872
// Currently, we don't import unnamed bitfields.
98709873
if (isa<clang::FieldDecl>(m) &&
98719874
cast<clang::FieldDecl>(m)->isUnnamedBitfield())
98729875
continue;
98739876

9874-
if (nd && nd == nd->getCanonicalDecl() &&
9875-
nd->getDeclContext() == clangRecord &&
9877+
// Make sure we always pull in record fields. Everything else had better
9878+
// be canonical. Note that this check mostly catches nested C++ types since
9879+
// we import nested C struct types by C's usual convention of chucking them
9880+
// into the global namespace.
9881+
const bool isCanonicalInContext =
9882+
(isa<clang::FieldDecl>(nd) || nd == nd->getCanonicalDecl());
9883+
if (isCanonicalInContext && nd->getDeclContext() == clangRecord &&
98769884
isVisibleClangEntry(nd))
98779885
insertMembersAndAlternates(nd, members);
98789886
}

test/Interop/Cxx/class/protocol-conformance-irgen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ protocol HasReturn42 {
1111
// CHECK: [[OUT:%.*]] = call i32 @{{_ZN18ConformsToProtocol8return42Ev|"\?return42@ConformsToProtocol@@QEAAHXZ"}}(%struct.ConformsToProtocol*
1212
// CHECK: ret i32 [[OUT]]
1313

14-
// CHECK: define {{.*}}%swift.metadata_response @"$sSo18ConformsToProtocolVMa"(i64 [[ARG:%.*]])
14+
// CHECK: define {{.*}}%swift.metadata_response @"$sSo18ConformsToProtocolVMa"({{i64|i32}} [[ARG:%.*]])
1515
// CHECK: load %swift.type*, %swift.type** @"$sSo18ConformsToProtocolVML"
16-
// CHECK: call swiftcc %swift.metadata_response @swift_getForeignTypeMetadata(i64 [[ARG]], %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* bitcast (<{ i8**, i64, <{ i32, i32, i32, i32, i32, i32, i32, i32 }>* }>* @"$sSo18ConformsToProtocolVMf" to %swift.full_type*), i32 0, i32 1))
16+
// CHECK: call swiftcc %swift.metadata_response @swift_getForeignTypeMetadata({{i64|i32}} [[ARG]]
1717
// CHECK: ret %swift.metadata_response
1818

1919
extension ConformsToProtocol : HasReturn42 {}

test/Interop/Cxx/templates/class-template-instantiation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ TemplatesTestSuite.test("with-swift-type") {
1818
expectEqual(wrappedMagicNumber.getValuePlusArg(8), 21)
1919
}
2020

21-
TemplatesTestSuite.test("with-c++-type-calling-method-on-arg") {
21+
TemplatesTestSuite.test("with-c++-type-calling-method-on-arg")
22+
.skip(.watchOSSimulatorAny("rdar://problem/87262809")).code {
2223
let i1 = IntWrapper(value: 42)
2324
let i2 = IntWrapper(value: 12)
2425
var wrappedMagicNumber = MagicWrapper<IntWrapper>(t: i1)

test/Interop/Cxx/templates/class-template-uninstantiatable-members-irgen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ClassTemplateInstantiationErrors
44

55
// CHECK-LABEL: define {{.*}}void @"$s4main23instantiateValidMembersyyF"()
66
// CHECK: call i32 @{{_ZN21CannotBeInstantiantedI10IntWrapperE8incValueEv|"\?incValue@\?\$CannotBeInstantianted@UIntWrapper@@@@QEAAHXZ"}}(%struct.CannotBeInstantianted*
7-
// CHECK: call i32 @{{_ZN21CannotBeInstantiantedI10IntWrapperE8incValueES0_|"\?incValue@\?\$CannotBeInstantianted@UIntWrapper@@@@QEAAHUIntWrapper@@@Z"}}(%struct.CannotBeInstantianted* {{.*}}, {{i32|i64|\[1 x i32\]|\%struct\.IntWrapper\* byval\(\%struct\.IntWrapper\)}}
7+
// CHECK: call i32 @{{_ZN21CannotBeInstantiantedI10IntWrapperE8incValueES0_|"\?incValue@\?\$CannotBeInstantianted@UIntWrapper@@@@QEAAHUIntWrapper@@@Z"}}(%struct.CannotBeInstantianted*
88
// CHECK: ret void
99

1010
// CHECK-LABEL: define {{.*}}i32 @{{_ZN21CannotBeInstantiantedI10IntWrapperE8incValueEv|"\?incValue@\?\$CannotBeInstantianted@UIntWrapper@@@@QEAAHXZ"}}(%struct.CannotBeInstantianted*

0 commit comments

Comments
 (0)