diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-12-08 19:35:31 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-12-08 19:35:31 +0000 |
commit | 770fd82f390b14f0f245b33d19167ec32727c5d2 (patch) | |
tree | a5e93698fa0480071bda6fea2c7ff7d089fb0209 /llvm/lib | |
parent | 970ac60573da3cce98934d73f65285bbcbfb5ba3 (diff) | |
download | bcm5719-llvm-770fd82f390b14f0f245b33d19167ec32727c5d2.tar.gz bcm5719-llvm-770fd82f390b14f0f245b33d19167ec32727c5d2.zip |
ConstantFold: Zero-sized globals might land on top of another global
A zero sized array is zero sized and might share its address with
another global.
llvm-svn: 223684
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 719a3a4b4c8..4cb22bc97a7 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1348,12 +1348,24 @@ 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(); + auto isGlobalUnsafeForEquality = [](const GlobalValue *GV) { + if (GV->hasExternalWeakLinkage() || GV->hasWeakAnyLinkage()) + return true; + if (const auto *GVar = dyn_cast<GlobalVariable>(GV)) { + Type *Ty = GVar->getType()->getPointerElementType(); + // A global with opaque type might end up being zero sized. + if (!Ty->isSized()) + return true; + // A global with an empty type might lie at the address of any other + // global. + if (Ty->isEmptyTy()) + return true; + } + return false; }; // Don't try to decide equality of aliases. if (!isa<GlobalAlias>(GV1) && !isa<GlobalAlias>(GV2)) - if (!isLinkageUnsafeForEquality(GV1) && !isLinkageUnsafeForEquality(GV2)) + if (!isGlobalUnsafeForEquality(GV1) && !isGlobalUnsafeForEquality(GV2)) return ICmpInst::ICMP_NE; return ICmpInst::BAD_ICMP_PREDICATE; } |