[modules] This check is run before we resolve the header, not after, so just
check that private headers are in a list matching the role. (We can't perform
the opposite checks for non-private headers because we infer those.)

llvm-svn: 231728
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index b4fe984..4fbed2c 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -219,28 +219,21 @@
                                    Module *RequestedModule) {
   bool IsPrivateRole = Role & ModuleMap::PrivateHeader;
 #ifndef NDEBUG
-  // 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.
-  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) {
+  if (IsPrivateRole) {
+    // 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 *Hs : HeaderList)
+      IsPrivate |=
+          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");
+          }) != Hs->end();
+    assert((!IsPrivateRole || IsPrivate) && "inconsistent headers and roles");
+  }
 #endif
   return IsPrivateRole &&
          RequestedModule->getTopLevelModule() != RequestingModule;