Issue 149821
Summary LLVM doesn't keep nullability information around when inlining
Labels new issue
Assignees
Reporter philnik777
    Consider
```
struct S {
  int* i;
};

[[gnu::returns_nonnull]] int* get(S& s) { return s.i; }

auto test1(S& s) {
  auto val = get(s);
  if (!val)
    __builtin_trap();
 return *val;
}

auto deref(int* val) {
  if (!val)
 __builtin_trap();
  return *val;
}

auto test2(S& s) {
  auto val = get(s);
  return deref(val);
}
```

`test1` gets optimized better than `test2`, even though the exact same information should be available to the compiler. It looks like LLVM doesn't keep the information that `s.i` can never be null when inlining `get`. This can be relevant for classes like `string`, where `data()` can never return a null pointer, but annotating the function doesn't help to remove redundant checks, since the annotation is lost as soon as the function is inlined.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to