Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Incorrect code generated with unusual bitvector sizes #27545

Open Quuxplusone opened 8 years ago

Quuxplusone commented 8 years ago
Bugzilla Link PR27546
Status NEW
Importance P normal
Reported by Rob Dockins (nitpicker2000@gmail.com)
Reported on 2016-04-27 15:11:38 -0700
Last modified on 2021-07-21 07:30:47 -0700
Version 3.8
Hardware PC MacOS X
CC hfinkel@anl.gov, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, ryan.gl.scott@gmail.com
Fixed by commit(s)
Attachments bug.ll (947 bytes, application/octet-stream)
Blocks
Blocked by
See also

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.

$ clang --version
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin15.4.0
Thread model: posix
$ clang -O0 -o bug bug.ll; ./bug; echo $?
255
$ clang -O1 -o bug bug.ll; ./bug; echo $?
255
$ clang -O2 -o bug bug.ll; ./bug; echo $?
0
$ clang -O3 -o bug bug.ll; ./bug; echo $?
0
$ clang -Os -o bug bug.ll; ./bug; echo $?
0

I get identical behavior from clang version 3.6.2 and clang 3.8.0 (installed via Homebrew).

Quuxplusone commented 8 years ago

Attached bug.ll (947 bytes, application/octet-stream): Bug test case

Quuxplusone commented 3 years ago

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.