================
@@ -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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to