// 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()) {
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())
.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;
Error("too many submodules");
return true;
}
-
+
+ if (const FileEntry *CurFile = CurrentModule->getASTFile()) {
+ if (CurFile != F.File) {
+ if (!Diags.isDiagnosticInFlight()) {
+ Diag(diag::err_module_file_conflict)
+ << CurrentModule->getTopLevelModuleName()
+ << CurFile->getName()
+ << F.File->getName();
+ }
+ return true;
+ }
+ }
CurrentModule->setASTFile(F.File);
CurrentModule->IsFromModuleFile = true;
CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem;
--- /dev/null
+// First trial: pass -DIGNORED=1 to both. It should be ignored in both
+// RUN: rm -rf %t.modules
+// RUN: %clang_cc1 -fmodule-cache-path %t.modules -DIGNORED=1 -fmodules -I %S/Inputs -emit-pch -o %t.pch -x objective-c-header %s -verify
+// RUN: %clang_cc1 -fmodule-cache-path %t.modules -DIGNORED=1 -fmodules -I %S/Inputs -include-pch %t.pch %s -verify
+
+// Second trial: pass -DIGNORED=1 only to the second invocation.
+// RUN: rm -rf %t.modules
+// RUN: %clang_cc1 -fmodule-cache-path %t.modules -fmodules -I %S/Inputs -emit-pch -o %t.pch -x objective-c-header %s -verify
+// RUN: not %clang_cc1 -fmodule-cache-path %t.modules -DIGNORED=1 -fmodules -I %S/Inputs -include-pch %t.pch %s > %t.err 2>&1
+// RUN: FileCheck -check-prefix=CHECK-CONFLICT %s < %t.err
+// CHECK-CONFLICT: module 'ignored_macros' found in both
+
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+@import ignored_macros;
+#endif
+
+@import ignored_macros;
+
+struct Point p;