[PATCH] D60047: [CaptureTracking] Pointer comparisons cannot escape

Ayke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 3 16:28:44 PDT 2019


aykevl added a comment.

Oh, I see. Thank you for explaining the actual behavior of getelementptr.

So I'm thinking about how to implement this feature. Would it be possible to infer the `nocapture` flag for the ptr argument in the following function, if it is also marked with `dereferenceable_or_null(4)`?

  int deref(int *ptr) {
      if (ptr == NULL) {
          abort(); // does not return
      }
      return *ptr;
  }

My understanding is that `dereferenceable_or_null(N)` implies that it is either a valid pointer (no out-of-bounds GEP allowed) or null, meaning that icmp cannot be used to let the pointer escape with a comparison against null.
In other words, it seems to me that if a pointer comes from a `dereferenceable_or_null(N)` argument (possibly through bitcast, inbounds GEP, addrspacecast, or other 'inbounds' operations) an icmp against null cannot let this pointer escape.

My goal is to make CaptureTracking (used in the functionattrs pass) powerful enough to be usable for escape analysis. The source language is Go, which has pointer semantics similar to Java.


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