Issue 241913
Summary [LoopVectorize] assertion failure "Too many bits for uint64_t" in computeMinimumValueSizes with __builtin_add_overflow
Labels generated by fuzzer
Assignees
Reporter hazohelet
    Live Reproducer: https://godbolt.org/z/8vWbqz9vM

Compiling the following C code for `x86_64` with `clang -O2` crashes with assertion failure.

```c
int t(long a, int *p, int n, int k) {
  long r;
  int o = __builtin_add_overflow(a, 1, &r);
  for (int i = 0; i < n; i++)
    p[i] = k <= ((signed char)(r + p[i]) > 0);
  return o;
}
```

clang command:

```sh
clang -O2 -c repro.c
```

The compiler crashes with the following output:

```
clang: /home/runner/work/ccput/ccput/llvm/llvm/include/llvm/ADT/APInt.h:1563: uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64 && "Too many bits for uint64_t"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0.	Program arguments: clang -O2 -c repro.c
1.	<eof> parser at end of file
2.	Optimizer
3.	Running pass "function<eager-inv>(...)" on module "repro.c"
4.	Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "t"
...
#12 llvm::computeMinimumValueSizes(llvm::ArrayRef<llvm::BasicBlock*>, llvm::DemandedBits&, llvm::TargetTransformInfo const*)
#13 llvm::VFSelectionContext::computeMinimalBitwidths()
#14 llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int)
#15 llvm::LoopVectorizePass::processLoop(llvm::Loop*)
#16 llvm::LoopVectorizePass::runImpl(llvm::Function&)
#17 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)
```

Notes:

* Also crashes at -O3 and -Os, with `-fno-slp-vectorize`, and for aarch64
* Compiles at -O1 and -Oz, with `-fno-vectorize`, and with `int` in place of `long`

clang version:

```text
clang version 24.0.0git (https://github.com/llvm/llvm-project f5744e07d2dba7367ec68426fd6b6b07e2916b39)
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to