Skip to content

Commit 4482704

Browse files
committed
Always Import FieldDecls from Records
When we switched this path over to use lazy member loading, a subsequent commit introduced a check that members were canonical. In certain extremely twisty scenarios involving multiple modular frameworks pulling in non-modular headers, this check can fail which results in us silently dropping these members on the floor. It's ultimately correct to only pull in the canonical members, but real-world examples of "system" frameworks evading modularity diagnostics exist so this is strictly a regression. Drop the canonicity check for FieldDecls. rdar://86740970
1 parent 76c9ec7 commit 4482704

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
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
}

0 commit comments

Comments
 (0)