[clang] [C++20] [Modules] Don't set modules owner ship information for builtin declarations (PR #102115)
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 6 19:48:07 PDT 2024
================
@@ -2376,6 +2376,12 @@ NamedDecl *Sema::LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID,
FunctionDecl *New = CreateBuiltin(II, R, ID, Loc);
RegisterLocallyScopedExternCDecl(New, S);
+ // Builtin functions shouldn't be owned by any module.
+ if (New->hasOwningModule()) {
+ New->setLocalOwningModule(nullptr);
----------------
ChuanqiXu9 wrote:
> When is the owning module set?
The owning module is set when we new the decl: https://github.com/llvm/llvm-project/blob/47bf996abe4fafa8192c78c472d68c6519349e90/clang/lib/AST/DeclBase.cpp#L106-L108. So design intention here should be, then we don't need to worry about modules ownership at most times when we develope Sema. And it explains the error, when we create the Builtin function decl, we set the context as the TU (good), and the TU is attached to a named module (good), then we attach the decl to the named module (bad).
And if we want to avoid setting the incorrect modules ownership in the first place, we need to change the new function. It smells bad.
I feel the current position is good as long as we can make sure we'll only create builtin functions here and it looks true now.
https://github.com/llvm/llvm-project/pull/102115
More information about the cfe-commits
mailing list