diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Basic/DiagnosticGroups.td | 1 | ||||
-rw-r--r-- | clang/include/clang/Basic/DiagnosticLexKinds.td | 5 | ||||
-rw-r--r-- | clang/lib/Lex/PPLexerChange.cpp | 30 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/incomplete_mod.h | 1 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/incomplete_mod_missing.h | 2 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/module.map | 4 | ||||
-rw-r--r-- | clang/test/Modules/incomplete-module.m | 5 |
7 files changed, 46 insertions, 2 deletions
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 605e6cc7d97..e56cfda056b 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -149,6 +149,7 @@ def IncompatiblePointerTypes : DiagGroup<"incompatible-pointer-types", [IncompatiblePointerTypesDiscardsQualifiers]>; def IncompleteUmbrella : DiagGroup<"incomplete-umbrella">; +def IncompleteModule : DiagGroup<"incomplete-module", [IncompleteUmbrella]>; def InvalidNoreturn : DiagGroup<"invalid-noreturn">; def InvalidSourceEncoding : DiagGroup<"invalid-source-encoding">; def KNRPromotedParameter : DiagGroup<"knr-promoted-parameter">; diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 2c16000d339..6d4008c5e76 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -579,7 +579,10 @@ def warn_auto_module_import : Warning< "import of module '%1'">, InGroup<AutoImport>, DefaultIgnore; def warn_uncovered_module_header : Warning< "umbrella header for module '%0' does not include header '%1'">, - InGroup<IncompleteUmbrella>; + InGroup<IncompleteUmbrella>, DefaultIgnore; +def warn_forgotten_module_header : Warning< + "header '%0' is included in module '%1' but not listed in module map">, + InGroup<IncompleteModule>, DefaultIgnore; def err_expected_id_building_module : Error< "expected a module name in '__building_module' expression">; diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index a22d67a6edf..deec5a8766c 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -401,8 +401,36 @@ bool Preprocessor::HandleEndOfFile(Token &Result, bool isEndOfMacro) { } } } + + // Check whether there are any headers that were included, but not + // mentioned at all in the module map. Such headers + SourceLocation StartLoc + = SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); + if (getDiagnostics().getDiagnosticLevel(diag::warn_forgotten_module_header, + StartLoc) + != DiagnosticsEngine::Ignored) { + ModuleMap &ModMap = getHeaderSearchInfo().getModuleMap(); + for (unsigned I = 0, N = SourceMgr.local_sloc_entry_size(); I != N; ++I) { + // We only care about file entries. + const SrcMgr::SLocEntry &Entry = SourceMgr.getLocalSLocEntry(I); + if (!Entry.isFile()) + continue; + + // Dig out the actual file. + const FileEntry *File = Entry.getFile().getContentCache()->OrigEntry; + if (!File) + continue; + + // If it's not part of a module and not unknown, complain. + if (!ModMap.findModuleForHeader(File) && + !ModMap.isHeaderInUnavailableModule(File)) { + Diag(StartLoc, diag::warn_forgotten_module_header) + << File->getName() << Mod->getFullModuleName(); + } + } + } } - + return true; } diff --git a/clang/test/Modules/Inputs/incomplete_mod.h b/clang/test/Modules/Inputs/incomplete_mod.h new file mode 100644 index 00000000000..f08be724413 --- /dev/null +++ b/clang/test/Modules/Inputs/incomplete_mod.h @@ -0,0 +1 @@ +#include "incomplete_mod_missing.h" diff --git a/clang/test/Modules/Inputs/incomplete_mod_missing.h b/clang/test/Modules/Inputs/incomplete_mod_missing.h new file mode 100644 index 00000000000..ffc85d5e730 --- /dev/null +++ b/clang/test/Modules/Inputs/incomplete_mod_missing.h @@ -0,0 +1,2 @@ +extern int *missing; + diff --git a/clang/test/Modules/Inputs/module.map b/clang/test/Modules/Inputs/module.map index d20521f9c76..249700a494a 100644 --- a/clang/test/Modules/Inputs/module.map +++ b/clang/test/Modules/Inputs/module.map @@ -209,3 +209,7 @@ module linkage_merge { } } + +module incomplete_mod { + header "incomplete_mod.h" +} diff --git a/clang/test/Modules/incomplete-module.m b/clang/test/Modules/incomplete-module.m new file mode 100644 index 00000000000..8edaea983cb --- /dev/null +++ b/clang/test/Modules/incomplete-module.m @@ -0,0 +1,5 @@ +@import incomplete_mod; + +// RUN: rm -rf %t +// RUN: %clang_cc1 -fmodules-cache-path=%t -Wincomplete-module -fmodules -I %S/Inputs %s 2>&1 | FileCheck %s +// CHECK: {{warning: header '.*incomplete_mod_missing.h' is included in module 'incomplete_mod' but not listed in module map}} |