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

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 6 21:26:00 PDT 2019


sanjoy added a comment.

In D60047#1491978 <https://reviews.llvm.org/D60047#1491978>, @jdoerfert wrote:

> I again think `dereferenceable_or_null` is fine because you basically have a single shot to guess the pointer by making it `null`:
>
> Any guess (with an offset) that keeps it in the `dereferenceable` part is useless as it cannot be `null`.


Agreed.

> Any guess that brings it outside the `dereferenceable` part which is not `null` will trigger undefined behavior (IMHO).

Agreed.

> Left is only the single guess that is just right which I would not count as escaping because the program could just as well
>  take the guessed value and pretend it is the pointer value without the check.

I don't think it could have done the same without the check.  One way to think about this is `foo` and `bar` are "colluding", `foo` knows that it will get a pointer that is at offset `4` from a valid pointer, so *if* it gets `null` then it knows that `-4` is a valid pointer.  This is just a more stylized way of doing:

  int* ptr = ...;
  int* ptr2 = (int*) 0x42000;
  if (ptr == ptr2) {  // Escapes ptr
    use ptr2;
  }


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