r182263 - Add -Wincomplete-module, which detects when a header is included from a module but isn't itself part of a module.

Douglas Gregor dgregor at apple.com
Mon May 20 06:49:41 PDT 2013


Author: dgregor
Date: Mon May 20 08:49:41 2013
New Revision: 182263

URL: http://llvm.org/viewvc/llvm-project?rev=182263&view=rev
Log:
Add -Wincomplete-module, which detects when a header is included from a module but isn't itself part of a module.

Added:
    cfe/trunk/test/Modules/Inputs/incomplete_mod.h
    cfe/trunk/test/Modules/Inputs/incomplete_mod_missing.h
    cfe/trunk/test/Modules/incomplete-module.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
    cfe/trunk/lib/Lex/PPLexerChange.cpp
    cfe/trunk/test/Modules/Inputs/module.map

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=182263&r1=182262&r2=182263&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Mon May 20 08:49:41 2013
@@ -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">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=182263&r1=182262&r2=182263&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Mon May 20 08:49:41 2013
@@ -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">;
   

Modified: cfe/trunk/lib/Lex/PPLexerChange.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPLexerChange.cpp?rev=182263&r1=182262&r2=182263&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPLexerChange.cpp (original)
+++ cfe/trunk/lib/Lex/PPLexerChange.cpp Mon May 20 08:49:41 2013
@@ -401,8 +401,36 @@ bool Preprocessor::HandleEndOfFile(Token
         }
       }
     }
+
+    // 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;
 }
 

Added: cfe/trunk/test/Modules/Inputs/incomplete_mod.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/incomplete_mod.h?rev=182263&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/incomplete_mod.h (added)
+++ cfe/trunk/test/Modules/Inputs/incomplete_mod.h Mon May 20 08:49:41 2013
@@ -0,0 +1 @@
+#include "incomplete_mod_missing.h"

Added: cfe/trunk/test/Modules/Inputs/incomplete_mod_missing.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/incomplete_mod_missing.h?rev=182263&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/incomplete_mod_missing.h (added)
+++ cfe/trunk/test/Modules/Inputs/incomplete_mod_missing.h Mon May 20 08:49:41 2013
@@ -0,0 +1,2 @@
+extern int *missing;
+

Modified: cfe/trunk/test/Modules/Inputs/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=182263&r1=182262&r2=182263&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/module.map (original)
+++ cfe/trunk/test/Modules/Inputs/module.map Mon May 20 08:49:41 2013
@@ -209,3 +209,7 @@ module linkage_merge {
   }
 
 }
+
+module incomplete_mod {
+  header "incomplete_mod.h"
+}

Added: cfe/trunk/test/Modules/incomplete-module.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/incomplete-module.m?rev=182263&view=auto
==============================================================================
--- cfe/trunk/test/Modules/incomplete-module.m (added)
+++ cfe/trunk/test/Modules/incomplete-module.m Mon May 20 08:49:41 2013
@@ -0,0 +1,5 @@
+ at 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}}





More information about the cfe-commits mailing list