r205762 - If a header is explicitly included in module A, and excluded from an umbrella

Richard Smith richard-llvm at metafoo.co.uk
Tue Apr 8 06:13:04 PDT 2014


Author: rsmith
Date: Tue Apr  8 08:13:04 2014
New Revision: 205762

URL: http://llvm.org/viewvc/llvm-project?rev=205762&view=rev
Log:
If a header is explicitly included in module A, and excluded from an umbrella
directory in module B, don't include it in module B!

Added:
    cfe/trunk/test/Modules/Inputs/exclude-header/
    cfe/trunk/test/Modules/Inputs/exclude-header/module.map
    cfe/trunk/test/Modules/Inputs/exclude-header/x/
    cfe/trunk/test/Modules/Inputs/exclude-header/x/a.h
    cfe/trunk/test/Modules/Inputs/exclude-header/x/bad.h
    cfe/trunk/test/Modules/Inputs/exclude-header/y/
    cfe/trunk/test/Modules/Inputs/exclude-header/y/b.h
    cfe/trunk/test/Modules/exclude-header.c
Modified:
    cfe/trunk/include/clang/Lex/ModuleMap.h
    cfe/trunk/lib/Frontend/FrontendActions.cpp
    cfe/trunk/lib/Lex/ModuleMap.cpp

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=205762&r1=205761&r2=205762&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Tue Apr  8 08:13:04 2014
@@ -242,6 +242,11 @@ public:
   /// marked 'unavailable'.
   bool isHeaderInUnavailableModule(const FileEntry *Header) const;
 
+  /// \brief Determine whether the given header is unavailable as part
+  /// of the specified module.
+  bool isHeaderUnavailableInModule(const FileEntry *Header,
+                                   Module *RequestingModule) const;
+
   /// \brief Retrieve a module with the given name.
   ///
   /// \param Name The name of the module to look up.

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=205762&r1=205761&r2=205762&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Tue Apr  8 08:13:04 2014
@@ -213,7 +213,7 @@ collectModuleHeaderIncludes(const LangOp
       // If this header is marked 'unavailable' in this module, don't include 
       // it.
       if (const FileEntry *Header = FileMgr.getFile(Dir->path())) {
-        if (ModMap.isHeaderInUnavailableModule(Header))
+        if (ModMap.isHeaderUnavailableInModule(Header, Module))
           continue;
         Module->addTopHeader(Header);
       }

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=205762&r1=205761&r2=205762&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Tue Apr  8 08:13:04 2014
@@ -396,30 +396,41 @@ ModuleMap::findModuleForHeader(const Fil
 }
 
 bool ModuleMap::isHeaderInUnavailableModule(const FileEntry *Header) const {
+  return isHeaderUnavailableInModule(Header, 0);
+}
+
+bool ModuleMap::isHeaderUnavailableInModule(const FileEntry *Header,
+                                            Module *RequestingModule) const {
   HeadersMap::const_iterator Known = Headers.find(Header);
   if (Known != Headers.end()) {
     for (SmallVectorImpl<KnownHeader>::const_iterator
              I = Known->second.begin(),
              E = Known->second.end();
          I != E; ++I) {
-      if (I->isAvailable())
+      if (I->isAvailable() && (!RequestingModule ||
+                               I->getModule()->isSubModuleOf(RequestingModule)))
         return false;
     }
     return true;
   }
-  
+
   const DirectoryEntry *Dir = Header->getDir();
   SmallVector<const DirectoryEntry *, 2> SkippedDirs;
   StringRef DirName = Dir->getName();
 
+  auto IsUnavailable = [&](const Module *M) {
+    return !M->isAvailable() && (!RequestingModule ||
+                                 M->isSubModuleOf(RequestingModule));
+  };
+
   // Keep walking up the directory hierarchy, looking for a directory with
   // an umbrella header.
-  do {    
+  do {
     llvm::DenseMap<const DirectoryEntry *, Module *>::const_iterator KnownDir
       = UmbrellaDirs.find(Dir);
     if (KnownDir != UmbrellaDirs.end()) {
       Module *Found = KnownDir->second;
-      if (!Found->isAvailable())
+      if (IsUnavailable(Found))
         return true;
 
       // Search up the module stack until we find a module with an umbrella
@@ -438,7 +449,7 @@ bool ModuleMap::isHeaderInUnavailableMod
           Found = lookupModuleQualified(Name, Found);
           if (!Found)
             return false;
-          if (!Found->isAvailable())
+          if (IsUnavailable(Found))
             return true;
         }
         
@@ -452,7 +463,7 @@ bool ModuleMap::isHeaderInUnavailableMod
           return false;
       }
 
-      return !Found->isAvailable();
+      return IsUnavailable(Found);
     }
     
     SkippedDirs.push_back(Dir);

Added: cfe/trunk/test/Modules/Inputs/exclude-header/module.map
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/exclude-header/module.map?rev=205762&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/exclude-header/module.map (added)
+++ cfe/trunk/test/Modules/Inputs/exclude-header/module.map Tue Apr  8 08:13:04 2014
@@ -0,0 +1,3 @@
+module x { umbrella "x" exclude header "x/bad.h" exclude header "y/b.h" module * {} }
+module y { umbrella "y" module * {} }
+module bad { header "x/bad.h" }

Added: cfe/trunk/test/Modules/Inputs/exclude-header/x/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/exclude-header/x/a.h?rev=205762&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/exclude-header/x/a.h (added)
+++ cfe/trunk/test/Modules/Inputs/exclude-header/x/a.h Tue Apr  8 08:13:04 2014
@@ -0,0 +1 @@
+typedef int a;

Added: cfe/trunk/test/Modules/Inputs/exclude-header/x/bad.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/exclude-header/x/bad.h?rev=205762&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/exclude-header/x/bad.h (added)
+++ cfe/trunk/test/Modules/Inputs/exclude-header/x/bad.h Tue Apr  8 08:13:04 2014
@@ -0,0 +1 @@
+#error bad

Added: cfe/trunk/test/Modules/Inputs/exclude-header/y/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/exclude-header/y/b.h?rev=205762&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/exclude-header/y/b.h (added)
+++ cfe/trunk/test/Modules/Inputs/exclude-header/y/b.h Tue Apr  8 08:13:04 2014
@@ -0,0 +1 @@
+typedef int b;

Added: cfe/trunk/test/Modules/exclude-header.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/exclude-header.c?rev=205762&view=auto
==============================================================================
--- cfe/trunk/test/Modules/exclude-header.c (added)
+++ cfe/trunk/test/Modules/exclude-header.c Tue Apr  8 08:13:04 2014
@@ -0,0 +1,11 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x objective-c -fmodules -fmodules-cache-path=%t -I %S/Inputs/exclude-header %s -verify
+
+ at import x;
+
+a var_a;
+b var_b1; // expected-error {{unknown type name 'b'}}
+
+ at import y;
+
+b var_b2;





More information about the cfe-commits mailing list