diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2220,6 +2220,9 @@ /// The modules we're currently parsing. llvm::SmallVector ModuleScopes; + /// The modules we imported directly. + llvm::SmallPtrSet DirectModuleImports; + /// Namespace definitions that we will export when they finish. llvm::SmallPtrSet DeferredExportedNamespaces; @@ -2247,6 +2250,10 @@ return Entity->getOwningModule(); } + bool isModuleDirectlyImported(const Module *M) { + return DirectModuleImports.contains(M); + } + /// Make a merged definition of an existing hidden definition \p ND /// visible at the specified location. void makeMergedDefinitionVisible(NamedDecl *ND); diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -434,6 +434,10 @@ << !ModuleScopes.back().ModuleInterface; } + // In some cases we need to know if an entity was present in a directly- + // imported module (as opposed to a transitive import). + DirectModuleImports.insert(Mod); + // FIXME: we should support importing a submodule within a different submodule // of the same top-level module. Until we do, make it an error rather than // silently ignoring the import.