summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2011-03-08 16:04:35 +0000
committerAnders Carlsson <andersca@mac.com>2011-03-08 16:04:35 +0000
commita426705cc6c70064d059036f1db0c92715d51cee (patch)
treeca684ef93340fe89ccd574e366b94004145031df
parent679cfb54ecca9f631f1183cce1b9aa1f6fdb41af (diff)
downloadbcm5719-llvm-a426705cc6c70064d059036f1db0c92715d51cee.tar.gz
bcm5719-llvm-a426705cc6c70064d059036f1db0c92715d51cee.zip
When writing file references in a pch, make sure to ask the file manager for the absolute path.
llvm-svn: 127248
-rw-r--r--clang/lib/Serialization/ASTWriter.cpp7
-rw-r--r--clang/test/PCH/Inputs/working-directory-1.h5
-rw-r--r--clang/test/PCH/working-directory.cpp12
-rw-r--r--clang/test/PCH/working-directory.h1
4 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index f172b7aceca..1cb195dd310 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -1460,6 +1460,13 @@ void ASTWriter::WriteSourceManagerBlock(SourceManager &SourceMgr,
// 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();
diff --git a/clang/test/PCH/Inputs/working-directory-1.h b/clang/test/PCH/Inputs/working-directory-1.h
new file mode 100644
index 00000000000..e42eda45c87
--- /dev/null
+++ b/clang/test/PCH/Inputs/working-directory-1.h
@@ -0,0 +1,5 @@
+template<typename T> struct A {
+ A() {
+ int a;
+ }
+};
diff --git a/clang/test/PCH/working-directory.cpp b/clang/test/PCH/working-directory.cpp
new file mode 100644
index 00000000000..e77d31b4be6
--- /dev/null
+++ b/clang/test/PCH/working-directory.cpp
@@ -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;
+}
diff --git a/clang/test/PCH/working-directory.h b/clang/test/PCH/working-directory.h
new file mode 100644
index 00000000000..02a60e3e763
--- /dev/null
+++ b/clang/test/PCH/working-directory.h
@@ -0,0 +1 @@
+#include <Inputs/working-directory-1.h>
OpenPOWER on IntegriCloud