forked from OSchip/llvm-project
[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:
parent
9ea81b0041
commit
ec87a50a3e
|
@ -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::KnownHeader
|
||||||
ModuleMap::findModuleForHeader(const FileEntry *File,
|
ModuleMap::findModuleForHeader(const FileEntry *File,
|
||||||
Module *RequestingModule,
|
Module *RequestingModule,
|
||||||
|
@ -348,8 +364,7 @@ ModuleMap::findModuleForHeader(const FileEntry *File,
|
||||||
!directlyUses(RequestingModule, I->getModule()))
|
!directlyUses(RequestingModule, I->getModule()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Prefer a public header over a private header.
|
if (!Result || isBetterKnownHeader(*I, Result))
|
||||||
if (!Result || (Result.getRole() & ModuleMap::PrivateHeader))
|
|
||||||
Result = *I;
|
Result = *I;
|
||||||
}
|
}
|
||||||
return MakeResult(Result);
|
return MakeResult(Result);
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
struct A {};
|
|
@ -0,0 +1,3 @@
|
||||||
|
module a { header "a.h" }
|
||||||
|
module b { header "a.h" }
|
||||||
|
module c { textual header "a.h" }
|
|
@ -0,0 +1,3 @@
|
||||||
|
module a { textual header "a.h" }
|
||||||
|
module b { header "a.h" }
|
||||||
|
module c { header "a.h" }
|
|
@ -0,0 +1,3 @@
|
||||||
|
module a { header "a.h" }
|
||||||
|
module b { textual header "a.h" }
|
||||||
|
module c { header "a.h" }
|
|
@ -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;
|
Loading…
Reference in New Issue