]> granicus.if.org Git - clang/commitdiff
Modules: Add -Rmodule-import
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 6 Mar 2019 02:50:46 +0000 (02:50 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 6 Mar 2019 02:50:46 +0000 (02:50 +0000)
Add a remark for importing modules.  Depending on whether this is a
direct import (into the TU being built by this compiler instance) or
transitive import (into an already-imported module), the diagnostic has
two forms:

    importing module 'Foo' from 'path/to/Foo.pcm'
    importing module 'Foo' into 'Bar' from 'path/to/Foo.pcm'

Also drop a redundant FileCheck invocation in Rmodule-build.m that was
using -Reverything, since the notes from -Rmodule-import were confusing
it.

https://reviews.llvm.org/D58891

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

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSerializationKinds.td
lib/Serialization/ASTReader.cpp
test/Modules/Inputs/Rmodule-import/A.h [new file with mode: 0644]
test/Modules/Inputs/Rmodule-import/B.h [new file with mode: 0644]
test/Modules/Inputs/Rmodule-import/C.h [new file with mode: 0644]
test/Modules/Inputs/Rmodule-import/D.h [new file with mode: 0644]
test/Modules/Inputs/Rmodule-import/module.modulemap [new file with mode: 0644]
test/Modules/Rmodule-build.m
test/Modules/Rmodule-import.m [new file with mode: 0644]

index 5e839691e07aa3c573439040db8850c3706594c0..69cec197aaaba21d0e0ed596e9c4e700c56defab 100644 (file)
@@ -351,6 +351,7 @@ def MismatchedReturnTypes : DiagGroup<"mismatched-return-types">;
 def MismatchedTags : DiagGroup<"mismatched-tags">;
 def MissingFieldInitializers : DiagGroup<"missing-field-initializers">;
 def ModuleBuild : DiagGroup<"module-build">;
+def ModuleImport : DiagGroup<"module-import">;
 def ModuleConflict : DiagGroup<"module-conflict">;
 def ModuleFileExtension : DiagGroup<"module-file-extension">;
 def NewlineEOF : DiagGroup<"newline-eof">;
index 3c5a06acfd10a731e34e51c7273ba6c1b2028e5f..43ba19b5853e2643650f47fe41dab39eff71779e 100644 (file)
@@ -72,6 +72,10 @@ def note_module_file_imported_by : Note<
 def err_module_file_not_module : Error<
   "AST file '%0' was not built as a module">, DefaultFatal;
 
+def remark_module_import : Remark<
+  "importing module '%0'%select{| into '%3'}2 from '%1'">,
+  InGroup<ModuleImport>;
+
 def err_imported_module_not_found : Error<
     "module '%0' in AST file '%1' (imported by AST file '%2') "
     "is not defined in any loaded module map file; "
index 5ad21604f4e7e341f2cbc6e00f515ba50bd07f21..39df352cb77df60e831c467b2d4cb8622a75668d 100644 (file)
@@ -2610,6 +2610,9 @@ ASTReader::ReadControlBlock(ModuleFile &F,
 
     case MODULE_NAME:
       F.ModuleName = Blob;
+      Diag(diag::remark_module_import)
+          << F.ModuleName << F.FileName << (ImportedBy ? true : false)
+          << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef());
       if (Listener)
         Listener->ReadModuleName(F.ModuleName);
 
@@ -4141,6 +4144,9 @@ ASTReader::ReadASTCore(StringRef FileName,
 
   switch (AddResult) {
   case ModuleManager::AlreadyLoaded:
+    Diag(diag::remark_module_import)
+        << M->ModuleName << M->FileName << (ImportedBy ? true : false)
+        << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef());
     return Success;
 
   case ModuleManager::NewlyLoaded:
diff --git a/test/Modules/Inputs/Rmodule-import/A.h b/test/Modules/Inputs/Rmodule-import/A.h
new file mode 100644 (file)
index 0000000..2b9dab8
--- /dev/null
@@ -0,0 +1,2 @@
+// A
+#include "B.h"
diff --git a/test/Modules/Inputs/Rmodule-import/B.h b/test/Modules/Inputs/Rmodule-import/B.h
new file mode 100644 (file)
index 0000000..a2711d4
--- /dev/null
@@ -0,0 +1,2 @@
+// B
+#include "C.h"
diff --git a/test/Modules/Inputs/Rmodule-import/C.h b/test/Modules/Inputs/Rmodule-import/C.h
new file mode 100644 (file)
index 0000000..6f30d47
--- /dev/null
@@ -0,0 +1 @@
+// C
diff --git a/test/Modules/Inputs/Rmodule-import/D.h b/test/Modules/Inputs/Rmodule-import/D.h
new file mode 100644 (file)
index 0000000..61177ec
--- /dev/null
@@ -0,0 +1 @@
+// D
diff --git a/test/Modules/Inputs/Rmodule-import/module.modulemap b/test/Modules/Inputs/Rmodule-import/module.modulemap
new file mode 100644 (file)
index 0000000..cf7cf1f
--- /dev/null
@@ -0,0 +1,4 @@
+module A { header "A.h" }
+module B { header "B.h" }
+module C { header "C.h" }
+module D { header "D.h" }
index 5c27ec6dfd97e2a3e3f845566c4ad29b2547ab2b..e9e2ca964e8fd18a890c55aebde8953d80f2a287 100644 (file)
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fsyntax-only %s -I %t \
 // RUN:            -Rmodule-build 2>&1 | FileCheck %s
 
-// RUN: echo ' ' >> %t/C.h
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fsyntax-only %s -I %t \
-// RUN:            -Reverything 2>&1 | FileCheck %s
-
 // RUN: echo ' ' >> %t/B.h
 // RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -fsyntax-only %s -I %t \
 // RUN:            2>&1 | FileCheck -allow-empty -check-prefix=NO-REMARKS %s
diff --git a/test/Modules/Rmodule-import.m b/test/Modules/Rmodule-import.m
new file mode 100644 (file)
index 0000000..54e2d02
--- /dev/null
@@ -0,0 +1,46 @@
+// RUN: rm -rf %t1 %t2
+
+// Run with -verify, which onliy gets remarks from the main TU.
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t1 \
+// RUN:     -fdisable-module-hash -fsyntax-only -I%S/Inputs/Rmodule-import \
+// RUN:     -Rmodule-build -Rmodule-import -verify %s
+
+// Run again, using FileCheck to check remarks from the module builds.
+//
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t2 \
+// RUN:     -fdisable-module-hash -fsyntax-only -I%S/Inputs/Rmodule-import \
+// RUN:     -Rmodule-build -Rmodule-import %s 2>&1 |\
+// RUN: FileCheck %s -implicit-check-not "remark:"
+
+#include "A.h" // \
+   expected-remark-re{{building module 'A' as '{{.*}}/A.pcm'}} \
+   expected-remark{{finished building module 'A'}} \
+   expected-remark-re{{importing module 'A' from '{{.*}}/A.pcm'}} \
+   expected-remark-re{{importing module 'B' into 'A' from '{{.*}}/B.pcm'}} \
+   expected-remark-re{{importing module 'C' into 'B' from '{{.*}}/C.pcm'}}
+// CHECK: remark: building module 'A'
+// CHECK: remark: building module 'B'
+// CHECK: remark: building module 'C'
+// CHECK: remark: finished building module 'C'
+// CHECK: remark: importing module 'C' from '{{.*}}/C.pcm'
+// CHECK: remark: finished building module 'B'
+// CHECK: remark: importing module 'B' from '{{.*}}/B.pcm'
+// CHECK: remark: importing module 'C' into 'B' from '{{.*}}/C.pcm'
+// CHECK: remark: finished building module 'A'
+// CHECK: remark: importing module 'A' from '{{.*}}/A.pcm'
+// CHECK: remark: importing module 'B' into 'A' from '{{.*}}/B.pcm'
+// CHECK: remark: importing module 'C' into 'B' from '{{.*}}/C.pcm'
+#include "B.h" // \
+   expected-remark-re{{importing module 'B' from '{{.*}}/B.pcm'}}
+// CHECK: remark: importing module 'B' from '{{.*}}/B.pcm'
+#include "C.h" // \
+   expected-remark-re{{importing module 'C' from '{{.*}}/C.pcm'}}
+// CHECK: remark: importing module 'C' from '{{.*}}/C.pcm'
+@import D; // \
+   expected-remark-re{{building module 'D' as '{{.*}}/D.pcm'}} \
+   expected-remark{{finished building module 'D'}} \
+   expected-remark-re{{importing module 'D' from '{{.*}}/D.pcm'}}
+// CHECK: remark: building module 'D'
+// CHECK: remark: finished building module 'D'
+// CHECK: remark: importing module 'D' from '{{.*}}/D.pcm'