]> granicus.if.org Git - clang/commitdiff
Improve the error message when a PCH dependency is modified
authorBen Langmuir <blangmuir@apple.com>
Fri, 17 Jan 2014 00:19:09 +0000 (00:19 +0000)
committerBen Langmuir <blangmuir@apple.com>
Fri, 17 Jan 2014 00:19:09 +0000 (00:19 +0000)
Show the top-level pch file as the culprit, rather than the immediate
dependency when a pch file imports a pcm from a module. To clarify the
relationship, the pch import stack is printed as notes. The old behaviour was
misleading when a pch imported a pcm (from a module), since removing the pcm
would not fix the problem, whereas rebuilding the pch would.

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

include/clang/Basic/DiagnosticSerializationKinds.td
lib/Serialization/ASTReader.cpp
test/PCH/modified-module-dependency.m [new file with mode: 0644]
test/PCH/modified-module-dependency.module.map [new file with mode: 0644]

index 81509cc18821680b8c929478a341c0f0bf693342..fe1de9db6f7a20eac0cbb8c9362be643dfadc4d4 100644 (file)
@@ -22,6 +22,8 @@ def err_fe_pch_file_modified : Error<
     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'">;
+def note_pch_rebuild_required : Note<"please rebuild precompiled header '%0'">;
 def note_module_cache_path : Note<
     "after modifying system headers, please delete the module cache at '%0'">;
 
index 26281cc747c42517659ff45fa2bcac8c8551dc89..76f62f5e71af78d0ae8b29e1b3668b1307d1bfbe 100644 (file)
@@ -1729,11 +1729,26 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
 #endif
          )) {
       if (Complain) {
-        Error(diag::err_fe_pch_file_modified, Filename, F.FileName);
-        if (Context.getLangOpts().Modules && !Diags.isDiagnosticInFlight()) {
-          Diag(diag::note_module_cache_path)
-            << PP.getHeaderSearchInfo().getModuleCachePath();
+        // Build a list of the PCH imports that got us here (in reverse).
+        SmallVector<ModuleFile *, 4> ImportStack(1, &F);
+        while (ImportStack.back()->ImportedBy.size() > 0)
+          ImportStack.push_back(ImportStack.back()->ImportedBy[0]);
+
+        // The top-level PCH is stale.
+        StringRef TopLevelPCHName(ImportStack.back()->FileName);
+        Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName);
+
+        // Print the import stack.
+        if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) {
+          Diag(diag::note_pch_required_by)
+            << Filename << ImportStack[0]->FileName;
+          for (unsigned I = 1; I < ImportStack.size(); ++I)
+            Diag(diag::note_pch_required_by)
+              << ImportStack[I-1]->FileName << ImportStack[I]->FileName;
         }
+
+        if (!Diags.isDiagnosticInFlight())
+          Diag(diag::note_pch_rebuild_required) << TopLevelPCHName;
       }
 
       IsOutOfDate = true;
diff --git a/test/PCH/modified-module-dependency.m b/test/PCH/modified-module-dependency.m
new file mode 100644 (file)
index 0000000..656fa34
--- /dev/null
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t-dir
+// RUN: mkdir -p %t-dir
+// RUN: echo '@import test;' > %t-dir/prefix.h
+// RUN: echo 'void foo(void);' > %t-dir/test.h
+// RUN: cp %S/modified-module-dependency.module.map %t-dir/module.map
+
+// Precompile prefix.pch.
+// RUN: %clang_cc1 -x objective-c -I %t-dir -fmodules -fmodules-cache-path=%t-dir/cache -emit-pch %t-dir/prefix.h -o %t-dir/prefix.pch
+
+// Modify the dependency.
+// RUN: echo ' ' >> %t-dir/test.h
+
+// Run and check the diagnostics.
+// RUN: not %clang_cc1 -x objective-c -include-pch %t-dir/prefix.pch -fmodules -fmodules-cache-path=%t-dir/cache -fsyntax-only %s 2> %t-dir/log
+// RUN: FileCheck %s < %t-dir/log
+
+// CHECK: file '{{.*}}/test.h' has been modified since the precompiled header '{{.*}}prefix.pch' was built
+// CHECK: '{{.*}}/test.h' required by '{{.*}}/test.pcm'
+// CHECK: '{{.*}}/test.pcm' required by '{{.*}}/prefix.pch'
+// CHECK: please rebuild precompiled header '{{.*}}/prefix.pch'
diff --git a/test/PCH/modified-module-dependency.module.map b/test/PCH/modified-module-dependency.module.map
new file mode 100644 (file)
index 0000000..b470677
--- /dev/null
@@ -0,0 +1,4 @@
+module test {
+  header "test.h"
+  export *
+}