llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

opt miscompiles with "opt -O3 -flattencfg"

Open Vsevolod-Livinskij opened this issue 8 years ago • 2 comments

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

Vsevolod-Livinskij avatar Jun 02 '18 15:06 Vsevolod-Livinskij

Fix available in review: https://reviews.llvm.org/D78881

ekatz avatar Apr 26 '20 16:04 ekatz

assigned to @ekatz

Vsevolod-Livinskij avatar Jun 02 '18 15:06 Vsevolod-Livinskij