r231725 - [modules] Don't assert if the same header is named as both a public and a

Richard Smith richard-llvm at metafoo.co.uk
Mon Mar 9 16:46:50 PDT 2015


Author: rsmith
Date: Mon Mar  9 18:46:50 2015
New Revision: 231725

URL: http://llvm.org/viewvc/llvm-project?rev=231725&view=rev
Log:
[modules] Don't assert if the same header is named as both a public and a
private header within the same module.

Added:
    cfe/trunk/test/Modules/Inputs/empty.h
    cfe/trunk/test/Modules/public-private.modulemap
Modified:
    cfe/trunk/lib/Lex/ModuleMap.cpp

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=231725&r1=231724&r2=231725&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Mon Mar  9 18:46:50 2015
@@ -222,15 +222,24 @@ static bool violatesPrivateInclude(Modul
   // Check for consistency between the module header role
   // as obtained from the lookup and as obtained from the module.
   // This check is not cheap, so enable it only for debugging.
-  bool IsPrivate = false;
-  SmallVectorImpl<Module::Header> *HeaderList[] =
-      {&RequestedModule->Headers[Module::HK_Private],
-       &RequestedModule->Headers[Module::HK_PrivateTextual]};
-  for (auto *Hdrs : HeaderList)
-    IsPrivate |=
-        std::find_if(Hdrs->begin(), Hdrs->end(), [&](const Module::Header &H) {
-          return H.Entry == IncFileEnt;
-        }) != Hdrs->end();
+  auto IsInHeaderList = [&](std::initializer_list<SmallVectorImpl<
+                                Module::Header>*> HeaderList) -> bool {
+    for (auto *Hs : HeaderList) {
+      if (std::find_if(Hs->begin(), Hs->end(), [&](const Module::Header &H) {
+            return H.Entry == IncFileEnt;
+          }) != Hs->end())
+        return true;
+    }
+    return false;
+  };
+  // If a header is both public and private, then it's available as a public
+  // header and that's OK.
+  // FIXME: Should we reject this when parsing the module map?
+  bool IsPrivate =
+      IsInHeaderList({&RequestedModule->Headers[Module::HK_Private],
+                      &RequestedModule->Headers[Module::HK_PrivateTextual]}) &&
+      !IsInHeaderList({&RequestedModule->Headers[Module::HK_Normal],
+                       &RequestedModule->Headers[Module::HK_Textual]});
   assert(IsPrivate == IsPrivateRole && "inconsistent headers and roles");
 #endif
   return IsPrivateRole &&

Added: cfe/trunk/test/Modules/Inputs/empty.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/empty.h?rev=231725&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Modules/public-private.modulemap
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/public-private.modulemap?rev=231725&view=auto
==============================================================================
--- cfe/trunk/test/Modules/public-private.modulemap (added)
+++ cfe/trunk/test/Modules/public-private.modulemap Mon Mar  9 18:46:50 2015
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%s -I%S -include "Inputs/empty.h" /dev/null
+module Blah {
+  header "Inputs/empty.h"
+  private header "Inputs/empty.h"
+}





More information about the cfe-commits mailing list