diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index a8c41492b61ac..fe8b387f198c5 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2303,7 +2303,6 @@ class Sema final { struct ModuleScope { SourceLocation BeginLoc; clang::Module *Module = nullptr; - bool ModuleInterface = false; VisibleModuleSet OuterVisibleModules; }; /// The modules we're currently parsing. @@ -2367,9 +2366,11 @@ class Sema final { return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; } - /// Is the module scope we are an interface? - bool currentModuleIsInterface() const { - return ModuleScopes.empty() ? false : ModuleScopes.back().ModuleInterface; + /// Is the module scope we are an implementation unit? + bool currentModuleIsImplementation() const { + return ModuleScopes.empty() + ? false + : ModuleScopes.back().Module->isModuleImplementation(); } /// Is the module scope we are in a C++ Header Unit? diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index 8a296837e2a19..99b4d7d0fe40e 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -125,7 +125,6 @@ void Sema::HandleStartOfHeaderUnit() { ModuleScopes.push_back({}); // No GMF ModuleScopes.back().BeginLoc = StartOfTU; ModuleScopes.back().Module = Mod; - ModuleScopes.back().ModuleInterface = true; VisibleModules.setVisible(Mod, StartOfTU); // From now on, we have an owning module for all declarations we see. @@ -375,7 +374,6 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, // Switch from the global module fragment (if any) to the named module. ModuleScopes.back().BeginLoc = StartLoc; ModuleScopes.back().Module = Mod; - ModuleScopes.back().ModuleInterface = MDK != ModuleDeclKind::Implementation; VisibleModules.setVisible(Mod, ModuleLoc); // From now on, we have an owning module for all declarations we see. @@ -470,7 +468,6 @@ Sema::ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, ModuleScopes.push_back({}); ModuleScopes.back().BeginLoc = ModuleLoc; ModuleScopes.back().Module = PrivateModuleFragment; - ModuleScopes.back().ModuleInterface = true; VisibleModules.setVisible(PrivateModuleFragment, ModuleLoc); // All declarations created from now on are scoped to the private module @@ -523,7 +520,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, if (getLangOpts().CPlusPlusModules && isCurrentModulePurview() && getCurrentModule()->Name == ModuleName) { Diag(ImportLoc, diag::err_module_self_import_cxx20) - << ModuleName << !ModuleScopes.back().ModuleInterface; + << ModuleName << currentModuleIsImplementation(); return true; } @@ -609,10 +606,7 @@ DeclResult Sema::ActOnModuleImport(SourceLocation StartLoc, Mod->Kind == Module::ModuleKind::ModulePartitionImplementation) { Diag(ExportLoc, diag::err_export_partition_impl) << SourceRange(ExportLoc, Path.back().second); - } else if (!ModuleScopes.empty() && - (ModuleScopes.back().ModuleInterface || - (getLangOpts().CPlusPlusModules && - ModuleScopes.back().Module->isGlobalModule()))) { + } else if (!ModuleScopes.empty() && !currentModuleIsImplementation()) { // Re-export the module if the imported module is exported. // Note that we don't need to add re-exported module to Imports field // since `Exports` implies the module is imported already. @@ -772,7 +766,7 @@ Decl *Sema::ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, Diag(ExportLoc, diag::err_export_not_in_module_interface) << 0; D->setInvalidDecl(); return D; - } else if (!ModuleScopes.back().ModuleInterface) { + } else if (currentModuleIsImplementation()) { Diag(ExportLoc, diag::err_export_not_in_module_interface) << 1; Diag(ModuleScopes.back().BeginLoc, diag::note_not_module_interface_add_export) @@ -932,7 +926,6 @@ Module *Sema::PushGlobalModuleFragment(SourceLocation BeginLoc) { // Enter the scope of the global module. ModuleScopes.push_back({BeginLoc, TheGlobalModuleFragment, - /*ModuleInterface=*/false, /*OuterVisibleModules=*/{}}); VisibleModules.setVisible(TheGlobalModuleFragment, BeginLoc); @@ -959,7 +952,6 @@ Module *Sema::PushImplicitGlobalModuleFragment(SourceLocation BeginLoc, // Enter the scope of the global module. ModuleScopes.push_back({BeginLoc, *M, - /*ModuleInterface=*/false, /*OuterVisibleModules=*/{}}); VisibleModules.setVisible(*M, BeginLoc); return *M;