[PATCH] D85332: [SCCP] Do not replace deref'able ptr with un-deref'able one.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 14:43:14 PDT 2020


efriedma added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/SCCP.cpp:1357
+          BasicAAResult::DecomposeGEPExpression(C, Dec, DL, nullptr, nullptr);
+          auto *BaseTy = Dec.Base->getType()->getPointerElementType();
+          if (BaseTy->isArrayTy() &&
----------------
fhahn wrote:
> efriedma wrote:
> > I'm not sure I completely follow what this code is doing, but using getPointerElementType() like this is probably wrong.
> My intention here is to catch the case where we create a pointer to the 'one-past-the-last-element', which clearly is not dereferenceable. 
> 
> As implemented above, it probably only works for GEPs with pointers to array types as bases. So this would need further refinement to make sure we actually use the right base when dealing with nested data types. Is that what you were referring to or is there something else I am missing? Do you know if there are any helpful utilities for doing such a thing?
The simplest correct check I can think of is that you could DecomposeGEPExpression both sides of the equality, and check if the "Base" is equal.  That should cover everything, barring any weirdness with noalias/argmemonly/etc.

The problem here isn't really restricted to one-past-the-end.  Consider, for example, if you call malloc, then free the memory, then call malloc again.  The two pointers can be equal, but don't point to the same object.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85332



More information about the llvm-commits mailing list