[cfe-commits] r86903 - in /cfe/trunk: include/clang/Frontend/Utils.h lib/Frontend/InitPreprocessor.cpp lib/Frontend/PCHReader.cpp

Daniel Dunbar daniel at zuster.org
Wed Nov 11 15:58:53 PST 2009


Author: ddunbar
Date: Wed Nov 11 17:58:53 2009
New Revision: 86903

URL: http://llvm.org/viewvc/llvm-project?rev=86903&view=rev
Log:
Tweak PCH -include handling to make sure it matches the name as would be present
in the predefines buffer.

Modified:
    cfe/trunk/include/clang/Frontend/Utils.h
    cfe/trunk/lib/Frontend/InitPreprocessor.cpp
    cfe/trunk/lib/Frontend/PCHReader.cpp

Modified: cfe/trunk/include/clang/Frontend/Utils.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=86903&r1=86902&r2=86903&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/Utils.h (original)
+++ cfe/trunk/include/clang/Frontend/Utils.h Wed Nov 11 17:58:53 2009
@@ -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 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,

Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=86903&r1=86902&r2=86903&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
+++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Wed Nov 11 17:58:53 2009
@@ -61,9 +61,7 @@
   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 @@
   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('"');
 }

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=86903&r1=86902&r2=86903&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Wed Nov 11 17:58:53 2009
@@ -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 @@
                                         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());





More information about the cfe-commits mailing list