1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

ConstantFold: Don't optimize comparisons with weak linkage objects

Consider:
void f() {}
void __attribute__((weak)) g() {}
bool b = &f != &g;

It's possble for g to resolve to f if --defsym=g=f is passed on to the
linker.

llvm-svn: 223585
This commit is contained in:
David Majnemer 2014-12-06 11:58:33 +00:00
parent dbb83f4a33
commit 0d1f96063b
2 changed files with 9 additions and 1 deletions

View File

@ -1348,9 +1348,12 @@ static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2) {
static ICmpInst::Predicate areGlobalsPotentiallyEqual(const GlobalValue *GV1,
const GlobalValue *GV2) {
auto isLinkageUnsafeForEquality = [](const GlobalValue *GV) {
return GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage();
};
// Don't try to decide equality of aliases.
if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2))
if (!GV1->hasExternalWeakLinkage() || !GV2->hasExternalWeakLinkage())
if (!isLinkageUnsafeForEquality(GV1) && !isLinkageUnsafeForEquality(GV2))
return ICmpInst::ICMP_NE;
return ICmpInst::BAD_ICMP_PREDICATE;
}

View File

@ -31,6 +31,11 @@ target datalayout = "p:32:32"
@weak.gep = global i32* getelementptr (i32* @weak, i32 1)
@weak = extern_weak global i32
; An object with weak linkage cannot have it's identity determined at compile time.
; CHECK: @F = global i1 icmp eq (i32* @weakany, i32* @glob)
@F = global i1 icmp eq (i32* @weakany, i32* @glob)
@weakany = weak global i32 0
; Don't add an inbounds on @glob.a3, since it's not inbounds.
; CHECK: @glob.a3 = alias getelementptr (i32* @glob.a2, i32 1)
@glob = global i32 0