[clang] baa5b76 - [C++20] [Modules] Make module local decls visible to language linkage in the same module

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 17 06:18:47 PST 2025


Author: Chuanqi Xu
Date: 2025-01-17T22:17:50+08:00
New Revision: baa5b769f2f76baa0ce1ebfe28236dee2c761f0d

URL: https://github.com/llvm/llvm-project/commit/baa5b769f2f76baa0ce1ebfe28236dee2c761f0d
DIFF: https://github.com/llvm/llvm-project/commit/baa5b769f2f76baa0ce1ebfe28236dee2c761f0d.diff

LOG: [C++20] [Modules] Make module local decls visible to language linkage in the same module

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

See the issue and the comments in the patch for details.

Added: 
    clang/test/Modules/module-local-visibility-in-language-linkage.cppm

Modified: 
    clang/lib/Sema/SemaLookup.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index e1171d4284c763..9d8cdc9c085251 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1624,6 +1624,11 @@ bool Sema::isUsableModule(const Module *M) {
   if (!Current)
     return false;
 
+  // For implicit global module, the decls in the same modules with the parent
+  // module should be visible to the decls in the implicit global module.
+  if (Current->isImplicitGlobalModule())
+    Current = Current->getTopLevelModule();
+
   // If M is the module we're parsing or M and the current module unit lives in
   // the same module, M should be usable.
   //

diff  --git a/clang/test/Modules/module-local-visibility-in-language-linkage.cppm b/clang/test/Modules/module-local-visibility-in-language-linkage.cppm
new file mode 100644
index 00000000000000..c046aef4e74867
--- /dev/null
+++ b/clang/test/Modules/module-local-visibility-in-language-linkage.cppm
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/m.a.cppm -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/m.b.cppm -fmodule-file=m:a=%t/a.pcm -fsyntax-only -verify
+
+//--- m.a.cppm
+export module m:a;
+int a;
+
+//--- m.b.cppm
+// expected-no-diagnostics
+module m:b;
+import :a;
+extern "C++" int get_a() { return a; }


        


More information about the cfe-commits mailing list