[cfe-commits] r127248 - in /cfe/trunk: lib/Serialization/ASTWriter.cpp test/PCH/Inputs/working-directory-1.h test/PCH/working-directory.cpp test/PCH/working-directory.h

Anders Carlsson andersca at mac.com
Tue Mar 8 08:04:35 PST 2011


Author: andersca
Date: Tue Mar  8 10:04:35 2011
New Revision: 127248

URL: http://llvm.org/viewvc/llvm-project?rev=127248&view=rev
Log:
When writing file references in a pch, make sure to ask the file manager for the absolute path.

Added:
    cfe/trunk/test/PCH/Inputs/working-directory-1.h
    cfe/trunk/test/PCH/working-directory.cpp
    cfe/trunk/test/PCH/working-directory.h
Modified:
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=127248&r1=127247&r2=127248&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Tue Mar  8 10:04:35 2011
@@ -1460,6 +1460,13 @@
         // Turn the file name into an absolute path, if it isn't already.
         const char *Filename = Content->OrigEntry->getName();
         llvm::SmallString<128> FilePath(Filename);
+
+        // Ask the file manager to fixup the relative path for us. This will 
+        // honor the working directory.
+        SourceMgr.getFileManager().FixupRelativePath(FilePath);
+
+        // FIXME: This call to make_absolute shouldn't be necessary, the
+        // call to FixupRelativePath should always return an absolute path.
         llvm::sys::fs::make_absolute(FilePath);
         Filename = FilePath.c_str();
 

Added: cfe/trunk/test/PCH/Inputs/working-directory-1.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/Inputs/working-directory-1.h?rev=127248&view=auto
==============================================================================
--- cfe/trunk/test/PCH/Inputs/working-directory-1.h (added)
+++ cfe/trunk/test/PCH/Inputs/working-directory-1.h Tue Mar  8 10:04:35 2011
@@ -0,0 +1,5 @@
+template<typename T> struct A {
+  A() {
+    int a;
+  }
+};

Added: cfe/trunk/test/PCH/working-directory.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/working-directory.cpp?rev=127248&view=auto
==============================================================================
--- cfe/trunk/test/PCH/working-directory.cpp (added)
+++ cfe/trunk/test/PCH/working-directory.cpp Tue Mar  8 10:04:35 2011
@@ -0,0 +1,12 @@
+// Test this without pch.
+// RUN: %clang_cc1 -working-directory %S -I. -include working-directory.h %s -Wunused
+
+// Test with pch.
+// RUN: %clang_cc1 -working-directory %S -x c++-header -emit-pch -o %t.pch -I. working-directory.h
+// RUN: %clang_cc1 -include-pch %t.pch -fsyntax-only %s -Wunused
+
+void f() {
+  // Instantiating A<char> will trigger a warning, which will end up trying to get the path to
+  // the header that contains A.
+  A<char> b;
+}

Added: cfe/trunk/test/PCH/working-directory.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/working-directory.h?rev=127248&view=auto
==============================================================================
--- cfe/trunk/test/PCH/working-directory.h (added)
+++ cfe/trunk/test/PCH/working-directory.h Tue Mar  8 10:04:35 2011
@@ -0,0 +1 @@
+#include <Inputs/working-directory-1.h>





More information about the cfe-commits mailing list