[all-commits] [llvm/llvm-project] acf327: For non-null pointer checks, do not descend throug...

Momchil Velikov via All-commits all-commits at lists.llvm.org
Fri Apr 9 06:09:52 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: acf3279a037ff9c8591f551e92b8e7a8c27b61a4
      https://github.com/llvm/llvm-project/commit/acf3279a037ff9c8591f551e92b8e7a8c27b61a4
  Author: Momchil Velikov <momchil.velikov at arm.com>
  Date:   2021-04-09 (Fri, 09 Apr 2021)

  Changed paths:
    M llvm/lib/Analysis/LazyValueInfo.cpp
    A llvm/test/Transforms/JumpThreading/nonnull-gep-out-of-bounds.ll

  Log Message:
  -----------
  For non-null pointer checks, do not descend through out-of-bounds GEPs

In LazyValueInfoImpl::isNonNullAtEndOfBlock we populate a set of
pointers, known to be non-null at the end of a block (e.g. because we
did a load through them). We then infer that any pointer, based on an
element of this set is non-null as well ("based" here meaning a
non-null pointer is the underlying object). This is incorrect, even if
the base pointer was non-null, the value of a GEP, that lacks the
inbounds` attribute, may be null.

This issue appeared as miscompilation of the following test case:

int puts(const char *);

typedef struct iter {
  int *val;
} iter_t;

static long distance(iter_t first, iter_t last) {
  long r = 0;
  for (; first.val != last.val; first.val++)
    ++r;
  return r;
}

int main() {
  int arr[2] = {0};
  iter_t i, j;
  i.val = arr;
  j.val = arr + 1;
  if (distance(i, j) >= 2)
    puts("failed");
  else
    puts("passed");
}

This fixes PR49662.

Differential Revision: https://reviews.llvm.org/D99642




More information about the All-commits mailing list