This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by Michael137 on Sep 15 2022, 8:06 AM.

Details

Summary

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

Diff Detail

Event Timeline

Michael137 created this revision.Sep 15 2022, 8:06 AM
Herald added a reviewer: shafik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: rnkovacs. · View Herald Transcript
Michael137 requested review of this revision.Sep 15 2022, 8:06 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 15 2022, 8:06 AM
Michael137 added inline comments.
clang/lib/AST/DeclBase.cpp
1777–1778

Could merge the two if-blocks now I suppose

  • Merge if-blocks
  • Reword commit
Michael137 retitled this revision from [clang][ASTImporter] Continue with slow lookup in DeclContext::localUncachedLookup when regular lookup fails to [clang][ASTImporter] DeclContext::localUncachedLookup: Continue lookup into decl chain when regular lookup fails.Sep 15 2022, 8:13 AM
Michael137 edited the summary of this revision. (Show Details)Sep 15 2022, 8:32 AM
  • Undo incorrect previous change
Michael137 added inline comments.Sep 15 2022, 8:43 AM
clang/lib/AST/DeclBase.cpp
1777–1778

Nevermind, not true

martong accepted this revision.Sep 16 2022, 1:42 AM

LGTM, Thanks!

clang/lib/AST/DeclBase.cpp
1777–1778

Yeah, we set HasLazyExternalLexicalLookups to true in https://reviews.llvm.org/D61333 exactly for the reason to continue the lookup into decl chain.

clang/unittests/AST/ASTImporterTest.cpp
4927–4929

Very good, now the behavior is the same that we have in case of the ASTImporterLookupTable.

This revision is now accepted and ready to land.Sep 16 2022, 1:42 AM