From e48ab7f6b5d4eb4f547c26234e52fbd4c22b7342 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 1 May 2015 01:53:09 +0000 Subject: [PATCH] [modules] Start moving the module visibility information off the Module itself. It has no place there; it's not a property of the Module, and it makes restoring the visibility set when we leave a submodule more difficult. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236300 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticLexKinds.td | 4 +- .../Basic/DiagnosticSerializationKinds.td | 3 - include/clang/Basic/Module.h | 55 +++++++++++++++++- include/clang/Frontend/ASTUnit.h | 2 +- include/clang/Frontend/CompilerInstance.h | 2 +- include/clang/Lex/ModuleLoader.h | 3 +- include/clang/Lex/ModuleMap.h | 3 + include/clang/Lex/Preprocessor.h | 14 +++-- include/clang/Serialization/ASTReader.h | 3 +- lib/Basic/Module.cpp | 57 ++++++++++++++++--- lib/Frontend/CompilerInstance.cpp | 10 ++-- lib/Lex/ModuleMap.cpp | 7 ++- lib/Lex/PPDirectives.cpp | 6 +- lib/Lex/PPLexerChange.cpp | 8 +-- lib/Lex/PPMacroExpansion.cpp | 8 +-- lib/Lex/Preprocessor.cpp | 26 +++++++-- lib/Sema/SemaDecl.cpp | 6 +- lib/Serialization/ASTReader.cpp | 29 +++------- lib/Serialization/ASTWriter.cpp | 13 ----- unittests/Basic/SourceManagerTest.cpp | 3 +- unittests/Lex/LexerTest.cpp | 3 +- unittests/Lex/PPCallbacksTest.cpp | 3 +- .../Lex/PPConditionalDirectiveRecordTest.cpp | 3 +- 23 files changed, 175 insertions(+), 96 deletions(-) diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index 6eaf423a77..3d568e84a9 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -638,7 +638,9 @@ def warn_non_modular_include_in_framework_module : Warning< def warn_non_modular_include_in_module : Warning< "include of non-modular header inside module '%0'">, InGroup, DefaultIgnore; - +def warn_module_conflict : Warning< + "module '%0' conflicts with already-imported module '%1': %2">, + InGroup; def warn_header_guard : Warning< "%0 is used as a header guard here, followed by #define of a different macro">, diff --git a/include/clang/Basic/DiagnosticSerializationKinds.td b/include/clang/Basic/DiagnosticSerializationKinds.td index b0d352fc69..796027ea62 100644 --- a/include/clang/Basic/DiagnosticSerializationKinds.td +++ b/include/clang/Basic/DiagnosticSerializationKinds.td @@ -66,9 +66,6 @@ def err_imported_module_relocated : Error< def err_module_different_modmap : Error< "module '%0' %select{uses|does not use}1 additional module map '%2'" "%select{| not}1 used when the module was built">; -def warn_module_conflict : Warning< - "module '%0' conflicts with already-imported module '%1': %2">, - InGroup; def err_pch_macro_def_undef : Error< "macro '%0' was %select{defined|undef'd}1 in the precompiled header but " diff --git a/include/clang/Basic/Module.h b/include/clang/Basic/Module.h index a976601c51..3c08b24d51 100644 --- a/include/clang/Basic/Module.h +++ b/include/clang/Basic/Module.h @@ -21,6 +21,7 @@ #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include @@ -85,6 +86,9 @@ private: /// \brief Cache of modules visible to lookup in this module. mutable llvm::DenseSet VisibleModulesCache; + /// The ID used when referencing this module within a VisibleModuleSet. + unsigned VisibilityID; + public: enum HeaderKind { HK_Normal, @@ -288,7 +292,7 @@ public: /// \brief Construct a new module or submodule. Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, - bool IsFramework, bool IsExplicit); + bool IsFramework, bool IsExplicit, unsigned VisibilityID); ~Module(); @@ -441,6 +445,8 @@ public: return VisibleModulesCache.count(M); } + unsigned getVisibilityID() const { return VisibilityID; } + typedef std::vector::iterator submodule_iterator; typedef std::vector::const_iterator submodule_const_iterator; @@ -470,6 +476,53 @@ private: void buildVisibleModulesCache() const; }; +/// \brief A set of visible modules. +class VisibleModuleSet { +public: + VisibleModuleSet() : Generation(0) {} + + VisibleModuleSet &operator=(VisibleModuleSet &&O) { + ImportLocs = std::move(O.ImportLocs); + ++Generation; + return *this; + } + + /// \brief Get the current visibility generation. + unsigned getGeneration() const { return Generation; } + + /// \brief Determine whether a module is visible. + bool isVisible(const Module *M) const { + return getImportLoc(M).isValid(); + } + + /// \brief Get the location at which the import of a module was triggered. + SourceLocation getImportLoc(const Module *M) const { + return M->getVisibilityID() < ImportLocs.size() + ? ImportLocs[M->getVisibilityID()] + : SourceLocation(); + } + + /// \brief A callback to call when a module is made visible (directly or + /// indirectly) by a call to \ref setVisible. + typedef llvm::function_ref VisibleCallback; + /// \brief A callback to call when a module conflict is found. \p Path + /// consists of a sequence of modules from the conflicting module to the one + /// made visible, where each was exported by the next. + typedef llvm::function_ref Path, + Module *Conflict, StringRef Message)> + ConflictCallback; + /// \brief Make a specific module visible. + void setVisible(Module *M, SourceLocation Loc, + VisibleCallback Vis, ConflictCallback Cb); + +private: + /// Import locations for each visible module. Indexed by the module's + /// VisibilityID. + std::vector ImportLocs; + /// Visibility generation, bumped every time the visibility state changes. + unsigned Generation; +}; + } // end namespace clang diff --git a/include/clang/Frontend/ASTUnit.h b/include/clang/Frontend/ASTUnit.h index 238069db3b..405774b811 100644 --- a/include/clang/Frontend/ASTUnit.h +++ b/include/clang/Frontend/ASTUnit.h @@ -880,7 +880,7 @@ public: } void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc, bool Complain) override {} + SourceLocation ImportLoc) override {} GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override { return nullptr; } diff --git a/include/clang/Frontend/CompilerInstance.h b/include/clang/Frontend/CompilerInstance.h index 62515666d5..8d0d939d78 100644 --- a/include/clang/Frontend/CompilerInstance.h +++ b/include/clang/Frontend/CompilerInstance.h @@ -716,7 +716,7 @@ public: bool IsInclusionDirective) override; void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc, bool Complain) override; + SourceLocation ImportLoc) override; bool hadModuleLoaderFatalFailure() const { return ModuleLoader::HadFatalFailure; diff --git a/include/clang/Lex/ModuleLoader.h b/include/clang/Lex/ModuleLoader.h index 36605c9c18..ae79650d1f 100644 --- a/include/clang/Lex/ModuleLoader.h +++ b/include/clang/Lex/ModuleLoader.h @@ -99,8 +99,7 @@ public: /// \brief Make the given module visible. virtual void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc, - bool Complain) = 0; + SourceLocation ImportLoc) = 0; /// \brief Load, create, or return global module. /// This function returns an existing global module index, if one diff --git a/include/clang/Lex/ModuleMap.h b/include/clang/Lex/ModuleMap.h index d281421ee0..a15ac9e826 100644 --- a/include/clang/Lex/ModuleMap.h +++ b/include/clang/Lex/ModuleMap.h @@ -64,6 +64,9 @@ private: /// \brief The top-level modules that are known. llvm::StringMap Modules; + /// \brief The number of modules we have created in total. + unsigned NumCreatedModules; + public: /// \brief Flags describing the role of a module header. enum ModuleHeaderRole { diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 015957204b..9950974aeb 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -374,7 +374,7 @@ class Preprocessor : public RefCountedBase { /// The active module macros for this identifier. llvm::TinyPtrVector ActiveModuleMacros; /// The generation number at which we last updated ActiveModuleMacros. - /// \see Preprocessor::MacroVisibilityGeneration. + /// \see Preprocessor::VisibleModules. unsigned ActiveModuleMacrosGeneration; /// Whether this macro name is ambiguous. bool IsAmbiguous; @@ -391,7 +391,7 @@ class Preprocessor : public RefCountedBase { // FIXME: Find a spare bit on IdentifierInfo and store a // HasModuleMacros flag. if (!II->hasMacroDefinition() || !PP.getLangOpts().Modules || - !PP.MacroVisibilityGeneration) + !PP.VisibleModules.getGeneration()) return nullptr; auto *Info = State.dyn_cast(); @@ -401,7 +401,8 @@ class Preprocessor : public RefCountedBase { State = Info; } - if (PP.MacroVisibilityGeneration != Info->ActiveModuleMacrosGeneration) + if (PP.VisibleModules.getGeneration() != + Info->ActiveModuleMacrosGeneration) PP.updateModuleMacroInfo(II, *Info); return Info; } @@ -520,9 +521,8 @@ class Preprocessor : public RefCountedBase { llvm::DenseMap> LeafModuleMacros; - /// The generation number for module macros. Incremented each time the set - /// of modules with visible macros changes. - unsigned MacroVisibilityGeneration; + /// The current set of visible modules. + VisibleModuleSet VisibleModules; /// \brief Macros that we want to warn because they are not used at the end /// of the translation unit. @@ -1062,6 +1062,8 @@ public: void LexAfterModuleImport(Token &Result); + void makeModuleVisible(Module *M, SourceLocation Loc); + /// \brief Lex a string literal, which may be the concatenation of multiple /// string literals and may even come from macro expansion. /// \returns true on success, false if a error diagnostic has been generated. diff --git a/include/clang/Serialization/ASTReader.h b/include/clang/Serialization/ASTReader.h index 711bf4dbcb..8481aeba8d 100644 --- a/include/clang/Serialization/ASTReader.h +++ b/include/clang/Serialization/ASTReader.h @@ -1316,8 +1316,7 @@ public: /// \param Complain Whether to complain about conflicting module imports. void makeModuleVisible(Module *Mod, Module::NameVisibilityKind NameVisibility, - SourceLocation ImportLoc, - bool Complain); + SourceLocation ImportLoc); /// \brief Make the names within this set of hidden names visible. void makeNamesVisible(const HiddenNames &Names, Module *Owner); diff --git a/lib/Basic/Module.cpp b/lib/Basic/Module.cpp index 5fad1a9b22..97f0a035b0 100644 --- a/lib/Basic/Module.cpp +++ b/lib/Basic/Module.cpp @@ -25,14 +25,14 @@ using namespace clang; Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, - bool IsFramework, bool IsExplicit) + bool IsFramework, bool IsExplicit, unsigned VisibilityID) : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), Directory(), - Umbrella(), ASTFile(nullptr), IsMissingRequirement(false), - IsAvailable(true), IsFromModuleFile(false), IsFramework(IsFramework), - IsExplicit(IsExplicit), IsSystem(false), IsExternC(false), - IsInferred(false), InferSubmodules(false), InferExplicitSubmodules(false), - InferExportWildcard(false), ConfigMacrosExhaustive(false), - NameVisibility(Hidden) { + Umbrella(), ASTFile(nullptr), VisibilityID(VisibilityID), + IsMissingRequirement(false), IsAvailable(true), IsFromModuleFile(false), + IsFramework(IsFramework), IsExplicit(IsExplicit), IsSystem(false), + IsExternC(false), IsInferred(false), InferSubmodules(false), + InferExplicitSubmodules(false), InferExportWildcard(false), + ConfigMacrosExhaustive(false), NameVisibility(Hidden) { if (Parent) { if (!Parent->isAvailable()) IsAvailable = false; @@ -475,4 +475,47 @@ void Module::dump() const { print(llvm::errs()); } +void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc, + VisibleCallback Vis, ConflictCallback Cb) { + if (isVisible(M)) + return; + ++Generation; + + struct Visiting { + Module *M; + Visiting *ExportedBy; + }; + + std::function VisitModule = [&](Visiting V) { + // Modules that aren't available cannot be made visible. + if (!V.M->isAvailable()) + return; + + // Nothing to do for a module that's already visible. + unsigned ID = V.M->getVisibilityID(); + if (ImportLocs.size() <= ID) + ImportLocs.resize(ID + 1); + else if (ImportLocs[ID].isValid()) + return; + + ImportLocs[ID] = Loc; + Vis(M); + + // Make any exported modules visible. + SmallVector Exports; + V.M->getExportedModules(Exports); + for (Module *E : Exports) + VisitModule({E, &V}); + + for (auto &C : V.M->Conflicts) { + if (isVisible(C.Other)) { + llvm::SmallVector Path; + for (Visiting *I = &V; I; I = I->ExportedBy) + Path.push_back(I->M); + Cb(Path, C.Other, C.Message); + } + } + }; + VisitModule({M, nullptr}); +} diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index f6602c8b50..2583ad199d 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -1357,7 +1357,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule && ModuleName != getLangOpts().ImplementationOfModule) ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility, - ImportLoc, /*Complain=*/false); + ImportLoc); return LastModuleImportResult; } @@ -1600,8 +1600,7 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, return ModuleLoadResult(); } - ModuleManager->makeModuleVisible(Module, Visibility, ImportLoc, - /*Complain=*/true); + ModuleManager->makeModuleVisible(Module, Visibility, ImportLoc); } // Check for any configuration macros that have changed. @@ -1637,9 +1636,8 @@ CompilerInstance::loadModule(SourceLocation ImportLoc, void CompilerInstance::makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc, - bool Complain){ - ModuleManager->makeModuleVisible(Mod, Visibility, ImportLoc, Complain); + SourceLocation ImportLoc) { + ModuleManager->makeModuleVisible(Mod, Visibility, ImportLoc); } GlobalModuleIndex *CompilerInstance::loadGlobalModuleIndex( diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index a4f1c05dc1..29594994ff 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -89,7 +89,7 @@ ModuleMap::ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, HeaderSearch &HeaderInfo) : SourceMgr(SourceMgr), Diags(Diags), LangOpts(LangOpts), Target(Target), HeaderInfo(HeaderInfo), BuiltinIncludeDir(nullptr), - CompilingModule(nullptr), SourceModule(nullptr) { + CompilingModule(nullptr), SourceModule(nullptr), NumCreatedModules(0) { MMapLangOpts.LineComment = true; } @@ -563,7 +563,7 @@ ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework, // Create a new module with this name. Module *Result = new Module(Name, SourceLocation(), Parent, - IsFramework, IsExplicit); + IsFramework, IsExplicit, NumCreatedModules++); if (LangOpts.CurrentModule == Name) { SourceModule = Result; SourceModuleName = Name; @@ -693,7 +693,8 @@ Module *ModuleMap::inferFrameworkModule(StringRef ModuleName, return nullptr; Module *Result = new Module(ModuleName, SourceLocation(), Parent, - /*IsFramework=*/true, /*IsExplicit=*/false); + /*IsFramework=*/true, /*IsExplicit=*/false, + NumCreatedModules++); InferredModuleAllowedBy[Result] = ModuleMapFile; Result->IsInferred = true; if (LangOpts.CurrentModule == ModuleName) { diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 1c66aac533..7de6c14ef3 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1686,7 +1686,8 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, ModuleLoadResult Imported = TheModuleLoader.loadModule(IncludeTok.getLocation(), Path, Visibility, /*IsIncludeDirective=*/true); - ++MacroVisibilityGeneration; + if (Imported) + makeModuleVisible(Imported, IncludeTok.getLocation()); assert((Imported == nullptr || Imported == SuggestedModule.getModule()) && "the imported module is different than the suggested one"); @@ -1766,6 +1767,9 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, assert(!FID.isInvalid() && "Expected valid file ID"); // Determine if we're switching to building a new submodule, and which one. + // + // FIXME: If we've already processed this header, just make it visible rather + // than entering it again. ModuleMap::KnownHeader BuildingModule; if (getLangOpts().Modules && !getLangOpts().CurrentModule.empty()) { Module *RequestingModule = getModuleForLocation(FilenameLoc); diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index dc1b5bed04..6766fdfcd0 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -671,13 +671,7 @@ void Preprocessor::LeaveSubmodule() { Macro.second.setOverriddenMacros(SavedInfo.Overridden); } - if (Info.M->NameVisibility < Module::MacrosVisible) { - Info.M->NameVisibility = Module::MacrosVisible; - Info.M->MacroVisibilityLoc = Info.ImportLoc; - ++MacroVisibilityGeneration; - // FIXME: Also mark any exported modules as visible, and check for - // conflicts. - } + makeModuleVisible(Info.M, Info.ImportLoc); BuildingSubmoduleStack.pop_back(); } diff --git a/lib/Lex/PPMacroExpansion.cpp b/lib/Lex/PPMacroExpansion.cpp index fca3f8b97c..edeed42c17 100644 --- a/lib/Lex/PPMacroExpansion.cpp +++ b/lib/Lex/PPMacroExpansion.cpp @@ -124,9 +124,9 @@ ModuleMacro *Preprocessor::getModuleMacro(Module *Mod, IdentifierInfo *II) { void Preprocessor::updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info) { - assert(Info.ActiveModuleMacrosGeneration != MacroVisibilityGeneration && + assert(Info.ActiveModuleMacrosGeneration != VisibleModules.getGeneration() && "don't need to update this macro name info"); - Info.ActiveModuleMacrosGeneration = MacroVisibilityGeneration; + Info.ActiveModuleMacrosGeneration = VisibleModules.getGeneration(); auto Leaf = LeafModuleMacros.find(II); if (Leaf == LeafModuleMacros.end()) { @@ -146,7 +146,7 @@ void Preprocessor::updateModuleMacroInfo(const IdentifierInfo *II, Leaf->second.end()); while (!Worklist.empty()) { auto *MM = Worklist.pop_back_val(); - if (MM->getOwningModule()->NameVisibility >= Module::MacrosVisible) { + if (VisibleModules.isVisible(MM->getOwningModule())) { // We only care about collecting definitions; undefinitions only act // to override other definitions. if (MM->getMacroInfo()) @@ -236,7 +236,7 @@ void Preprocessor::dumpMacroInfo(const IdentifierInfo *II) { if (Active.count(MM)) llvm::errs() << " active"; - else if (MM->getOwningModule()->NameVisibility < Module::MacrosVisible) + else if (!VisibleModules.isVisible(MM->getOwningModule())) llvm::errs() << " hidden"; else llvm::errs() << " overridden"; diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 231720b8db..2db109565a 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -107,9 +107,6 @@ Preprocessor::Preprocessor(IntrusiveRefCntPtr PPOpts, // We haven't read anything from the external source. ReadMacrosFromExternalSource = false; - // We might already have some macros from an imported module (via a PCH or - // preamble) if modules is enabled. - MacroVisibilityGeneration = LangOpts.Modules ? 1 : 0; // "Poison" __VA_ARGS__, which can only appear in the expansion of a macro. // This gets unpoisoned where it is allowed. @@ -757,13 +754,34 @@ void Preprocessor::LexAfterModuleImport(Token &Result) { ModuleImportPath, Module::MacrosVisible, /*IsIncludeDirective=*/false); - ++MacroVisibilityGeneration; + if (Imported) + makeModuleVisible(Imported, ModuleImportLoc); } if (Callbacks && (getLangOpts().Modules || getLangOpts().DebuggerSupport)) Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported); } } +void Preprocessor::makeModuleVisible(Module *M, SourceLocation Loc) { + if (VisibleModules.isVisible(M)) + return; + + VisibleModules.setVisible( + M, Loc, [](Module *) {}, + [&](ArrayRef Path, Module *Conflict, StringRef Message) { + // FIXME: Include the path in the diagnostic. + // FIXME: Include the import location for the conflicting module. + Diag(ModuleImportLoc, diag::warn_module_conflict) + << Path[0]->getFullModuleName() + << Conflict->getFullModuleName() + << Message; + }); + + // Add this module to the imports list of the currently-built submodule. + if (!BuildingSubmoduleStack.empty()) + BuildingSubmoduleStack.back().M->Imports.push_back(M); +} + bool Preprocessor::FinishLexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion) { diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 34e5784e86..00922f73a8 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -14088,8 +14088,7 @@ void Sema::ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod) { checkModuleImportContext(*this, Mod, DirectiveLoc, CurContext); // FIXME: Should we synthesize an ImportDecl here? - getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, DirectiveLoc, - /*Complain=*/true); + getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, DirectiveLoc); } void Sema::createImplicitModuleImportForErrorRecovery(SourceLocation Loc, @@ -14106,8 +14105,7 @@ void Sema::createImplicitModuleImportForErrorRecovery(SourceLocation Loc, Consumer.HandleImplicitImportDecl(ImportD); // Make the module visible. - getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, Loc, - /*Complain=*/false); + getModuleLoader().makeModuleVisible(Mod, Module::AllVisible, Loc); } void Sema::ActOnPragmaRedefineExtname(IdentifierInfo* Name, diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 7225d2f610..d67d79b52d 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -3240,8 +3240,7 @@ void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { void ASTReader::makeModuleVisible(Module *Mod, Module::NameVisibilityKind NameVisibility, - SourceLocation ImportLoc, - bool Complain) { + SourceLocation ImportLoc) { llvm::SmallPtrSet Visited; SmallVector Stack; Stack.push_back(Mod); @@ -3285,20 +3284,6 @@ void ASTReader::makeModuleVisible(Module *Mod, if (Visited.insert(Exported).second) Stack.push_back(Exported); } - - // Detect any conflicts. - if (Complain) { - assert(ImportLoc.isValid() && "Missing import location"); - for (unsigned I = 0, N = Mod->Conflicts.size(); I != N; ++I) { - if (Mod->Conflicts[I].Other->NameVisibility >= NameVisibility) { - Diag(ImportLoc, diag::warn_module_conflict) - << Mod->getFullModuleName() - << Mod->Conflicts[I].Other->getFullModuleName() - << Mod->Conflicts[I].Message; - // FIXME: Need note where the other module was imported. - } - } - } } } @@ -3669,7 +3654,7 @@ ASTReader::ReadASTCore(StringRef FileName, return Success; } -void ASTReader::InitializeContext() { +void ASTReader::InitializeContext() { // If there's a listener, notify them that we "read" the translation unit. if (DeserializationListener) DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, @@ -3792,13 +3777,13 @@ void ASTReader::InitializeContext() { } // Re-export any modules that were imported by a non-module AST file. - // FIXME: This does not make macro-only imports visible again. It also doesn't - // make #includes mapped to module imports visible. + // FIXME: This does not make macro-only imports visible again. for (auto &Import : ImportedModules) { - if (Module *Imported = getSubmodule(Import.ID)) + if (Module *Imported = getSubmodule(Import.ID)) { makeModuleVisible(Imported, Module::AllVisible, - /*ImportLoc=*/Import.ImportLoc, - /*Complain=*/false); + /*ImportLoc=*/Import.ImportLoc); + PP.makeModuleVisible(Imported, Import.ImportLoc); + } } ImportedModules.clear(); } diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 3843697734..8a3b9d5163 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -2323,19 +2323,6 @@ static unsigned getNumberOfModules(Module *Mod) { } void ASTWriter::WriteSubmodules(Module *WritingModule) { - // Determine the dependencies of our module and each of it's submodules. - // FIXME: This feels like it belongs somewhere else, but there are no - // other consumers of this information. - SourceManager &SrcMgr = PP->getSourceManager(); - ModuleMap &ModMap = PP->getHeaderSearchInfo().getModuleMap(); - for (const auto *I : Context->local_imports()) { - if (Module *ImportedFrom - = ModMap.inferModuleFromLocation(FullSourceLoc(I->getLocation(), - SrcMgr))) { - ImportedFrom->Imports.push_back(I->getImportedModule()); - } - } - // Enter the submodule description block. Stream.EnterSubblock(SUBMODULE_BLOCK_ID, /*bits for abbreviations*/5); diff --git a/unittests/Basic/SourceManagerTest.cpp b/unittests/Basic/SourceManagerTest.cpp index 57b87b7604..a151bd5a1f 100644 --- a/unittests/Basic/SourceManagerTest.cpp +++ b/unittests/Basic/SourceManagerTest.cpp @@ -61,8 +61,7 @@ class VoidModuleLoader : public ModuleLoader { void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc, - bool Complain) override { } + SourceLocation ImportLoc) override { } GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override { return nullptr; } diff --git a/unittests/Lex/LexerTest.cpp b/unittests/Lex/LexerTest.cpp index 85987bf001..b5a39b303d 100644 --- a/unittests/Lex/LexerTest.cpp +++ b/unittests/Lex/LexerTest.cpp @@ -37,8 +37,7 @@ class VoidModuleLoader : public ModuleLoader { void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc, - bool Complain) override { } + SourceLocation ImportLoc) override { } GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override { return nullptr; } diff --git a/unittests/Lex/PPCallbacksTest.cpp b/unittests/Lex/PPCallbacksTest.cpp index da641a7afb..94812fc93d 100644 --- a/unittests/Lex/PPCallbacksTest.cpp +++ b/unittests/Lex/PPCallbacksTest.cpp @@ -42,8 +42,7 @@ class VoidModuleLoader : public ModuleLoader { void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc, - bool Complain) override { } + SourceLocation ImportLoc) override { } GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override { return nullptr; } diff --git a/unittests/Lex/PPConditionalDirectiveRecordTest.cpp b/unittests/Lex/PPConditionalDirectiveRecordTest.cpp index 946cb88b98..d2e3640501 100644 --- a/unittests/Lex/PPConditionalDirectiveRecordTest.cpp +++ b/unittests/Lex/PPConditionalDirectiveRecordTest.cpp @@ -61,8 +61,7 @@ class VoidModuleLoader : public ModuleLoader { void makeModuleVisible(Module *Mod, Module::NameVisibilityKind Visibility, - SourceLocation ImportLoc, - bool Complain) override { } + SourceLocation ImportLoc) override { } GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override { return nullptr; } -- 2.40.0