diff options
| author | Manuel Klimek <klimek@google.com> | 2017-07-25 10:22:06 +0000 |
|---|---|---|
| committer | Manuel Klimek <klimek@google.com> | 2017-07-25 10:22:06 +0000 |
| commit | 1b29b4f9533a012755c78383dc93256c4a0b306d (patch) | |
| tree | 1363d72f0bd7513ef0698b1858f0597f1b7cf878 /clang/lib | |
| parent | e235bd1d03234873047357656f32659b84f1c62f (diff) | |
| download | bcm5719-llvm-1b29b4f9533a012755c78383dc93256c4a0b306d.tar.gz bcm5719-llvm-1b29b4f9533a012755c78383dc93256c4a0b306d.zip | |
Fix incorrect use of current directory to find moved paths in ASTReader.
CurrentDir was set as the path of the current module, but that can change as
part of a chain of loaded modules.
When we try to locate a file mentioned in a module that does not exist, we use
a heuristic to look at the relative path between the original location of the
module and the file we look for, and use that relatively to the CurrentDir.
This only works if CurrentDir is the same as the (current) path of the module
file the file was mentioned in; if it is not, we look at the path relatively to
the wrong directory, and can end up reading random unrelated files that happen
to have the same name.
This patch fixes this by using the BaseDirectory of the module file the file
we look for was mentioned in instead of the CurrentDir heuristic.
Differential Revision: https://reviews.llvm.org/D35828
llvm-svn: 308962
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 50be74f6bf6..cae99e8bf0a 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2060,14 +2060,12 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { StringRef Filename = FI.Filename; const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false); - // If we didn't find the file, resolve it relative to the // original directory from which this AST file was created. - if (File == nullptr && !F.OriginalDir.empty() && !CurrentDir.empty() && - F.OriginalDir != CurrentDir) { - std::string Resolved = resolveFileRelativeToOriginalDir(Filename, - F.OriginalDir, - CurrentDir); + if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() && + F.OriginalDir != F.BaseDirectory) { + std::string Resolved = resolveFileRelativeToOriginalDir( + Filename, F.OriginalDir, F.BaseDirectory); if (!Resolved.empty()) File = FileMgr.getFile(Resolved); } @@ -4065,13 +4063,6 @@ ASTReader::ReadASTCore(StringRef FileName, assert(M && "Missing module file"); - // FIXME: This seems rather a hack. Should CurrentDir be part of the - // module? - if (FileName != "-") { - CurrentDir = llvm::sys::path::parent_path(FileName); - if (CurrentDir.empty()) CurrentDir = "."; - } - ModuleFile &F = *M; BitstreamCursor &Stream = F.Stream; Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer)); |

