Skip to content

Commit 8d2bf20

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 e5ecc9d commit 8d2bf20

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
@@ -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
}

0 commit comments

Comments
 (0)