aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/CaptureTracking.cpp
diff options
context:
space:
mode:
authorJohannes Doerfert <jdoerfert@anl.gov>2019-08-19 21:56:38 +0000
committerJohannes Doerfert <jdoerfert@anl.gov>2019-08-19 21:56:38 +0000
commit8b962f2814999e1cf48e964096fb9b657ba5b6eb (patch)
treef6f20ccaf62ced024c81205e9c72178d054f44c0 /llvm/lib/Analysis/CaptureTracking.cpp
parent8b0d15e43f339371204961566aa7ba5f64c209c5 (diff)
downloadllvm-8b962f2814999e1cf48e964096fb9b657ba5b6eb.zip
llvm-8b962f2814999e1cf48e964096fb9b657ba5b6eb.tar.gz
llvm-8b962f2814999e1cf48e964096fb9b657ba5b6eb.tar.bz2
[CaptureTracker] Let subclasses provide dereferenceability information
Summary: CaptureTracker subclasses might have better dereferenceability information which allows null pointer checks to be no-capturing. The first user will be D59922. Reviewers: sanjoy, hfinkel, aykevl, sstefan1, uenoku, xbolva00 Subscribers: hiraditya, bollu, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66371 llvm-svn: 369305
Diffstat (limited to 'llvm/lib/Analysis/CaptureTracking.cpp')
-rw-r--r--llvm/lib/Analysis/CaptureTracking.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index fe551bd..20e2f06 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -33,6 +33,22 @@ CaptureTracker::~CaptureTracker() {}
bool CaptureTracker::shouldExplore(const Use *U) { return true; }
+bool CaptureTracker::isDereferenceableOrNull(Value *O, const DataLayout &DL) {
+ // 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 GEP there is no way to let
+ // the pointer escape using clever GEP hacking because doing so
+ // would make the pointer point outside of the allocated object
+ // and thus make the GEP result a poison value. Similarly, other
+ // dereferenceable pointers cannot be manipulated without producing
+ // poison.
+ if (auto *GEP = dyn_cast<GetElementPtrInst>(O))
+ if (GEP->isInBounds())
+ return true;
+ bool CanBeNull;
+ return O->getPointerDereferenceableBytes(DL, CanBeNull);
+}
+
namespace {
struct SimpleCaptureTracker : public CaptureTracker {
explicit SimpleCaptureTracker(bool ReturnCaptures)
@@ -342,21 +358,10 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
break;
if (!I->getFunction()->nullPointerIsDefined()) {
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
- // the pointer escape using clever GEP hacking because doing so
- // would make the pointer point outside of the allocated object
- // and thus make the GEP result a poison value.
- if (auto *GEP = dyn_cast<GetElementPtrInst>(O))
- if (GEP->isInBounds())
- break;
- // Comparing a dereferenceable_or_null argument against null
- // 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))
+ // Comparing a dereferenceable_or_null pointer against null cannot
+ // lead to pointer escapes, because if it is not null it must be a
+ // valid (in-bounds) pointer.
+ if (Tracker->isDereferenceableOrNull(O, I->getModule()->getDataLayout()))
break;
}
}