summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-02-06 22:40:31 +0000
committerDouglas Gregor <dgregor@apple.com>2013-02-06 22:40:31 +0000
commit8a114ab557f04ac015dc67a4d92ddeb8978833e0 (patch)
treeba9747a1c74fb35ea146d1da8ff342ea82f81a6c /clang/lib/Frontend/CompilerInstance.cpp
parentd5d4c89bf0484422d52857d193fbced51472d5d1 (diff)
downloadbcm5719-llvm-8a114ab557f04ac015dc67a4d92ddeb8978833e0.tar.gz
bcm5719-llvm-8a114ab557f04ac015dc67a4d92ddeb8978833e0.zip
Detect when we end up trying to load conflicting module files.
This can happen when one abuses precompiled headers by passing more -D options when using a precompiled hedaer than when it was built. This is intentionally permitted by precompiled headers (and is exploited by some build environments), but causes problems for modules. First part of <rdar://problem/13165109>, detecting when something when horribly wrong. llvm-svn: 174554
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index d4a351394a2..b6115ec6ffa 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -915,9 +915,9 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
// Search for a module with the given name.
Module = PP->getHeaderSearchInfo().lookupModule(ModuleName);
std::string ModuleFileName;
- if (Module)
+ if (Module) {
ModuleFileName = PP->getHeaderSearchInfo().getModuleFileName(Module);
- else
+ } else
ModuleFileName = PP->getHeaderSearchInfo().getModuleFileName(ModuleName);
if (ModuleFileName.empty()) {
@@ -987,6 +987,20 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
return ModuleLoadResult();
}
+ // If there is already a module file associated with this module, make sure
+ // it is the same as the module file we're looking for. Otherwise, we
+ // have two module files for the same module.
+ if (const FileEntry *CurModuleFile = Module? Module->getASTFile() : 0) {
+ if (CurModuleFile != ModuleFile) {
+ getDiagnostics().Report(ModuleNameLoc, diag::err_module_file_conflict)
+ << ModuleName
+ << CurModuleFile->getName()
+ << ModuleFile->getName();
+ ModuleBuildFailed = true;
+ return ModuleLoadResult();
+ }
+ }
+
// If we don't already have an ASTReader, create one now.
if (!ModuleManager) {
if (!hasASTContext())
@@ -1085,8 +1099,9 @@ CompilerInstance::loadModule(SourceLocation ImportLoc,
.findModule((Path[0].first->getName()));
}
- if (Module)
+ if (Module) {
Module->setASTFile(ModuleFile);
+ }
// Cache the result of this top-level module lookup for later.
Known = KnownModules.insert(std::make_pair(Path[0].first, Module)).first;
OpenPOWER on IntegriCloud