]> granicus.if.org Git - clang/commitdiff
Tweak PCH -include handling to make sure it matches the name as would be present
authorDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 23:58:53 +0000 (23:58 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 11 Nov 2009 23:58:53 +0000 (23:58 +0000)
in the predefines buffer.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86903 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/Utils.h
lib/Frontend/InitPreprocessor.cpp
lib/Frontend/PCHReader.cpp

index 60c0f226ef54f19e62476e11e396c79bcbbba098..4bda8bd71dc19ee6073c7cbc69aa9f10e6578b17 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef LLVM_CLANG_FRONTEND_UTILS_H
 #define LLVM_CLANG_FRONTEND_UTILS_H
 
+#include "llvm/ADT/StringRef.h"
 #include <vector>
 #include <string>
 
@@ -40,6 +41,10 @@ class SourceManager;
 class Stmt;
 class TargetInfo;
 
+/// Normalize \arg File for use in a user defined #include directive (in the
+/// predefines buffer).
+std::string NormalizeDashIncludePath(llvm::StringRef File);
+
 /// Apply the header search options to get given HeaderSearch object.
 void ApplyHeaderSearchOptions(HeaderSearch &HS,
                               const HeaderSearchOptions &HSOpts,
index ad70727c05e6a6ec6a07524aa1e3d71390e436de..462e065e8c14154bc85116467ccf4c170d0c2ac2 100644 (file)
@@ -61,9 +61,7 @@ static void UndefineBuiltinMacro(std::vector<char> &Buf, const char *Macro) {
   Buf.push_back('\n');
 }
 
-/// Add the quoted name of an implicit include file.
-static void AddQuotedIncludePath(std::vector<char> &Buf,
-                                 const std::string &File) {
+std::string clang::NormalizeDashIncludePath(llvm::StringRef File) {
   // Implicit include paths should be resolved relative to the current
   // working directory first, and then use the regular header search
   // mechanism. The proper way to handle this is to have the
@@ -76,9 +74,16 @@ static void AddQuotedIncludePath(std::vector<char> &Buf,
   if (!Path.exists())
     Path = File;
 
+  return Lexer::Stringify(Path.str());
+}
+
+/// Add the quoted name of an implicit include file.
+static void AddQuotedIncludePath(std::vector<char> &Buf,
+                                 const std::string &File) {
+
   // Escape double quotes etc.
   Buf.push_back('"');
-  std::string EscapedFile = Lexer::Stringify(Path.str());
+  std::string EscapedFile = NormalizeDashIncludePath(File);
   Buf.insert(Buf.end(), EscapedFile.begin(), EscapedFile.end());
   Buf.push_back('"');
 }
index 936382482c9a629802c3259355830d90c83bb0cf..780890de2abf46f7af793e7f83daaab24112554f 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "clang/Frontend/PCHReader.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Frontend/Utils.h"
 #include "../Sema/Sema.h" // FIXME: move Sema headers elsewhere
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
@@ -158,12 +159,13 @@ bool PCHValidator::ReadPredefinesBuffer(llvm::StringRef PCHPredef,
                                         FileID PCHBufferID,
                                         llvm::StringRef OriginalFileName,
                                         std::string &SuggestedPredefines) {
-  // We are in the context of an implicit include, so the predefines buffer
-  // will have a #include entry for the PCH file itself. Find it and skip over
-  // it in the checking below.
+  // We are in the context of an implicit include, so the predefines buffer will
+  // have a #include entry for the PCH file itself (as normalized by the
+  // preprocessor initialization). Find it and skip over it in the checking
+  // below.
   llvm::SmallString<256> PCHInclude;
   PCHInclude += "#include \"";
-  PCHInclude += OriginalFileName;
+  PCHInclude += NormalizeDashIncludePath(OriginalFileName);
   PCHInclude += "\"\n";
   std::pair<llvm::StringRef,llvm::StringRef> Split =
     llvm::StringRef(PP.getPredefines()).split(PCHInclude.str());