[cfe-commits] r68665 - /cfe/trunk/tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Wed Apr 8 17:51:16 PDT 2009


Author: ddunbar
Date: Wed Apr  8 19:51:16 2009
New Revision: 68665

URL: http://llvm.org/viewvc/llvm-project?rev=68665&view=rev
Log:
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

Modified:
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68665&r1=68664&r2=68665&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Apr  8 19:51:16 2009
@@ -1006,28 +1006,37 @@
   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"; // ##?





More information about the cfe-commits mailing list