[PATCH] D110245: [ConstantFolding] Fold ptrtoint(gep i8 null, x) -> x

Alexander Richardson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 23 02:40:17 PDT 2021


arichardson added inline comments.


================
Comment at: llvm/lib/Analysis/ConstantFolding.cpp:1371-1373
+          // for the invalid inbounds case. Using the integer value is safer
+          // than unconditionally returning zero for inbounds since e.g. Clang
+          // will emit an inbounds GEP on null for hand-written offsetof().
----------------
nikic wrote:
> lebedev.ri wrote:
> > I don't think matters what is "safer", that mentioned code is UB, and UBSan will catch it.
> I think this comment should just be dropped entirely. Any optimization that is valid without inbounds is valid with inbounds and does not require explicit justification.
Sounds good to me. I added this comment since I only recently looked into the detailed semantics of inbounds/non-inbounds GEPs. But for someone familiar with it that is indeed obvious.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110245



More information about the llvm-commits mailing list