Skip to content

Commit 4a9cd5b

Browse files
authored
Merge pull request #40771 from CodaFi/field-hockey
[5.6] Always Import FieldDecls from Records
2 parents 38febd6 + df70cb8 commit 4a9cd5b

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9769,13 +9769,21 @@ void ClangImporter::Implementation::loadAllMembersOfRecordDecl(
97699769
llvm::SmallVector<Decl *, 16> members;
97709770
for (const clang::Decl *m : clangRecord->decls()) {
97719771
auto nd = dyn_cast<clang::NamedDecl>(m);
9772+
if (!nd)
9773+
continue;
9774+
97729775
// Currently, we don't import unnamed bitfields.
97739776
if (isa<clang::FieldDecl>(m) &&
97749777
cast<clang::FieldDecl>(m)->isUnnamedBitfield())
97759778
continue;
97769779

9777-
if (nd && nd == nd->getCanonicalDecl() &&
9778-
nd->getDeclContext() == clangRecord &&
9780+
// Make sure we always pull in record fields. Everything else had better
9781+
// be canonical. Note that this check mostly catches nested C++ types since
9782+
// we import nested C struct types by C's usual convention of chucking them
9783+
// into the global namespace.
9784+
const bool isCanonicalInContext =
9785+
(isa<clang::FieldDecl>(nd) || nd == nd->getCanonicalDecl());
9786+
if (isCanonicalInContext && nd->getDeclContext() == clangRecord &&
97799787
isVisibleClangEntry(nd))
97809788
insertMembersAndAlternates(nd, members);
97819789
}

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)