r263449 - [modules] Don't diagnose non-modular includes from modular files that are

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 14 10:52:37 PDT 2016


Author: rsmith
Date: Mon Mar 14 12:52:37 2016
New Revision: 263449

URL: http://llvm.org/viewvc/llvm-project?rev=263449&view=rev
Log:
[modules] Don't diagnose non-modular includes from modular files that are
implementation units of modules rather than interface units.

Added:
    cfe/trunk/test/Modules/Inputs/non-module.h
    cfe/trunk/test/Modules/include-own-headers.m
Modified:
    cfe/trunk/include/clang/Lex/ModuleMap.h
    cfe/trunk/lib/Lex/ModuleMap.cpp
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=263449&r1=263448&r2=263449&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Mon Mar 14 12:52:37 2016
@@ -313,12 +313,18 @@ public:
   ///
   /// \param RequestingModule The module including a file.
   ///
+  /// \param RequestingModuleIsModuleInterface \c true if the inclusion is in
+  ///        the interface of RequestingModule, \c false if it's in the
+  ///        implementation of RequestingModule. Value is ignored and
+  ///        meaningless if RequestingModule is nullptr.
+  ///
   /// \param FilenameLoc The location of the inclusion's filename.
   ///
   /// \param Filename The included filename as written.
   ///
   /// \param File The included file.
   void diagnoseHeaderInclusion(Module *RequestingModule,
+                               bool RequestingModuleIsModuleInterface,
                                SourceLocation FilenameLoc, StringRef Filename,
                                const FileEntry *File);
 

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=263449&r1=263448&r2=263449&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Mon Mar 14 12:52:37 2016
@@ -239,6 +239,7 @@ static Module *getTopLevelOrNull(Module
 }
 
 void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
+                                        bool RequestingModuleIsModuleInterface,
                                         SourceLocation FilenameLoc,
                                         StringRef Filename,
                                         const FileEntry *File) {
@@ -301,7 +302,7 @@ void ModuleMap::diagnoseHeaderInclusion(
   if (LangOpts.ModulesStrictDeclUse) {
     Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module)
         << RequestingModule->getFullModuleName() << Filename;
-  } else if (RequestingModule) {
+  } else if (RequestingModule && RequestingModuleIsModuleInterface) {
     diag::kind DiagID = RequestingModule->getTopLevelModule()->IsFramework ?
         diag::warn_non_modular_include_in_framework_module :
         diag::warn_non_modular_include_in_module;

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=263449&r1=263448&r2=263449&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Mar 14 12:52:37 2016
@@ -609,6 +609,7 @@ const FileEntry *Preprocessor::LookupFil
     ModuleMap::KnownHeader *SuggestedModule,
     bool SkipCache) {
   Module *RequestingModule = getModuleForLocation(FilenameLoc); 
+  bool RequestingModuleIsModuleInterface = !SourceMgr.isInMainFile(FilenameLoc);
 
   // If the header lookup mechanism may be relative to the current inclusion
   // stack, record the parent #includes.
@@ -683,7 +684,8 @@ const FileEntry *Preprocessor::LookupFil
   if (FE) {
     if (SuggestedModule && !LangOpts.AsmPreprocessor)
       HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
-          RequestingModule, FilenameLoc, Filename, FE);
+          RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
+          Filename, FE);
     return FE;
   }
 
@@ -699,7 +701,8 @@ const FileEntry *Preprocessor::LookupFil
                                                     SuggestedModule))) {
         if (SuggestedModule && !LangOpts.AsmPreprocessor)
           HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
-              RequestingModule, FilenameLoc, Filename, FE);
+              RequestingModule, RequestingModuleIsModuleInterface, FilenameLoc,
+              Filename, FE);
         return FE;
       }
     }
@@ -714,7 +717,8 @@ const FileEntry *Preprocessor::LookupFil
                 RequestingModule, SuggestedModule))) {
           if (SuggestedModule && !LangOpts.AsmPreprocessor)
             HeaderInfo.getModuleMap().diagnoseHeaderInclusion(
-                RequestingModule, FilenameLoc, Filename, FE);
+                RequestingModule, RequestingModuleIsModuleInterface,
+                FilenameLoc, Filename, FE);
           return FE;
         }
       }

Added: cfe/trunk/test/Modules/Inputs/non-module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/non-module.h?rev=263449&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/non-module.h (added)
+++ cfe/trunk/test/Modules/Inputs/non-module.h Mon Mar 14 12:52:37 2016
@@ -0,0 +1,4 @@
+#ifndef NON_MODULE_H
+#define NON_MODULE_H
+
+#endif

Added: cfe/trunk/test/Modules/include-own-headers.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/include-own-headers.m?rev=263449&view=auto
==============================================================================
--- cfe/trunk/test/Modules/include-own-headers.m (added)
+++ cfe/trunk/test/Modules/include-own-headers.m Mon Mar 14 12:52:37 2016
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodule-name=Module -fimplicit-module-maps -fmodules-cache-path=%t -Werror=non-modular-include-in-framework-module -F%S/Inputs -I%S -fsyntax-only %s
+#include "Module/Module.h"
+#include "Inputs/non-module.h"




More information about the cfe-commits mailing list