summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorJohannes Doerfert <jdoerfert@anl.gov>2019-08-16 21:53:49 +0000
committerJohannes Doerfert <jdoerfert@anl.gov>2019-08-16 21:53:49 +0000
commit17cb91853638facffe4a26fbf632c845a9830359 (patch)
tree79884bd9cd73aac588687f516b026d02a930c9db /llvm/lib/Analysis
parentac67414618df9fdc24754b05cf438f8f7568f04a (diff)
downloadbcm5719-llvm-17cb91853638facffe4a26fbf632c845a9830359.tar.gz
bcm5719-llvm-17cb91853638facffe4a26fbf632c845a9830359.zip
[CaptureTracking] Allow null to be in either icmp operand
Summary: Before we required the comparison against null to be "canonical", hence null to be operand #1. This patch allows null to be in either operand, similar to the handling of loaded globals that follows. Reviewers: sanjoy, hfinkel, aykevl, sstefan1, uenoku Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66321 llvm-svn: 369158
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/CaptureTracking.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index f12e50e6c92..fe551bdfe18 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -331,7 +331,9 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
AddUses(I);
break;
case Instruction::ICmp: {
- if (auto *CPN = dyn_cast<ConstantPointerNull>(I->getOperand(1))) {
+ unsigned Idx = (I->getOperand(0) == V) ? 0 : 1;
+ unsigned OtherIdx = 1 - Idx;
+ if (auto *CPN = dyn_cast<ConstantPointerNull>(I->getOperand(OtherIdx))) {
// Don't count comparisons of a no-alias return value against null as
// captures. This allows us to ignore comparisons of malloc results
// with null, for example.
@@ -339,7 +341,7 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
if (isNoAliasCall(V->stripPointerCasts()))
break;
if (!I->getFunction()->nullPointerIsDefined()) {
- auto *O = I->getOperand(0)->stripPointerCastsSameRepresentation();
+ auto *O = I->getOperand(Idx)->stripPointerCastsSameRepresentation();
// An inbounds GEP can either be a valid pointer (pointing into
// or to the end of an allocation), or be null in the default
// address space. So for an inbounds GEPs there is no way to let
@@ -353,15 +355,15 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
// cannot lead to pointer escapes, because if it is not null it
// must be a valid (in-bounds) pointer.
bool CanBeNull;
- if (O->getPointerDereferenceableBytes(I->getModule()->getDataLayout(), CanBeNull))
+ if (O->getPointerDereferenceableBytes(I->getModule()->getDataLayout(),
+ CanBeNull))
break;
}
}
// Comparison against value stored in global variable. Given the pointer
// does not escape, its value cannot be guessed and stored separately in a
// global variable.
- unsigned OtherIndex = (I->getOperand(0) == V) ? 1 : 0;
- auto *LI = dyn_cast<LoadInst>(I->getOperand(OtherIndex));
+ auto *LI = dyn_cast<LoadInst>(I->getOperand(OtherIdx));
if (LI && isa<GlobalVariable>(LI->getPointerOperand()))
break;
// Otherwise, be conservative. There are crazy ways to capture pointers
OpenPOWER on IntegriCloud