[PATCH] D107822: [InstCombine] Fold Int2Ptr/PtrToInt if the ptr is dereferenceable

Nuno Lopes via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 19 02:11:30 PDT 2021


nlopes added a comment.

In D107822#2953955 <https://reviews.llvm.org/D107822#2953955>, @aqjune wrote:

> Hi,
>
> I became to wonder what happens if a pointer is freed in the function.
> For example:
>
>   // assume that %p is dereferenceable(8)
>   call void @g(%p);
>   %q = inttoptr (ptrtoint %p);
>   use(%q); // can we replace this with %p?
>
> I guess the answer is no, because if `@g` freed %p and allocated an object at `%p`'s location, replacing `inttoptr(ptrtoint %p)` with `%p` makes the program more undefined.
>
> Is the semantics of `dereferenceable(8) %p` implying `%p` must not be freed in the function as well?
> If it isn't I think we should check whether `nofree` flag is attached to the functions (`@test`, `@test1`, ...) as well.

I agree with you, but this is a bug in `isDereferenceableAndAlignedPointer`. This API should receive the instruction where we want to prove the ptr is dereferenceable and take care of free, etc.
So I would not block this patch on this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107822



More information about the llvm-commits mailing list