[modules] If we have a choice between including a file textually and importing

a prebuilt form from a module, prefer the modular form, all else being equal.

llvm-svn: 229188
This commit is contained in:
Richard Smith 2015-02-13 23:50:20 +00:00
parent 9ea81b0041
commit ec87a50a3e
6 changed files with 36 additions and 2 deletions
clang
lib/Lex
test/Modules
Inputs/header-in-multiple-maps
header-in-multiple-maps.cpp

View File

@ -314,6 +314,22 @@ void ModuleMap::diagnoseHeaderInclusion(Module *RequestingModule,
}
}
static bool isBetterKnownHeader(const ModuleMap::KnownHeader &New,
const ModuleMap::KnownHeader &Old) {
// Prefer a public header over a private header.
if ((New.getRole() & ModuleMap::PrivateHeader) !=
(Old.getRole() & ModuleMap::PrivateHeader))
return !(New.getRole() & ModuleMap::PrivateHeader);
// Prefer a non-textual header over a textual header.
if ((New.getRole() & ModuleMap::TextualHeader) !=
(Old.getRole() & ModuleMap::TextualHeader))
return !(New.getRole() & ModuleMap::TextualHeader);
// Don't have a reason to choose between these. Just keep the first one.
return false;
}
ModuleMap::KnownHeader
ModuleMap::findModuleForHeader(const FileEntry *File,
Module *RequestingModule,
@ -348,8 +364,7 @@ ModuleMap::findModuleForHeader(const FileEntry *File,
!directlyUses(RequestingModule, I->getModule()))
continue;
// Prefer a public header over a private header.
if (!Result || (Result.getRole() & ModuleMap::PrivateHeader))
if (!Result || isBetterKnownHeader(*I, Result))
Result = *I;
}
return MakeResult(Result);

View File

@ -0,0 +1 @@
struct A {};

View File

@ -0,0 +1,3 @@
module a { header "a.h" }
module b { header "a.h" }
module c { textual header "a.h" }

View File

@ -0,0 +1,3 @@
module a { textual header "a.h" }
module b { header "a.h" }
module c { header "a.h" }

View File

@ -0,0 +1,3 @@
module a { header "a.h" }
module b { textual header "a.h" }
module c { header "a.h" }

View File

@ -0,0 +1,9 @@
// RUN: rm -rf %t
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/header-in-multiple-maps -fmodule-map-file=%S/Inputs/header-in-multiple-maps/map1 -verify %s
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/header-in-multiple-maps -fmodule-map-file=%S/Inputs/header-in-multiple-maps/map2 -verify %s
// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/header-in-multiple-maps -fmodule-map-file=%S/Inputs/header-in-multiple-maps/map3 -verify %s
// expected-no-diagnostics
#include "a.h"
#include "a.h"
A *p;