[llvm-bugs] [Bug 35240] New: Wrong constant folding
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Nov 8 00:18:39 PST 2017
https://bugs.llvm.org/show_bug.cgi?id=35240
Bug ID: 35240
Summary: Wrong constant folding
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: ishiura-compiler at ml.kwansei.ac.jp
CC: llvm-bugs at lists.llvm.org
LLVM + clang 6.0 for x86_64 miscompiles the following code.
% cat test.c
volatile int buff = 0;
void PRINTF(const int* s)
{
while(*s++) buff = *s;
}
char a = 0;
char b = 0;
short c = 0;
int d = 0;
int e = 0;
int main (void)
{
volatile short f = 1;
volatile int g = 1;
int h = ( 1 << c ) & 3;
a = 0 == g;
int i = 1 == g;
volatile int j = ((long)3>>g)%3;
volatile int k = (1*i)>>c;
c = a|f;
e = 3<<a;
b = d*i;
int l = (3>>a)/3;
if (h != 1) { PRINTF((const int*)&h); }
if (c != 1) __builtin_abort();
if (l != 1) __builtin_abort();
return 0;
}
% clang-6.0 -O1 test.c
% ./a.out
zsh: abort (core dumped) ./a.out
% clang-6.0 -O2 test.c
% ./a.out
zsh: abort (core dumped) ./a.out
% clang-6.0 -O3 test.c
% ./a.out
zsh: abort (core dumped) ./a.out
% clang-6.0 -Os test.c
% ./a.out
zsh: abort (core dumped) ./a.out
% clang-6.0 -v
clang version 6.0.0 (trunk 317078)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171108/9e83a0ef/attachment-0001.html>
More information about the llvm-bugs
mailing list