Add another workaround for -include.
- If we don't find a file looking relative to the current working
directory, fall back to header search. This is closer to what would
happen if the lookup was starting from right directory in the first
place (except it will find files in the directory of the main
source file, which I *think* should not be found).
- PR3992.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69794 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index 746eba9..f9929d1 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -54,11 +54,17 @@
/// Add the quoted name of an implicit include file.
static void AddQuotedIncludePath(std::vector<char> &Buf,
const std::string &File) {
- // Implicit include paths are relative to the current working
- // directory; resolve them now instead of using the normal machinery
- // (which would look relative to the input file).
+ // Implicit include paths should be resolved relative to the current
+ // working directory first, and then use the regular header search
+ // mechanism. The proper way to handle this is to have the
+ // predefines buffer located at the current working directory, but
+ // it has not file entry. For now, workaround this by using an
+ // absolute path if we find the file here, and otherwise letting
+ // header search handle it.
llvm::sys::Path Path(File);
Path.makeAbsolute();
+ if (!Path.exists())
+ Path = File;
// Escape double quotes etc.
Buf.push_back('"');