]> granicus.if.org Git - clang/commitdiff
Add -Wincomplete-module, which detects when a header is included from a module but...
authorDouglas Gregor <dgregor@apple.com>
Mon, 20 May 2013 13:49:41 +0000 (13:49 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 20 May 2013 13:49:41 +0000 (13:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182263 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticLexKinds.td
lib/Lex/PPLexerChange.cpp
test/Modules/Inputs/incomplete_mod.h [new file with mode: 0644]
test/Modules/Inputs/incomplete_mod_missing.h [new file with mode: 0644]
test/Modules/Inputs/module.map
test/Modules/incomplete-module.m [new file with mode: 0644]

index 605e6cc7d97f249d24d318521a3b7835873d50d3..e56cfda056bf33c6e50ad96a14aaa9ccc67ebd70 100644 (file)
@@ -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">;
index 2c16000d339d7e8fe38e8eeed1c54e6f72059a82..6d4008c5e76e76e89e6903c280b4acc15fc84123 100644 (file)
@@ -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">;
   
index a22d67a6edff429f986e6f9a8188d6386b9cfe6e..deec5a8766c6d5110b87851eea624952f866abb8 100644 (file)
@@ -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/test/Modules/Inputs/incomplete_mod.h b/test/Modules/Inputs/incomplete_mod.h
new file mode 100644 (file)
index 0000000..f08be72
--- /dev/null
@@ -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 (file)
index 0000000..ffc85d5
--- /dev/null
@@ -0,0 +1,2 @@
+extern int *missing;
+
index d20521f9c7649e2398ef641ec63334de209d6967..249700a494ac0ce4667ee185f7d83a0a0bf9139a 100644 (file)
@@ -209,3 +209,7 @@ module linkage_merge {
   }
 
 }
+
+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 (file)
index 0000000..8edaea9
--- /dev/null
@@ -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}}