[clang] [C++20] [Modules] Don't set modules owner ship information for builtin declarations (PR #102115)

via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 6 02:28:48 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-modules

Author: Chuanqi Xu (ChuanqiXu9)

<details>
<summary>Changes</summary>

Close https://github.com/llvm/llvm-project/issues/101939

As the issue said, the builtin declarations shouldn't be in any modules.

---
Full diff: https://github.com/llvm/llvm-project/pull/102115.diff


2 Files Affected:

- (modified) clang/lib/Sema/SemaDecl.cpp (+6) 
- (added) clang/test/Modules/pr101939.cppm (+6) 


``````````diff
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1f4bfa247b544..a82c66ced817e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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);
+    New->setModuleOwnershipKind(Decl::ModuleOwnershipKind::Unowned);
+  }
+
   // TUScope is the translation-unit scope to insert this function into.
   // FIXME: This is hideous. We need to teach PushOnScopeChains to
   // relate Scopes to DeclContexts, and probably eliminate CurContext
diff --git a/clang/test/Modules/pr101939.cppm b/clang/test/Modules/pr101939.cppm
new file mode 100644
index 0000000000000..35c243ed0f1bf
--- /dev/null
+++ b/clang/test/Modules/pr101939.cppm
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c++20 %s -ast-dump | FileCheck %s
+
+export module mod;
+export auto a = __builtin_expect(true, true);
+
+// CHECK-NOT: FunctionDecl{{.*}} in mod {{.*}} __builtin_expect

``````````

</details>


https://github.com/llvm/llvm-project/pull/102115


More information about the cfe-commits mailing list