[llvm-bugs] [Bug 35507] New: [Clang-Optimization] wrong code for union assignment optimization
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Dec 2 07:37:43 PST 2017
https://bugs.llvm.org/show_bug.cgi?id=35507
Bug ID: 35507
Summary: [Clang-Optimization] wrong code for union assignment
optimization
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: yangyibiao at nju.edu.cn
CC: llvm-bugs at lists.llvm.org
$ clang -v
clang version 6.0.0-svn319460-1~exp1 (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.1
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
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.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.2.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
$ cat small.c
int printf(const char*, ...);
union {
int a;
} b;
int *c = (int*)&b;
int main() {
int *d = (int*)&b;
*d = 2;
*c = 1;
printf("%d\n", b.a);
}
$ clang -O0 small.c; ./a.out
1
$ clang -O1 small.c; ./a.out
2
$ clang -O2 small.c; ./a.out
2
$ clang -Ofast small.c; ./a.out
2
The output is different while the optimization is enabled.
--
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/20171202/0dd6d73c/attachment.html>
More information about the llvm-bugs
mailing list