[PATCH] D99642: For non-null pointer checks, do not descend through out-of-bounds GEPs

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 31 02:12:43 PDT 2021


fhahn added a comment.

In D99642#2660824 <https://reviews.llvm.org/D99642#2660824>, @lebedev.ri wrote:

> alive2 again doesn't agree that non-inbounds GEP is allowed to produce null pointer: https://alive2.llvm.org/ce/z/9wfL5x

Interesting, but also surprising, especially because the LangRef explicitly calls out GEPs without `inbounds` to wrap silently?



================
Comment at: llvm/lib/Analysis/ValueTracking.cpp:4275
     if (auto *GEP = dyn_cast<GEPOperator>(V)) {
+      if (InBounds && !GEP->isInBounds())
+        return V;
----------------
According to https://llvm.org/docs/LangRef.html#pointer-aliasing-rules, `inbounds` should not impact the underlying object property IIUC. But probably can only rely on that, if the pointer gets actually dereferenced? 


================
Comment at: llvm/test/Analysis/ValueTracking/unknown-nonnull-gep-out-of-bounds.ll:16
+  %0 = sub i64 0, %i
+  %q = getelementptr i8, i8* %p, i64 %0
+  %c = icmp eq i8* %q, null
----------------
do we need the sub & `ptrtoint` bits here? We also shouldn't the the transform if the index is an arbitrary value, e.g. an argument, right?


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

https://reviews.llvm.org/D99642



More information about the llvm-commits mailing list