mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-03-04 00:20:14 +00:00
[C++20][Modules][8/8] Amend module visibility rules for partitions.
Implementation partitions bring two extra cases where we have visibility of module-private data. 1) When we import a module implementation partition. 2) When a partition implementation imports the primary module intertace. We maintain a record of direct imports into the current module since partition decls from direct imports (but not trasitive ones) are visible. The rules on decl-reachability are much more relaxed (with the standard giving permission for an implementation to load dependent modules and for the decls there to be reachable, but not visible). Differential Revision: https://reviews.llvm.org/D118599
This commit is contained in:
parent
e9085d0d25
commit
a29f8dbb7f
@ -1687,8 +1687,8 @@ bool LookupResult::isVisibleSlow(Sema &SemaRef, NamedDecl *D) {
|
||||
Module *DeclModule = SemaRef.getOwningModule(D);
|
||||
assert(DeclModule && "hidden decl has no owning module");
|
||||
|
||||
// If the owning module is visible, the decl is visible.
|
||||
if (SemaRef.isModuleVisible(DeclModule, D->isModulePrivate()))
|
||||
// If the owning module is visible, the decl is visible.
|
||||
return true;
|
||||
|
||||
// Determine whether a decl context is a file context for the purpose of
|
||||
@ -1762,6 +1762,22 @@ bool Sema::isModuleVisible(const Module *M, bool ModulePrivate) {
|
||||
if (ModulePrivate) {
|
||||
if (isInCurrentModule(M, getLangOpts()))
|
||||
return true;
|
||||
else if (M->Kind == Module::ModuleKind::ModulePartitionImplementation &&
|
||||
isModuleDirectlyImported(M))
|
||||
// Unless a partition implementation is directly imported it is not
|
||||
// counted as visible for lookup, although the contained decls might
|
||||
// still be reachable. It's a partition, so it must be part of the
|
||||
// current module to be a valid import.
|
||||
return true;
|
||||
else if (getLangOpts().CPlusPlusModules && !ModuleScopes.empty() &&
|
||||
ModuleScopes[0].Module->Kind ==
|
||||
Module::ModuleKind::ModulePartitionImplementation &&
|
||||
ModuleScopes[0].Module->getPrimaryModuleInterfaceName() ==
|
||||
M->Name &&
|
||||
isModuleDirectlyImported(M))
|
||||
// We are building a module implementation partition and the TU imports
|
||||
// the primary module interface unit.
|
||||
return true;
|
||||
} else {
|
||||
if (VisibleModules.isVisible(M))
|
||||
return true;
|
||||
|
@ -12,9 +12,8 @@
|
||||
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu3.cpp \
|
||||
// RUN: -o %t/B_X1.pcm -verify
|
||||
|
||||
// Not expected to work yet.
|
||||
// %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu4.cpp \
|
||||
// -fmodule-file=%t/B.pcm -o %t/B_X2.pcm
|
||||
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu4.cpp \
|
||||
// RUN:-fmodule-file=%t/B.pcm -o %t/B_X2.pcm
|
||||
|
||||
// RUN: %clang_cc1 -std=c++20 -emit-obj %t/std10-1-ex2-tu5.cpp \
|
||||
// RUN: -fmodule-file=%t/B.pcm -o %t/b_tu5.o
|
||||
@ -22,9 +21,8 @@
|
||||
// RUN: %clang_cc1 -std=c++20 -S %t/std10-1-ex2-tu6.cpp \
|
||||
// RUN: -fmodule-file=%t/B.pcm -o %t/b_tu6.s -verify
|
||||
|
||||
// Not expected to work yet.
|
||||
// %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu7.cpp \
|
||||
// -fmodule-file=%t/B_X2.pcm -o %t/B_X3.pcm -verify
|
||||
// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/std10-1-ex2-tu7.cpp \
|
||||
// RUN: -fmodule-file=%t/B_X2.pcm -o %t/B_X3.pcm -verify
|
||||
|
||||
//--- std10-1-ex2-tu1.cpp
|
||||
module B:Y;
|
||||
|
Loading…
x
Reference in New Issue
Block a user