mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00: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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223585 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user