manmanren created this revision.
manmanren added reviewers: bruno, rsmith, benlangmuir.
manmanren added a subscriber: cfe-commits.

I don't quite like the if statement in the patch, but given that 
ASTReader::Error and DelayedDiagnostic only take strings, it is hard to just 
change err_fe_pch_file_modified to take a %select that depends on an integer.

On the other hard, it seems impossible to have another diagnostics in flight 
when emitting err_fe_pch_file_modified. Is it okay to just use Diag instead of 
Error?

Unfortunately I was not able to come up with a test that outputs this 
diagnostics for a module file.


https://reviews.llvm.org/D25806

Files:
  include/clang/Basic/DiagnosticSerializationKinds.td
  lib/Serialization/ASTReader.cpp


Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -1983,6 +1983,7 @@
   return R;
 }
 
+static unsigned moduleKindForDiagnostic(ModuleKind Kind);
 InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
   // If this ID is bogus, just return an empty input file.
   if (ID == 0 || ID > F.InputFilesLoaded.size())
@@ -2079,7 +2080,13 @@
 
       // The top-level PCH is stale.
       StringRef TopLevelPCHName(ImportStack.back()->FileName);
-      Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+      unsigned DiagnosticKind = 
moduleKindForDiagnostic(ImportStack.back()->Kind);
+      if (DiagnosticKind == 0)
+        Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+      else if (DiagnosticKind == 1)
+        Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
+      else
+        Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
 
       // Print the import stack.
       if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
Index: include/clang/Basic/DiagnosticSerializationKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSerializationKinds.td
+++ include/clang/Basic/DiagnosticSerializationKinds.td
@@ -21,6 +21,12 @@
 def err_fe_pch_file_modified : Error<
     "file '%0' has been modified since the precompiled header '%1' was built">,
     DefaultFatal;
+def err_fe_module_file_modified : Error<
+    "file '%0' has been modified since the module file '%1' was built">,
+    DefaultFatal;
+def err_fe_ast_file_modified : Error<
+    "file '%0' has been modified since the AST file '%1' was built">,
+    DefaultFatal;
 def err_fe_pch_file_overridden : Error<
     "file '%0' from the precompiled header has been overridden">;
 def note_pch_required_by : Note<"'%0' required by '%1'">;


Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -1983,6 +1983,7 @@
   return R;
 }
 
+static unsigned moduleKindForDiagnostic(ModuleKind Kind);
 InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
   // If this ID is bogus, just return an empty input file.
   if (ID == 0 || ID > F.InputFilesLoaded.size())
@@ -2079,7 +2080,13 @@
 
       // The top-level PCH is stale.
       StringRef TopLevelPCHName(ImportStack.back()->FileName);
-      Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+      unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind);
+      if (DiagnosticKind == 0)
+        Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+      else if (DiagnosticKind == 1)
+        Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName);
+      else
+        Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName);
 
       // Print the import stack.
       if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
Index: include/clang/Basic/DiagnosticSerializationKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSerializationKinds.td
+++ include/clang/Basic/DiagnosticSerializationKinds.td
@@ -21,6 +21,12 @@
 def err_fe_pch_file_modified : Error<
     "file '%0' has been modified since the precompiled header '%1' was built">,
     DefaultFatal;
+def err_fe_module_file_modified : Error<
+    "file '%0' has been modified since the module file '%1' was built">,
+    DefaultFatal;
+def err_fe_ast_file_modified : Error<
+    "file '%0' has been modified since the AST file '%1' was built">,
+    DefaultFatal;
 def err_fe_pch_file_overridden : Error<
     "file '%0' from the precompiled header has been overridden">;
 def note_pch_required_by : Note<"'%0' required by '%1'">;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to