[clang] [lldb] [C++20][Modules] Do not update the declaration generation number if the redeclaration chain completion was delayed. (PR #129982)
Michael Park via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 7 00:14:34 PST 2025
================
@@ -9180,6 +9180,12 @@ bool Sema::hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested,
if (!getLangOpts().Modules && !getLangOpts().ModulesLocalVisibility)
return true;
+ // The external source may have additional definitions of this entity that are
+ // visible, so complete the redeclaration chain now.
+ if (auto *Source = Context.getExternalSource()) {
+ Source->CompleteRedeclChain(D);
+ }
----------------
mpark wrote:
Hm, okay... so the `DC->lookup(Name)` have different behaviors because of [`Source->FindExternalVisibleDeclsByName(...)`](https://github.com/llvm/llvm-project/blob/release/20.x/clang/lib/AST/DeclBase.cpp#L1913). In `ASTReader::FindExternalVisibleDeclsByName`, we get to [here](https://github.com/llvm/llvm-project/blob/c6d95c441a29a45782ff72d6cb82839b86fd0e4a/clang/lib/Serialization/ASTReader.cpp#L8494-L8501) looking through `Lookups` data structure. In the first call, `Lookups[DC].Table[Name]` has 1 entry (just a decl), whereas in the second call it has 2 entries (the decl and a defn).
In summary, we have `LazyGenerationalUpdatePtr::get` calling `CompleteRedeclChain` where `Lookups` isn't populated with the definition, and updates the generation number. The second time `LazyGenerationUpdatePtr::get` is called, `Lookups` **is** populated with the definition, but the generation number matches, and so it doesn't call `CompleteRedeclChain` even though it would yield a different result.
https://github.com/llvm/llvm-project/pull/129982
More information about the cfe-commits
mailing list