diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-12-06 11:58:33 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-12-06 11:58:33 +0000 |
commit | 64ba326b1e79007c0f06b093e3a643b64674aede (patch) | |
tree | 541813fbda49c7b65e4e00f09db3c0cf060d751c /llvm/lib | |
parent | ed00cd20ade2931c957ff20fb1072404aec709ed (diff) | |
download | bcm5719-llvm-64ba326b1e79007c0f06b093e3a643b64674aede.tar.gz bcm5719-llvm-64ba326b1e79007c0f06b093e3a643b64674aede.zip |
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
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index cdfb41f7dcc..719a3a4b4c8 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -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; } |