From 223d3f2e4d49c52b0b5516f001d1827c6e55d44b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 6 Dec 2014 03:21:08 +0000 Subject: [modules] If we import a module, and we've seen a module map that describes the module, use the path from the module map file in preference to the path from the .pcm file when resolving relative paths in the .pcm file. This allows diagnostics (and .d output) to give relative paths if the module was found via a relative path. llvm-svn: 223577 --- clang/lib/Serialization/ASTReader.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'clang/lib') diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index e1c418b30c8..eea4ba84b0c 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2508,9 +2508,31 @@ ASTReader::ReadControlBlock(ModuleFile &F, Listener->ReadModuleName(F.ModuleName); break; - case MODULE_DIRECTORY: - F.BaseDirectory = Blob; + case MODULE_DIRECTORY: { + assert(!F.ModuleName.empty() && + "MODULE_DIRECTORY found before MODULE_NAME"); + // If we've already loaded a module map file covering this module, we may + // have a better path for it (relative to the current build). + Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); + if (M && M->Directory) { + // If we're implicitly loading a module, the base directory can't + // change between the build and use. + if (F.Kind != MK_ExplicitModule) { + const DirectoryEntry *BuildDir = + PP.getFileManager().getDirectory(Blob); + if (!BuildDir || BuildDir != M->Directory) { + if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) + Diag(diag::err_imported_module_relocated) + << F.ModuleName << Blob << M->Directory->getName(); + return OutOfDate; + } + } + F.BaseDirectory = M->Directory->getName(); + } else { + F.BaseDirectory = Blob; + } break; + } case MODULE_MAP_FILE: if (ASTReadResult Result = -- cgit v1.2.3