]> granicus.if.org Git - clang/commitdiff
Module: correctly set the module file kind when emitting file_modified.
authorManman Ren <manman.ren@gmail.com>
Fri, 21 Oct 2016 23:35:03 +0000 (23:35 +0000)
committerManman Ren <manman.ren@gmail.com>
Fri, 21 Oct 2016 23:35:03 +0000 (23:35 +0000)
rdar://28503343

Differential Revision: http://reviews.llvm.org/D25806

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

include/clang/Basic/DiagnosticSerializationKinds.td
lib/Serialization/ASTReader.cpp
test/Modules/module-file-modified.c [new file with mode: 0644]

index 16c77435558fd6947a40bd3d317754ba1380f38f..066a1f5fa68f2c056c3473382119322fc2eeb8fc 100644 (file)
@@ -21,6 +21,12 @@ def err_fe_pch_malformed_block : Error<
 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 8ce118ce7100fc0adbb033fd7e8ed0d28e3486cd..57de217078f6294eb10890b7479bcf64367be786 100644 (file)
@@ -1983,6 +1983,7 @@ ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) {
   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 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
 
       // 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()) {
diff --git a/test/Modules/module-file-modified.c b/test/Modules/module-file-modified.c
new file mode 100644 (file)
index 0000000..85018b5
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: echo 'int foo = 0;' > %t/a.h
+// RUN: echo 'module A { header "a.h" }' > %t/m.modulemap
+// RUN: %clang_cc1 -fmodules -emit-module -fmodule-name=A -x c %t/m.modulemap -o %t/m.pcm
+// RUN: echo 'int bar;' > %t/a.h
+// RUN: not %clang_cc1 -fmodules -fmodule-file=%t/m.pcm -fmodule-map-file=%t/m.modulemap -x c %s -I%t -fsyntax-only 2>&1 | FileCheck %s
+#include "a.h"
+int foo = 0; // redefinition of 'foo'
+// CHECK: fatal error: file {{.*}} has been modified since the module file {{.*}} was built
+// REQUIRES: shell