r236300 - [modules] Start moving the module visibility information off the Module itself.
Richard Smith
richard-llvm at metafoo.co.uk
Thu Apr 30 18:53:10 PDT 2015
Author: rsmith
Date: Thu Apr 30 20:53:09 2015
New Revision: 236300
URL: http://llvm.org/viewvc/llvm-project?rev=236300&view=rev
Log:
[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.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
cfe/trunk/include/clang/Basic/Module.h
cfe/trunk/include/clang/Frontend/ASTUnit.h
cfe/trunk/include/clang/Frontend/CompilerInstance.h
cfe/trunk/include/clang/Lex/ModuleLoader.h
cfe/trunk/include/clang/Lex/ModuleMap.h
cfe/trunk/include/clang/Lex/Preprocessor.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Basic/Module.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/lib/Lex/PPLexerChange.cpp
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/unittests/Basic/SourceManagerTest.cpp
cfe/trunk/unittests/Lex/LexerTest.cpp
cfe/trunk/unittests/Lex/PPCallbacksTest.cpp
cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Thu Apr 30 20:53:09 2015
@@ -638,7 +638,9 @@ def warn_non_modular_include_in_framewor
def warn_non_modular_include_in_module : Warning<
"include of non-modular header inside module '%0'">,
InGroup<NonModularIncludeInModule>, DefaultIgnore;
-
+def warn_module_conflict : Warning<
+ "module '%0' conflicts with already-imported module '%1': %2">,
+ InGroup<ModuleConflict>;
def warn_header_guard : Warning<
"%0 is used as a header guard here, followed by #define of a different macro">,
Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Thu Apr 30 20:53:09 2015
@@ -66,9 +66,6 @@ def err_imported_module_relocated : Erro
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<ModuleConflict>;
def err_pch_macro_def_undef : Error<
"macro '%0' was %select{defined|undef'd}1 in the precompiled header but "
Modified: cfe/trunk/include/clang/Basic/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Thu Apr 30 20:53:09 2015
@@ -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 <string>
@@ -85,6 +86,9 @@ private:
/// \brief Cache of modules visible to lookup in this module.
mutable llvm::DenseSet<const Module*> 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<Module *>::iterator submodule_iterator;
typedef std::vector<Module *>::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<void(Module *M)> 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<void(ArrayRef<Module *> 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<SourceLocation> ImportLocs;
+ /// Visibility generation, bumped every time the visibility state changes.
+ unsigned Generation;
+};
+
} // end namespace clang
Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/ASTUnit.h (original)
+++ cfe/trunk/include/clang/Frontend/ASTUnit.h Thu Apr 30 20:53:09 2015
@@ -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; }
Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Thu Apr 30 20:53:09 2015
@@ -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;
Modified: cfe/trunk/include/clang/Lex/ModuleLoader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleLoader.h?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleLoader.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleLoader.h Thu Apr 30 20:53:09 2015
@@ -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
Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Thu Apr 30 20:53:09 2015
@@ -64,6 +64,9 @@ private:
/// \brief The top-level modules that are known.
llvm::StringMap<Module *> 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 {
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Thu Apr 30 20:53:09 2015
@@ -374,7 +374,7 @@ class Preprocessor : public RefCountedBa
/// The active module macros for this identifier.
llvm::TinyPtrVector<ModuleMacro*> 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 RefCountedBa
// 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<ModuleMacroInfo*>();
@@ -401,7 +401,8 @@ class Preprocessor : public RefCountedBa
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 RefCountedBa
llvm::DenseMap<const IdentifierInfo *, llvm::TinyPtrVector<ModuleMacro*>>
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.
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Thu Apr 30 20:53:09 2015
@@ -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);
Modified: cfe/trunk/lib/Basic/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Module.cpp (original)
+++ cfe/trunk/lib/Basic/Module.cpp Thu Apr 30 20:53:09 2015
@@ -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<void(Visiting)> 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<Module *, 16> Exports;
+ V.M->getExportedModules(Exports);
+ for (Module *E : Exports)
+ VisitModule({E, &V});
+
+ for (auto &C : V.M->Conflicts) {
+ if (isVisible(C.Other)) {
+ llvm::SmallVector<Module*, 8> Path;
+ for (Visiting *I = &V; I; I = I->ExportedBy)
+ Path.push_back(I->M);
+ Cb(Path, C.Other, C.Message);
+ }
+ }
+ };
+ VisitModule({M, nullptr});
+}
Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Apr 30 20:53:09 2015
@@ -1357,7 +1357,7 @@ CompilerInstance::loadModule(SourceLocat
if (LastModuleImportResult && ModuleName != getLangOpts().CurrentModule &&
ModuleName != getLangOpts().ImplementationOfModule)
ModuleManager->makeModuleVisible(LastModuleImportResult, Visibility,
- ImportLoc, /*Complain=*/false);
+ ImportLoc);
return LastModuleImportResult;
}
@@ -1600,8 +1600,7 @@ CompilerInstance::loadModule(SourceLocat
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(SourceLocat
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(
Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Thu Apr 30 20:53:09 2015
@@ -89,7 +89,7 @@ ModuleMap::ModuleMap(SourceManager &Sour
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
// 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(
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) {
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Thu Apr 30 20:53:09 2015
@@ -1686,7 +1686,8 @@ void Preprocessor::HandleIncludeDirectiv
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::HandleIncludeDirectiv
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);
Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Thu Apr 30 20:53:09 2015
@@ -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();
}
Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Thu Apr 30 20:53:09 2015
@@ -124,9 +124,9 @@ ModuleMacro *Preprocessor::getModuleMacr
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
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 I
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";
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Thu Apr 30 20:53:09 2015
@@ -107,9 +107,6 @@ Preprocessor::Preprocessor(IntrusiveRefC
// 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(
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<Module *> 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) {
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Apr 30 20:53:09 2015
@@ -14088,8 +14088,7 @@ void Sema::ActOnModuleInclude(SourceLoca
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::createImplicitModuleImportFor
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,
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Apr 30 20:53:09 2015
@@ -3240,8 +3240,7 @@ void ASTReader::makeNamesVisible(const H
void ASTReader::makeModuleVisible(Module *Mod,
Module::NameVisibilityKind NameVisibility,
- SourceLocation ImportLoc,
- bool Complain) {
+ SourceLocation ImportLoc) {
llvm::SmallPtrSet<Module *, 4> Visited;
SmallVector<Module *, 4> Stack;
Stack.push_back(Mod);
@@ -3285,20 +3284,6 @@ void ASTReader::makeModuleVisible(Module
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 FileNam
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();
}
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Apr 30 20:53:09 2015
@@ -2323,19 +2323,6 @@ static unsigned getNumberOfModules(Modul
}
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);
Modified: cfe/trunk/unittests/Basic/SourceManagerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/SourceManagerTest.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/unittests/Basic/SourceManagerTest.cpp (original)
+++ cfe/trunk/unittests/Basic/SourceManagerTest.cpp Thu Apr 30 20:53:09 2015
@@ -61,8 +61,7 @@ class VoidModuleLoader : public ModuleLo
void makeModuleVisible(Module *Mod,
Module::NameVisibilityKind Visibility,
- SourceLocation ImportLoc,
- bool Complain) override { }
+ SourceLocation ImportLoc) override { }
GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
{ return nullptr; }
Modified: cfe/trunk/unittests/Lex/LexerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/LexerTest.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/LexerTest.cpp (original)
+++ cfe/trunk/unittests/Lex/LexerTest.cpp Thu Apr 30 20:53:09 2015
@@ -37,8 +37,7 @@ class VoidModuleLoader : public ModuleLo
void makeModuleVisible(Module *Mod,
Module::NameVisibilityKind Visibility,
- SourceLocation ImportLoc,
- bool Complain) override { }
+ SourceLocation ImportLoc) override { }
GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
{ return nullptr; }
Modified: cfe/trunk/unittests/Lex/PPCallbacksTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/PPCallbacksTest.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/PPCallbacksTest.cpp (original)
+++ cfe/trunk/unittests/Lex/PPCallbacksTest.cpp Thu Apr 30 20:53:09 2015
@@ -42,8 +42,7 @@ class VoidModuleLoader : public ModuleLo
void makeModuleVisible(Module *Mod,
Module::NameVisibilityKind Visibility,
- SourceLocation ImportLoc,
- bool Complain) override { }
+ SourceLocation ImportLoc) override { }
GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
{ return nullptr; }
Modified: cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp?rev=236300&r1=236299&r2=236300&view=diff
==============================================================================
--- cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp (original)
+++ cfe/trunk/unittests/Lex/PPConditionalDirectiveRecordTest.cpp Thu Apr 30 20:53:09 2015
@@ -61,8 +61,7 @@ class VoidModuleLoader : public ModuleLo
void makeModuleVisible(Module *Mod,
Module::NameVisibilityKind Visibility,
- SourceLocation ImportLoc,
- bool Complain) override { }
+ SourceLocation ImportLoc) override { }
GlobalModuleIndex *loadGlobalModuleIndex(SourceLocation TriggerLoc) override
{ return nullptr; }
More information about the cfe-commits
mailing list