<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 19, 2016 at 5:05 PM, Manman Ren <span dir="ltr"><<a href="mailto:manman.ren@gmail.com" target="_blank">manman.ren@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">manmanren created this revision.<br>
manmanren added reviewers: bruno, rsmith, benlangmuir.<br>
manmanren added a subscriber: cfe-commits.<br>
<br>
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.<br>
<br>
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?<br></blockquote><div><br></div><div>No, this diagnostic can be produced lazily when first trying to emit a diagnostic that points into the modified file.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Unfortunately I was not able to come up with a test that outputs this diagnostics for a module file.<br></blockquote><div><br></div><div>Try something like this:</div><div><br></div><div><div>// RUN: rm -rf %t</div><div>// RUN: mkdir %t</div><div>// RUN: echo 'int foo = 0;' > %t/a</div><div>// RUN: echo 'module A { header "a" }' > %t/m</div><div>// RUN: %clang_cc1 -fmodules -emit-module -fmodule-name=A -x c %t/m -o %t/pcm</div><div>// RUN: echo 'int bar;' > %t/a</div><div>// RUN: %clang_cc1 -fmodules -fmodule-file=%t/pcm -fmodule-map-file=%t/m -x c %s -I%t</div><div>#include "a"</div><div>int foo = 0;</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<a href="https://reviews.llvm.org/D25806" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2580<wbr>6</a><br>
<br>
Files:<br>
  include/clang/Basic/Diagnostic<wbr>SerializationKinds.td<br>
  lib/Serialization/ASTReader.cp<wbr>p<br>
<br>
<br>
Index: lib/Serialization/ASTReader.cp<wbr>p<br>
==============================<wbr>==============================<wbr>=======<br>
--- lib/Serialization/ASTReader.cp<wbr>p<br>
+++ lib/Serialization/ASTReader.cp<wbr>p<br>
@@ -1983,6 +1983,7 @@<br>
   return R;<br>
 }<br>
<br>
+static unsigned moduleKindForDiagnostic(Module<wbr>Kind Kind);<br>
 InputFile ASTReader::getInputFile(Module<wbr>File &F, unsigned ID, bool Complain) {<br>
   // If this ID is bogus, just return an empty input file.<br>
   if (ID == 0 || ID > F.InputFilesLoaded.size())<br>
@@ -2079,7 +2080,13 @@<br>
<br>
       // The top-level PCH is stale.<br>
       StringRef TopLevelPCHName(ImportStack.ba<wbr>ck()->FileName);<br>
-      Error(diag::err_fe_pch_file_mo<wbr>dified, Filename, TopLevelPCHName);<br>
+      unsigned DiagnosticKind = moduleKindForDiagnostic(Import<wbr>Stack.back()->Kind);<br>
+      if (DiagnosticKind == 0)<br>
+        Error(diag::err_fe_pch_file_mo<wbr>dified, Filename, TopLevelPCHName);<br>
+      else if (DiagnosticKind == 1)<br>
+        Error(diag::err_fe_module_file<wbr>_modified, Filename, TopLevelPCHName);<br>
+      else<br>
+        Error(diag::err_fe_ast_file_mo<wbr>dified, Filename, TopLevelPCHName);<br>
<br>
       // Print the import stack.<br>
       if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {<br>
Index: include/clang/Basic/Diagnostic<wbr>SerializationKinds.td<br>
==============================<wbr>==============================<wbr>=======<br>
--- include/clang/Basic/Diagnostic<wbr>SerializationKinds.td<br>
+++ include/clang/Basic/Diagnostic<wbr>SerializationKinds.td<br>
@@ -21,6 +21,12 @@<br>
 def err_fe_pch_file_modified : Error<<br>
     "file '%0' has been modified since the precompiled header '%1' was built">,<br>
     DefaultFatal;<br>
+def err_fe_module_file_modified : Error<<br>
+    "file '%0' has been modified since the module file '%1' was built">,<br>
+    DefaultFatal;<br>
+def err_fe_ast_file_modified : Error<<br>
+    "file '%0' has been modified since the AST file '%1' was built">,<br>
+    DefaultFatal;<br>
 def err_fe_pch_file_overridden : Error<<br>
     "file '%0' from the precompiled header has been overridden">;<br>
 def note_pch_required_by : Note<"'%0' required by '%1'">;<br>
<br>
<br>
</blockquote></div><br></div></div>