[clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails

The uncached lookup is mainly used in the ASTImporter/LLDB code-path
where we're not allowed to load from external storage. When importing
a FieldDecl with a DeclContext that had no external visible storage
(but came from a Clang module or PCH) the above call to `lookup(Name)`
the regular `DeclContext::lookup` fails because:
1. `DeclContext::buildLookup` doesn't set `LookupPtr` for decls
   that came from a module
2. LLDB doesn't use the `SharedImporterState`

In such a case we would never continue with the "slow" path of iterating
through the decl chain on the DeclContext. In some cases this means that
ASTNodeImporter::VisitFieldDecl ends up importing a decl into the
DeclContext a second time.

The patch removes the short-circuit in the case where we don't find
any decls via the regular lookup.

**Tests**

* Un-skip the failing LLDB API tests

Differential Revision: https://reviews.llvm.org/D133945
This commit is contained in:
Michael Buch 2022-09-14 22:37:08 -04:00
parent 3004a759bc
commit e456d2ba8b
3 changed files with 4 additions and 5 deletions

View File

@ -1771,7 +1771,8 @@ void DeclContext::localUncachedLookup(DeclarationName Name,
if (!hasExternalVisibleStorage() && !hasExternalLexicalStorage() && Name) {
lookup_result LookupResults = lookup(Name);
Results.insert(Results.end(), LookupResults.begin(), LookupResults.end());
return;
if (!Results.empty())
return;
}
// If we have a lookup table, check there first. Maybe we'll get lucky.

View File

@ -4924,9 +4924,9 @@ TEST_P(ASTImporterLookupTableTest,
FooDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
EXPECT_EQ(FoundDecls.size(), 0u);
// Cannot find in the LookupTable of its LexicalDC (A).
// Finds via linear search of its LexicalDC (A).
FooLexicalDC->getRedeclContext()->localUncachedLookup(FooName, FoundDecls);
EXPECT_EQ(FoundDecls.size(), 0u);
EXPECT_EQ(FoundDecls.size(), 1u);
// Can't find in the list of Decls of the DC.
EXPECT_EQ(findInDeclListOfDC(FooDC, FooName), nullptr);

View File

@ -34,7 +34,6 @@ class TestTemplateWithSameArg(TestBase):
self.main_source_file = lldb.SBFileSpec("main.cpp")
@add_test_categories(["gmodules"])
@skipIf(bugnumber='rdar://96581048')
def test_same_template_arg(self):
lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)
@ -51,7 +50,6 @@ class TestTemplateWithSameArg(TestBase):
])
@add_test_categories(["gmodules"])
@skipIf(bugnumber='rdar://96581048')
def test_duplicate_decls(self):
lldbutil.run_to_source_breakpoint(self, "Break here", self.main_source_file)