| Issue |
176729
|
| Summary |
[Miscompile] Incorrect overflow check removal at `-O3 -fno-inline`
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zunnurawan
|
**LLVM versions:** LLVM-21.1.8-Linux-X64 (latest release), LLVM-22.1.0-rc1-Linux-X64 (latest pre-release)
**Target:** x86_64-unknown-linux-gnu
## Summary
Overflow check in v9.9 (latest) `coreutils`'s `split` is incorrectly removed when compiling with `-O3 -fno-inline` as well as `O3 -finline-hint-functions`. The issue does not occur with `-O0` or `-O3` alone. Also, `-O3 -fno-inline` on GCC does not cause the same miscompilation.
## Steps to reproduce
```bash
git clone https://github.com/coreutils/coreutils
cd coreutils && git checkout 0ae5bdc7a8311efd3efe43363050710d6ea1c367 # this is the commit for release tag of v9.9 (latest)
mkdir build && cd build
# Miscompilation condition:
CC=clang-21 CFLAGS="-O3 -fno-inline" ../configure
make -j
./src/split --number=r/18446744073709551616 # this input causes overflow
# Result: Segmentation fault (core dumped)
# Correctly compiles:
CC=clang-21 CFLAGS="-O3" ../configure
make -j
./src/split --number=r/18446744073709551616 # this input causes overflow
# Result: split: memory exhausted
```
I've tried to reduce the source files to their minimal reproducible form but unfortunately I've not been successful. Reproduction will therefore require cloning and building the entire `coreutils` project.
## Notes
Preventing inlining (e.g. `-fno-inline`, `-finline-hint-functions`) at high optimization levels where inlining is enabled by default (`-O1`, `-O2`, `-O3`) drops an overflow check in the `split` binary in `coreutils`, causing a segfault when the overflow happens. This overflow check is part of the `coreutils` test suite.
The miscompilation is replicated using the latest release (v21.1.8) and pre-release (v22.1.0-rc) versions of LLVM on x86-64/linux.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs