[clang] d2e5103 - [C++20] [Modules] Correct the visibility of decls in implicit global module of other units in the same TU
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 22 01:25:00 PST 2025
Author: Chuanqi Xu
Date: 2025-01-22T17:24:12+08:00
New Revision: d2e510360fc9b17a3ad536582f076795c4c37634
URL: https://github.com/llvm/llvm-project/commit/d2e510360fc9b17a3ad536582f076795c4c37634
DIFF: https://github.com/llvm/llvm-project/commit/d2e510360fc9b17a3ad536582f076795c4c37634.diff
LOG: [C++20] [Modules] Correct the visibility of decls in implicit global module of other units in the same TU
See the test for the case. It is similar with
https://github.com/llvm/llvm-project/commit/baa5b769f2f76baa0ce1ebfe28236dee2c761f0d
Added:
clang/test/Modules/visibility-for-implicit-global-module.cppm
Modified:
clang/lib/Sema/SemaLookup.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 9d8cdc9c085251..e18e3c197383e2 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1614,7 +1614,7 @@ bool Sema::isUsableModule(const Module *M) {
// Otherwise, the global module fragment from other translation unit is not
// directly usable.
- if (M->isGlobalModule())
+ if (M->isExplicitGlobalModule())
return false;
Module *Current = getCurrentModule();
@@ -1628,6 +1628,8 @@ bool Sema::isUsableModule(const Module *M) {
// module should be visible to the decls in the implicit global module.
if (Current->isImplicitGlobalModule())
Current = Current->getTopLevelModule();
+ if (M->isImplicitGlobalModule())
+ M = M->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/visibility-for-implicit-global-module.cppm b/clang/test/Modules/visibility-for-implicit-global-module.cppm
new file mode 100644
index 00000000000000..c55f2c3beee202
--- /dev/null
+++ b/clang/test/Modules/visibility-for-implicit-global-module.cppm
@@ -0,0 +1,18 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 %t/a.interface.cppm -emit-module-interface -o %t/a.pcm
+// RUN: %clang_cc1 -std=c++20 %t/a.impl.cc -fmodule-file=a:interface=%t/a.pcm \
+// RUN: -verify -fsyntax-only
+
+//--- a.interface.cppm
+export module a:interface;
+extern "C++" constexpr int a = 43;
+
+//--- a.impl.cc
+// expected-no-diagnostics
+module a:impl;
+import :interface;
+static_assert(a == 43);
+
More information about the cfe-commits
mailing list