From: Daniel Dunbar Date: Wed, 22 Apr 2009 08:53:01 +0000 (+0000) Subject: Add another workaround for -include. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1e7c6b67879b41369d5e8ddadb8aa6cef9013910;p=clang 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 746eba9cf2..f9929d1558 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -54,11 +54,17 @@ static void DefineBuiltinMacro(std::vector &Buf, const char *Macro, /// Add the quoted name of an implicit include file. static void AddQuotedIncludePath(std::vector &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('"');