opt miscompiles with "opt -O3 -flattencfg"
| Bugzilla Link | 37662 |
| Resolution | FIXED |
| Resolved on | May 21, 2020 04:22 |
| Version | trunk |
| OS | Linux |
| Attachments | Reproducer. |
| CC | @dbabokin,@ekatz,@Vsevolod-Livinskij |
| Fixed by commit(s) | rG111ddc57d380 |
Extended Description
Opt produces incorrect code with opt -O3 -o func.ll func.bc -flattencfg opt-bisect-limit points to Simplify the CFG on function
Reproducer:
$ cat func.cpp extern unsigned short a, c; extern short *d; extern unsigned short *e; extern short b; void foo() { e = &a; c = 0; if (*d) e = &c; if (b) e = &c; }
$ cat driver.cpp #include <stdio.h>
short a = 6, b = 6; unsigned short c; unsigned short *d = &c; short *e;
void foo();
int main() { foo(); printf("%hd\n", *(e)); }
Error:
$ clang++ driver.cpp func.cpp $ ./a.out 0 $ clang++ -O3 -Xclang -disable-llvm-optzns -emit-llvm -c -o func.bc func.cpp $ opt -O3 -o func.ll func.bc -flattencfg $ clang++ -c -o func.o func.ll $ clang++ driver.cpp func.o $ ./a.out 6
LLVM version:
$ clang++ -v clang version 7.0.0 (trunk 333377) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /llvm/bin-trunk/bin Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7 Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.2 Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5 Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.8.5 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64
Fix available in review: https://reviews.llvm.org/D78881
assigned to @ekatz