Modules: Add -Rmodule-import

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

llvm-svn: 355477
This commit is contained in:
Duncan P. N. Exon Smith 2019-03-06 02:50:46 +00:00
parent 4cc9ff1245
commit 9dda8f540c
10 changed files with 67 additions and 4 deletions

View 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">;

View 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; "

View 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:

View File

@ -0,0 +1,2 @@
// A
#include "B.h"

View File

@ -0,0 +1,2 @@
// B
#include "C.h"

View File

@ -0,0 +1 @@
// C

View File

@ -0,0 +1 @@
// D

View File

@ -0,0 +1,4 @@
module A { header "A.h" }
module B { header "B.h" }
module C { header "C.h" }
module D { header "D.h" }

View File

@ -19,10 +19,6 @@
// 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

View File

@ -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'