[PATCH] D60047: [CaptureTracking] Don't let comparisons against null escape inbounds pointers

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat May 18 09:09:06 PDT 2019


aykevl added a comment.

I've updated the code, but there are a few things I'm not so sure about:

- It seems to me that comparisons against null might escape a pointer if the function is marked `"null-pointer-is-valid"`? But at the same time, that seems to be equivalent to comparing against a raw pointer (for example, `ptr == (uint32*)0x1000`) in a function that is not marked `"null-pointer-is-valid"` so I don't think it's a special case: if the comparison returns true you already had the pointer (in the form of a constant) so no pointer really escapes here.
- Can pointers in non-0 namespaces be considered noescape with this change? It might be better to be conservative and just don't apply this optimization to non-0 AS pointers. On the other hand, the same reasoning as in the previous point might apply here.

Also, there is the `stripPointerCasts` issue that has not yet been resolved, waiting for D61607 <https://reviews.llvm.org/D61607> to be merged.



================
Comment at: lib/Analysis/CaptureTracking.cpp:353
+        // (in-bounds) pointer.
+        if (Argument *A = dyn_cast<Argument>(O))
+          if (A->getDereferenceableOrNullBytes())
----------------
jdoerfert wrote:
> Why is this specific to arguments? We have other pointers that can be `dereferenceable_or_null`, see `Value::getPointerDereferenceableBytes`
Does `Value::getPointerDereferenceableBytes` have the same semantics (ignoring the CanBeNull) as `dereferenceable_or_null`? I see there are quite a few things that make a pointer dereferenceable, like `byval`. It seems to me that the same reasoning that holds true for `dereferenceable_or_null` also holds true for any dereferenceable (or null) pointer, but just want to make sure.

Also, where do I get a `DataLayout` from?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60047/new/

https://reviews.llvm.org/D60047





More information about the llvm-commits mailing list