Open Quuxplusone opened 8 years ago
Attached bug.ll
(947 bytes, application/octet-stream): Bug test case
This appears to have been fixed in recent versions of Clang. If I use Clang 10.0.0, for instance, then the program always returns exit code 0 regardless of the optimization level:
$ clang --version
clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ clang -O0 -o bug bug.ll; ./bug; echo $?
0
$ clang -O1 -o bug bug.ll; ./bug; echo $?
0
$ clang -O2 -o bug bug.ll; ./bug; echo $?
0
$ clang -O3 -o bug bug.ll; ./bug; echo $?
0
I'm not sure if a test case needs to be added, however.
bug.ll
(947 bytes, application/octet-stream)Created attachment 16277 Bug test case
The attached LLVM assembly file demonstrates the bug. Certain code sequences involving unusual bitvector sizes (i65, in particular) seem to generate incorrect code.
In the attached file, the procedure @bug_proc performs some bit-manipulations on its argument, which is supposed to result in the temporary %t5 containing the original value zero extended to i65. This value is negated and returned. The procedure @correct_proc does a zero extend directly and then negates and returns. I claim both procedures should be semantically identical, which should result in the main function always returning a 0 exit code. However, this is not the case. For some arguments, and at some optimization levels, these procedures differ and the program returns exit code -1. As best I can tell, the attached program should not exhibit undefined behavior.
I get identical behavior from clang version 3.6.2 and clang 3.8.0 (installed via Homebrew).