r180635 - [PCH/modules] Require the preprocessing record option to match the used PCH, if modules are enabled.

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Apr 26 14:33:40 PDT 2013


Author: akirtzidis
Date: Fri Apr 26 16:33:40 2013
New Revision: 180635

URL: http://llvm.org/viewvc/llvm-project?rev=180635&view=rev
Log:
[PCH/modules] Require the preprocessing record option to match the used PCH, if modules are enabled.

The preprocessing record becomes important when modules are enabled, since it is used to calculate the
module cache hash.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp
    cfe/trunk/test/Index/targeted-annotation.c
    cfe/trunk/tools/c-index-test/c-index-test.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=180635&r1=180634&r2=180635&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Fri Apr 26 16:33:40 2013
@@ -58,6 +58,10 @@ def err_pch_undef : Error<
     "%select{command line contains|precompiled header was built with}0 "
     "'-undef' but %select{precompiled header was not built with it|"
     "it is not present on the command line}0">;
+def err_pch_pp_detailed_record : Error<
+    "%select{command line contains|precompiled header was built with}0 "
+    "'-detailed-preprocessing-record' but %select{precompiled header was not "
+    "built with it|it is not present on the command line}0">;
 
 def err_not_a_pch_file : Error<
     "'%0' does not appear to be a precompiled header file">, DefaultFatal;

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=180635&r1=180634&r2=180635&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Apr 26 16:33:40 2013
@@ -257,7 +257,8 @@ static bool checkPreprocessorOptions(con
                                      const PreprocessorOptions &ExistingPPOpts,
                                      DiagnosticsEngine *Diags,
                                      FileManager &FileMgr,
-                                     std::string &SuggestedPredefines) {
+                                     std::string &SuggestedPredefines,
+                                     const LangOptions &LangOpts) {
   // Check macro definitions.
   MacroDefinitionsMap ASTFileMacros;
   collectMacroDefinitions(PPOpts, ASTFileMacros);
@@ -323,6 +324,15 @@ static bool checkPreprocessorOptions(con
     return true;
   }
 
+  // Detailed record is important since it is used for the module cache hash.
+  if (LangOpts.Modules &&
+      PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord) {
+    if (Diags) {
+      Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord;
+    }
+    return true;
+  }
+
   // Compute the #include and #include_macros lines we need.
   for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) {
     StringRef File = ExistingPPOpts.Includes[I];
@@ -363,7 +373,8 @@ bool PCHValidator::ReadPreprocessorOptio
   return checkPreprocessorOptions(PPOpts, ExistingPPOpts,
                                   Complain? &Reader.Diags : 0,
                                   PP.getFileManager(),
-                                  SuggestedPredefines);
+                                  SuggestedPredefines,
+                                  PP.getLangOpts());
 }
 
 void PCHValidator::ReadHeaderFileInfo(const HeaderFileInfo &HFI,
@@ -3427,7 +3438,7 @@ namespace {
                                          bool Complain,
                                          std::string &SuggestedPredefines) {
       return checkPreprocessorOptions(ExistingPPOpts, PPOpts, 0, FileMgr,
-                                      SuggestedPredefines);
+                                      SuggestedPredefines, ExistingLangOpts);
     }
   };
 }
@@ -4004,6 +4015,7 @@ bool ASTReader::ParsePreprocessorOptions
   }
 
   PPOpts.UsePredefines = Record[Idx++];
+  PPOpts.DetailedRecord = Record[Idx++];
   PPOpts.ImplicitPCHInclude = ReadString(Record, Idx);
   PPOpts.ImplicitPTHInclude = ReadString(Record, Idx);
   PPOpts.ObjCXXARCStandardLibrary =

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=180635&r1=180634&r2=180635&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Apr 26 16:33:40 2013
@@ -1170,6 +1170,8 @@ void ASTWriter::WriteControlBlock(Prepro
     AddString(PPOpts.MacroIncludes[I], Record);
 
   Record.push_back(PPOpts.UsePredefines);
+  // Detailed record is important since it is used for the module cache hash.
+  Record.push_back(PPOpts.DetailedRecord);
   AddString(PPOpts.ImplicitPCHInclude, Record);
   AddString(PPOpts.ImplicitPTHInclude, Record);
   Record.push_back(static_cast<unsigned>(PPOpts.ObjCXXARCStandardLibrary));

Modified: cfe/trunk/test/Index/targeted-annotation.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/targeted-annotation.c?rev=180635&r1=180634&r2=180635&view=diff
==============================================================================
--- cfe/trunk/test/Index/targeted-annotation.c (original)
+++ cfe/trunk/test/Index/targeted-annotation.c Fri Apr 26 16:33:40 2013
@@ -82,10 +82,10 @@ int LocalVar2;
 // TOP: Identifier: "TARGETED_TOP_H" [2:9 - 2:23] preprocessing directive=
 // TOP: Punctuation: "#" [3:1 - 3:2] preprocessing directive=
 // TOP: Identifier: "define" [3:2 - 3:8] preprocessing directive=
-// TOP: Identifier: "TARGETED_TOP_H" [3:9 - 3:23] preprocessing directive=
-// TOP: Punctuation: "#" [5:1 - 5:2] preprocessing directive=
-// TOP: Identifier: "include" [5:2 - 5:9] preprocessing directive=
-// TOP: Literal: ""targeted-nested1.h"" [5:10 - 5:30] preprocessing directive=
+// TOP: Identifier: "TARGETED_TOP_H" [3:9 - 3:23] macro definition=TARGETED_TOP_H
+// TOP: Punctuation: "#" [5:1 - 5:2] inclusion directive=targeted-nested1.h
+// TOP: Identifier: "include" [5:2 - 5:9] inclusion directive=targeted-nested1.h
+// TOP: Literal: ""targeted-nested1.h"" [5:10 - 5:30] inclusion directive=targeted-nested1.h
 // TOP: Keyword: "enum" [7:1 - 7:5] EnumDecl=:7:1 (Definition)
 // TOP: Punctuation: "{" [7:6 - 7:7] EnumDecl=:7:1 (Definition)
 // TOP: Identifier: "VALUE" [8:3 - 8:8] EnumConstantDecl=VALUE:8:3 (Definition)

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=180635&r1=180634&r2=180635&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Fri Apr 26 16:33:40 2013
@@ -3508,6 +3508,7 @@ int write_pch_file(const char *filename,
                                   unsaved_files,
                                   num_unsaved_files,
                                   CXTranslationUnit_Incomplete |
+                                  CXTranslationUnit_DetailedPreprocessingRecord|
                                     CXTranslationUnit_ForSerialization);
   if (!TU) {
     fprintf(stderr, "Unable to load translation unit!\n");





More information about the cfe-commits mailing list