Open tesuji opened 3 years ago
Doesn't optimize to ret true
when compiling the C reproducer with clang either.
More: even if using iterators that can produce non increasing number of elements, rust (or llvm, don't know which part) can't prove bounds.
The upstream llvm bug seems to be fixed.
Current status: Waiting for llvm/llvm-project#90417
When trying to get rid of
unsafe
code in commit 57d25179e6751854c298313070adc4ac4454e230 in #81427. I found a case that GCC can prove that the slice index in bound but LLVM cannot.I tried this code (see generated assembly at godbolt https://godbolt.org/z/dTraGe):
I expected to see this happen: Compiler optimizes
eat_digits
to onlytrue
.Instead, this happened: LLVM cannot prove that, which leads to bounds check with
s[..i]
.Note that for the C version (more or less), gcc can optimize the code to
ret true
:Meta
rustc --version --verbose
:@rustbot label A-LLVM I-slow T-compiler