aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/ModuleMap.cpp
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2018-01-04 07:31:24 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2018-01-04 07:31:24 +0000
commitfec26b0bbba9f7c1704f021c1d830bb012578674 (patch)
treeda8a037faa566951a59fa9e6f2ff9a0397d329fd /clang/lib/Lex/ModuleMap.cpp
parentb8f2978bec86d1f4d04f4e1eebbfa9e7bada0c9a (diff)
downloadllvm-fec26b0bbba9f7c1704f021c1d830bb012578674.zip
llvm-fec26b0bbba9f7c1704f021c1d830bb012578674.tar.gz
llvm-fec26b0bbba9f7c1704f021c1d830bb012578674.tar.bz2
Revert "[Modules] Allow modules specified by -fmodule-map-file to shadow implicitly found ones"
This reverts r321781 until I fix the leaks pointed out by bots: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/12146 http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/3741 llvm-svn: 321786
Diffstat (limited to 'clang/lib/Lex/ModuleMap.cpp')
-rw-r--r--clang/lib/Lex/ModuleMap.cpp100
1 files changed, 32 insertions, 68 deletions
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index c2ea64f..b3ac10c 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -744,13 +744,14 @@ Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) const{
return Context->findSubmodule(Name);
}
-std::pair<Module *, bool>
-ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
- bool IsExplicit, bool UsesExplicitModuleMapFile) {
+std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name,
+ Module *Parent,
+ bool IsFramework,
+ bool IsExplicit) {
// Try to find an existing module with this name.
if (Module *Sub = lookupModuleQualified(Name, Parent))
return std::make_pair(Sub, false);
-
+
// Create a new module with this name.
Module *Result = new Module(Name, SourceLocation(), Parent, IsFramework,
IsExplicit, NumCreatedModules++);
@@ -758,8 +759,6 @@ ModuleMap::findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework,
if (LangOpts.CurrentModule == Name)
SourceModule = Result;
Modules[Name] = Result;
- if (UsesExplicitModuleMapFile)
- ExplicitlyProvidedModules.insert(Result);
}
return std::make_pair(Result, true);
}
@@ -1000,19 +999,6 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
return Result;
}
-Module *ModuleMap::createShadowedModule(StringRef Name, bool IsFramework,
- Module *ShadowingModule) {
-
- // Create a new module with this name.
- Module *Result =
- new Module(Name, SourceLocation(), /*Parent=*/nullptr, IsFramework,
- /*IsExplicit=*/false, NumCreatedModules++);
- Result->ShadowingModule = ShadowingModule;
- Result->IsAvailable = false;
-
- return Result;
-}
-
void ModuleMap::setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
Twine NameAsWritten) {
Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
@@ -1130,11 +1116,6 @@ void ModuleMap::excludeHeader(Module *Mod, Module::Header Header) {
Mod->Headers[Module::HK_Excluded].push_back(std::move(Header));
}
-void ModuleMap::setExplicitlyProvided(Module *Mod) {
- assert(Modules[Mod->Name] == Mod && "explicitly provided module is shadowed");
- ExplicitlyProvidedModules.insert(Mod);
-}
-
const FileEntry *
ModuleMap::getContainingModuleMapFile(const Module *Module) const {
if (Module->DefinitionLoc.isInvalid())
@@ -1338,9 +1319,7 @@ namespace clang {
/// \brief Consume the current token and return its location.
SourceLocation consumeToken();
-
- bool UsesExplicitModuleMapFile = false;
-
+
/// \brief Skip tokens until we reach the a token with the given kind
/// (or the end of the file).
void skipUntil(MMToken::TokenKind K);
@@ -1366,19 +1345,20 @@ namespace clang {
bool parseOptionalAttributes(Attributes &Attrs);
public:
- explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr,
- const TargetInfo *Target, DiagnosticsEngine &Diags,
- ModuleMap &Map, const FileEntry *ModuleMapFile,
- const DirectoryEntry *Directory, bool IsSystem,
- bool UsesExplicitModuleMapFile)
+ explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr,
+ const TargetInfo *Target,
+ DiagnosticsEngine &Diags,
+ ModuleMap &Map,
+ const FileEntry *ModuleMapFile,
+ const DirectoryEntry *Directory,
+ bool IsSystem)
: L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map),
ModuleMapFile(ModuleMapFile), Directory(Directory),
- IsSystem(IsSystem),
- UsesExplicitModuleMapFile(UsesExplicitModuleMapFile) {
+ IsSystem(IsSystem) {
Tok.clear();
consumeToken();
}
-
+
bool parseModuleMapFile();
bool terminatedByDirective() { return false; }
@@ -1807,7 +1787,6 @@ void ModuleMapParser::parseModuleDecl() {
SourceLocation LBraceLoc = consumeToken();
// Determine whether this (sub)module has already been defined.
- Module *ShadowingModule = nullptr;
if (Module *Existing = Map.lookupModuleQualified(ModuleName, ActiveModule)) {
// We might see a (re)definition of a module that we already have a
// definition for in two cases:
@@ -1833,36 +1812,23 @@ void ModuleMapParser::parseModuleDecl() {
}
return;
}
-
- if (!Existing->Parent &&
- Map.mayShadowModuleBeingParsed(Existing, UsesExplicitModuleMapFile)) {
- ShadowingModule = Existing;
- } else {
- // This is not a shawdowed module decl, it is an illegal redefinition.
- Diags.Report(ModuleNameLoc, diag::err_mmap_module_redefinition)
- << ModuleName;
- Diags.Report(Existing->DefinitionLoc, diag::note_mmap_prev_definition);
-
- // Skip the module definition.
- skipUntil(MMToken::RBrace);
- if (Tok.is(MMToken::RBrace))
- consumeToken();
-
- HadError = true;
- return;
- }
+
+ Diags.Report(ModuleNameLoc, diag::err_mmap_module_redefinition)
+ << ModuleName;
+ Diags.Report(Existing->DefinitionLoc, diag::note_mmap_prev_definition);
+
+ // Skip the module definition.
+ skipUntil(MMToken::RBrace);
+ if (Tok.is(MMToken::RBrace))
+ consumeToken();
+
+ HadError = true;
+ return;
}
// Start defining this module.
- if (ShadowingModule) {
- ActiveModule =
- Map.createShadowedModule(ModuleName, Framework, ShadowingModule);
- } else {
- ActiveModule = Map.findOrCreateModule(ModuleName, ActiveModule, Framework,
- Explicit, UsesExplicitModuleMapFile)
- .first;
- }
-
+ ActiveModule = Map.findOrCreateModule(ModuleName, ActiveModule, Framework,
+ Explicit).first;
ActiveModule->DefinitionLoc = ModuleNameLoc;
if (Attrs.IsSystem || IsSystem)
ActiveModule->IsSystem = true;
@@ -2038,7 +2004,7 @@ void ModuleMapParser::parseExternModuleDecl() {
Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd
? Directory
: File->getDir(),
- false /*IsExplicitlyProvided*/, FileID(), nullptr, ExternLoc);
+ FileID(), nullptr, ExternLoc);
}
/// Whether to add the requirement \p Feature to the module \p M.
@@ -2845,8 +2811,7 @@ bool ModuleMapParser::parseModuleMapFile() {
}
bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
- const DirectoryEntry *Dir,
- bool IsExplicitlyProvided, FileID ID,
+ const DirectoryEntry *Dir, FileID ID,
unsigned *Offset,
SourceLocation ExternModuleLoc) {
assert(Target && "Missing target information");
@@ -2876,7 +2841,7 @@ bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
Buffer->getBufferEnd());
SourceLocation Start = L.getSourceLocation();
ModuleMapParser Parser(L, SourceMgr, Target, Diags, *this, File, Dir,
- IsSystem, IsExplicitlyProvided);
+ IsSystem);
bool Result = Parser.parseModuleMapFile();
ParsedModuleMap[File] = Result;
@@ -2889,6 +2854,5 @@ bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
// Notify callbacks that we parsed it.
for (const auto &Cb : Callbacks)
Cb->moduleMapFileRead(Start, *File, IsSystem);
-
return Result;
}