From 118076d1640c973a5794c2a4b484d2fccd349da2 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 10 Mar 2015 00:19:04 +0000 Subject: [PATCH] [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.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@231728 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Lex/ModuleMap.cpp | 35 +++++++++++---------------- test/Modules/public-private.modulemap | 7 +++++- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/lib/Lex/ModuleMap.cpp b/lib/Lex/ModuleMap.cpp index b4fe98488b..4fbed2cc06 100644 --- a/lib/Lex/ModuleMap.cpp +++ b/lib/Lex/ModuleMap.cpp @@ -219,28 +219,21 @@ static bool violatesPrivateInclude(Module *RequestingModule, 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*> 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 *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; diff --git a/test/Modules/public-private.modulemap b/test/Modules/public-private.modulemap index b07d161665..ef4ae9885f 100644 --- a/test/Modules/public-private.modulemap +++ b/test/Modules/public-private.modulemap @@ -1,5 +1,10 @@ // RUN: %clang_cc1 -fmodules -fmodule-map-file=%s -I%S -include "Inputs/empty.h" /dev/null -module Blah { +// RUN: %clang_cc1 -fmodules -fmodule-map-file=%s -I%S -include "Inputs/dummy.h" /dev/null +module A { header "Inputs/empty.h" private header "Inputs/empty.h" } +module B { + private header "Inputs/dummy.h" + header "Inputs/dummy.h" +} -- 2.40.0