diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index e1171d4284c7..9d8cdc9c0852 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 000000000000..c046aef4e748 --- /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; }