r318503 - [PCH+Modules] Improve diagnosticts to help out users pass an extra header search path

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 16 19:24:11 PST 2017


Author: bruno
Date: Thu Nov 16 19:24:11 2017
New Revision: 318503

URL: http://llvm.org/viewvc/llvm-project?rev=318503&view=rev
Log:
[PCH+Modules] Improve diagnosticts to help out users pass an extra header search path

When mixing PCH and Implicit Modules, missing a header search path
can lead to the implicit built PCM to complaint about not finding its
matching module map.

Instead of adding more magic to implicit modules engine, add a note to
help the user add the appropriate path.

rdar://problem/33388847

Added:
    cfe/trunk/test/Modules/module-imported-by-pch-path.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td?rev=318503&r1=318502&r2=318503&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSerializationKinds.td Thu Nov 16 19:24:11 2017
@@ -77,6 +77,8 @@ def err_imported_module_not_found : Erro
     "module '%0' in AST file '%1' (imported by AST file '%2') "
     "is not defined in any loaded module map file; "
     "maybe you need to load '%3'?">, DefaultFatal;
+def note_imported_by_pch_module_not_found : Note<
+    "consider adding '%0' to the header search path">;
 def err_imported_module_modmap_changed : Error<
     "module '%0' imported by AST file '%1' found in a different module map file"
     " (%2) than when the importing AST file was built (%3)">, DefaultFatal;

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=318503&r1=318502&r2=318503&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Thu Nov 16 19:24:11 2017
@@ -3569,15 +3569,22 @@ ASTReader::ReadModuleMapFileBlock(Record
     if (!ModMap) {
       assert(ImportedBy && "top-level import should be verified");
       if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) {
-        if (auto *ASTFE = M ? M->getASTFile() : nullptr)
+        if (auto *ASTFE = M ? M->getASTFile() : nullptr) {
           // This module was defined by an imported (explicit) module.
           Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName
                                                << ASTFE->getName();
-        else
+        } else {
           // This module was built with a different module map.
           Diag(diag::err_imported_module_not_found)
               << F.ModuleName << F.FileName << ImportedBy->FileName
               << F.ModuleMapPath;
+          // In case it was imported by a PCH, there's a chance the user is
+          // just missing to include the search path to the directory containing
+          // the modulemap.
+          if (ImportedBy->Kind == MK_PCH)
+            Diag(diag::note_imported_by_pch_module_not_found)
+                << llvm::sys::path::parent_path(F.ModuleMapPath);
+        }
       }
       return OutOfDate;
     }

Added: cfe/trunk/test/Modules/module-imported-by-pch-path.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/module-imported-by-pch-path.m?rev=318503&view=auto
==============================================================================
--- cfe/trunk/test/Modules/module-imported-by-pch-path.m (added)
+++ cfe/trunk/test/Modules/module-imported-by-pch-path.m Thu Nov 16 19:24:11 2017
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t.dst %t.cache
+// RUN: mkdir -p %t.dst/folder-with-modulemap %t.dst/pch-folder
+// RUN: echo '#import "folder-with-modulemap/included.h"' > %t.dst/header.h
+// RUN: echo 'extern int MyModuleVersion;' > %t.dst/folder-with-modulemap/MyModule.h
+// RUN: echo '@import MyModule;' > %t.dst/folder-with-modulemap/included.h
+// RUN: echo 'module MyModule { header "MyModule.h" }' > %t.dst/folder-with-modulemap/module.modulemap
+
+// RUN: %clang -o %t.dst/pch-folder/header.pch -x objective-c-header -fmodules-cache-path=%t.cache -fmodules %t.dst/header.h
+// RUN: not %clang -fsyntax-only -fmodules-cache-path=%t.cache -fmodules %s -include-pch %t.dst/pch-folder/header.pch 2>&1 | FileCheck %s
+
+void test() {
+  (void)MyModuleVersion; // should be found by implicit import
+}
+
+// CHECK: module 'MyModule' in AST file '{{.*MyModule.*pcm}}' (imported by AST file '[[PCH:.*header.pch]]') is not defined in any loaded module map file; maybe you need to load '[[PATH:.*folder-with-modulemap]]/module.modulemap'
+// CHECK: consider adding '[[PATH]]' to the header search path
+// CHECK: imported by '[[PCH]]'




More information about the cfe-commits mailing list