Skip to content

Commit d01126b

Browse files
committed
[ClangImporter] Deserialize only decls with a matching @objc name
Prevents a cycle where a general access to all top level decls lead the deserialization to call ClangImporter which triggered more deserialization. It crashed the compiler in a complex case so only limiting what is deserialized should be enough to fix this for now. rdar://problem/57118844
1 parent e9abba2 commit d01126b

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,17 +4563,25 @@ namespace {
45634563

45644564
if (!found) {
45654565
// Try harder to find a match looking at just custom Objective-C names.
4566-
SmallVector<Decl *, 64> allTopLevelDecls;
4567-
overlay->getTopLevelDecls(allTopLevelDecls);
4568-
for (auto result : allTopLevelDecls) {
4566+
// Limit what we deserialize to decls with an @objc attribute.
4567+
SmallVector<Decl *, 4> matchingTopLevelDecls;
4568+
4569+
// Get decls with a matching @objc attribute
4570+
overlay->getTopLevelDeclsWhereAttributesMatch(
4571+
matchingTopLevelDecls,
4572+
[&name](const DeclAttributes attrs) -> bool {
4573+
if (auto objcAttr = attrs.getAttribute<ObjCAttr>())
4574+
if (auto objcName = objcAttr->getName())
4575+
return objcName->getSimpleName() == name;
4576+
return false;
4577+
});
4578+
4579+
// Filter by decl kind
4580+
for (auto result : matchingTopLevelDecls) {
45694581
if (auto singleResult = dyn_cast<T>(result)) {
4570-
// The base name _could_ match but it's irrelevant here.
4571-
if (isMatch(singleResult, /*baseNameMatches=*/false,
4572-
/*allowObjCMismatch=*/false)) {
4573-
if (found)
4574-
return nullptr;
4575-
found = singleResult;
4576-
}
4582+
if (found)
4583+
return nullptr;
4584+
found = singleResult;
45774585
}
45784586
}
45794587
}

0 commit comments

Comments
 (0)