diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2025-01-22 17:22:00 +0800 |
---|---|---|
committer | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2025-01-22 17:24:12 +0800 |
commit | d2e510360fc9b17a3ad536582f076795c4c37634 (patch) | |
tree | 675977540a711d9612f4686ef94595b4b248b26c | |
parent | a343b8e595d56bde91800aeaa7826cbed4e0a18d (diff) | |
download | llvm-d2e510360fc9b17a3ad536582f076795c4c37634.zip llvm-d2e510360fc9b17a3ad536582f076795c4c37634.tar.gz llvm-d2e510360fc9b17a3ad536582f076795c4c37634.tar.bz2 |
[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
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 4 | ||||
-rw-r--r-- | clang/test/Modules/visibility-for-implicit-global-module.cppm | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 9d8cdc9..e18e3c1 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 0000000..c55f2c3 --- /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); + |