Add -Wincomplete-module, which detects when a header is included from a module but isn't itself part of a module.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182263 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td
index 605e6cc..e56cfda 100644
--- a/include/clang/Basic/DiagnosticGroups.td
+++ b/include/clang/Basic/DiagnosticGroups.td
@@ -149,6 +149,7 @@
: 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/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td
index 2c16000..6d4008c 100644
--- a/include/clang/Basic/DiagnosticLexKinds.td
+++ b/include/clang/Basic/DiagnosticLexKinds.td
@@ -579,7 +579,10 @@
"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/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp
index a22d67a..deec5a8 100644
--- a/lib/Lex/PPLexerChange.cpp
+++ b/lib/Lex/PPLexerChange.cpp
@@ -401,8 +401,36 @@
}
}
}
+
+ // 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/test/Modules/Inputs/incomplete_mod.h b/test/Modules/Inputs/incomplete_mod.h
new file mode 100644
index 0000000..f08be72
--- /dev/null
+++ b/test/Modules/Inputs/incomplete_mod.h
@@ -0,0 +1 @@
+#include "incomplete_mod_missing.h"
diff --git a/test/Modules/Inputs/incomplete_mod_missing.h b/test/Modules/Inputs/incomplete_mod_missing.h
new file mode 100644
index 0000000..ffc85d5
--- /dev/null
+++ b/test/Modules/Inputs/incomplete_mod_missing.h
@@ -0,0 +1,2 @@
+extern int *missing;
+
diff --git a/test/Modules/Inputs/module.map b/test/Modules/Inputs/module.map
index d20521f..249700a 100644
--- a/test/Modules/Inputs/module.map
+++ b/test/Modules/Inputs/module.map
@@ -209,3 +209,7 @@
}
}
+
+module incomplete_mod {
+ header "incomplete_mod.h"
+}
diff --git a/test/Modules/incomplete-module.m b/test/Modules/incomplete-module.m
new file mode 100644
index 0000000..8edaea9
--- /dev/null
+++ b/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}}