llvm-project/llvm
Momchil Velikov acf3279a03 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
2021-04-09 14:09:23 +01:00
..
benchmarks
bindings [NFC][OCaml] Reformat to clean up following CAMLprim removal 2021-04-05 10:55:08 +01:00
cmake [CMake] try creating symlink first on windows 2021-04-07 11:23:10 +02:00
docs AMDGPU: Add gfx90c support to code object v2 for backwards compatibility 2021-04-08 16:42:43 -04:00
examples [Orc][examples] Add missing FileCheck for lit test and polish output 2021-04-07 11:12:20 +02:00
include [AA][NFC] Convert AliasResult to class containing offset for PartialAlias case. 2021-04-09 13:26:09 +03:00
lib For non-null pointer checks, do not descend through out-of-bounds GEPs 2021-04-09 14:09:23 +01:00
projects
resources
runtimes [runtimes] Add the libc project to the list of runtimes. 2021-03-23 17:33:03 +00:00
test For non-null pointer checks, do not descend through out-of-bounds GEPs 2021-04-09 14:09:23 +01:00
tools [dsymutil] Don't emit .debug_pubnames and .debug_pubtypes 2021-04-06 19:01:45 -07:00
unittests [AA][NFC] Convert AliasResult to class containing offset for PartialAlias case. 2021-04-09 13:26:09 +03:00
utils abtest.py: support bisection based on a response file 2021-04-08 09:46:01 -07:00
.clang-format
.clang-tidy
.gitattributes
.gitignore Remove .gitignore entries not relevant in the monorepo. 2021-04-07 12:25:02 -07:00
CMakeLists.txt [mlgo] fix build rules 2021-04-03 12:49:03 -07:00
CODE_OWNERS.TXT
CREDITS.TXT
LICENSE.TXT
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in

README.txt

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.