diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2009-04-09 00:51:16 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2009-04-09 00:51:16 +0000 |
| commit | f67829ac6a19e9d82fd9c051347455efd03bb54b (patch) | |
| tree | 0ffb1f70abe7c2228cf53db92e52d782935cac1e | |
| parent | f02d62deebfb9b9bf9ffc517a04855bd2ed60224 (diff) | |
| download | bcm5719-llvm-f67829ac6a19e9d82fd9c051347455efd03bb54b.tar.gz bcm5719-llvm-f67829ac6a19e9d82fd9c051347455efd03bb54b.zip | |
Make -include, -imacros paths absolute in Frontend.
- Otherwise paths will be resolved relative to the main input file,
which is incorrect.
- I don't know how to make a reasonable test case for this with our
testing infrastructure.
- PR3395
llvm-svn: 68665
| -rw-r--r-- | clang/tools/clang-cc/clang-cc.cpp | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/clang/tools/clang-cc/clang-cc.cpp b/clang/tools/clang-cc/clang-cc.cpp index ea65c0f8cf7..3c06ea736ca 100644 --- a/clang/tools/clang-cc/clang-cc.cpp +++ b/clang/tools/clang-cc/clang-cc.cpp @@ -1006,28 +1006,37 @@ static void DefineBuiltinMacro(std::vector<char> &Buf, const char *Macro, Buf.push_back('\n'); } -/// AddImplicitInclude - Add an implicit #include of the specified file to the -/// predefines buffer. -static void AddImplicitInclude(std::vector<char> &Buf, const std::string &File){ - const char *Inc = "#include \""; - Buf.insert(Buf.end(), Inc, Inc+strlen(Inc)); - +/// 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). + llvm::sys::Path Path(File); + Path.makeAbsolute(); + // Escape double quotes etc. - std::string EscapedFile = Lexer::Stringify(File); + Buf.push_back('"'); + std::string EscapedFile = Lexer::Stringify(Path.toString()); Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end()); Buf.push_back('"'); +} + +/// AddImplicitInclude - Add an implicit #include of the specified file to the +/// predefines buffer. +static void AddImplicitInclude(std::vector<char> &Buf, + const std::string &File) { + const char *Inc = "#include "; + Buf.insert(Buf.end(), Inc, Inc+strlen(Inc)); + AddQuotedIncludePath(Buf, File); Buf.push_back('\n'); } static void AddImplicitIncludeMacros(std::vector<char> &Buf, const std::string &File) { - const char *Inc = "#__include_macros \""; + const char *Inc = "#__include_macros "; Buf.insert(Buf.end(), Inc, Inc+strlen(Inc)); - - // Escape double quotes etc. - std::string EscapedFile = Lexer::Stringify(File); - Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end()); - Buf.push_back('"'); + AddQuotedIncludePath(Buf, File); Buf.push_back('\n'); // Marker token to stop the __include_macros fetch loop. const char *Marker = "##\n"; // ##? |

