From: Anders Carlsson Date: Tue, 8 Mar 2011 16:04:35 +0000 (+0000) Subject: When writing file references in a pch, make sure to ask the file manager for the... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c10c8072cabeb22651462e435e8b81f3221b6a5;p=clang When writing file references in a pch, make sure to ask the file manager for the absolute path. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127248 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index f172b7acec..1cb195dd31 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/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/test/PCH/Inputs/working-directory-1.h b/test/PCH/Inputs/working-directory-1.h new file mode 100644 index 0000000000..e42eda45c8 --- /dev/null +++ b/test/PCH/Inputs/working-directory-1.h @@ -0,0 +1,5 @@ +template struct A { + A() { + int a; + } +}; diff --git a/test/PCH/working-directory.cpp b/test/PCH/working-directory.cpp new file mode 100644 index 0000000000..e77d31b4be --- /dev/null +++ b/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 will trigger a warning, which will end up trying to get the path to + // the header that contains A. + A b; +} diff --git a/test/PCH/working-directory.h b/test/PCH/working-directory.h new file mode 100644 index 0000000000..02a60e3e76 --- /dev/null +++ b/test/PCH/working-directory.h @@ -0,0 +1 @@ +#include