[llvm-bugs] [Bug 35615] New: [Clang-optimization] wrong code for elements in a union pointed by two types of global pointers
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Dec 10 18:28:07 PST 2017
https://bugs.llvm.org/show_bug.cgi?id=35615
Bug ID: 35615
Summary: [Clang-optimization] wrong code for elements in a
union pointed by two types of global pointers
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-svn320001-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 a {
int b;
long c;
} e[] = {{0}, {8}};
int d = 0;
int *f = &e[1].b;
long *g = &e[1].c;
void h() {
for (; d < 2; d++) {
*g = 0;
if (*f)
return;
}
return;
}
int main() {
h();
printf("%d\n", d);
}
$ clang -O0 small.c; ./a.out
2
$ clang -Ofast small.c; ./a.out
0
$ clang -fsanitize=alignment small.c; ./a.out
2
I am not very sure whether there exist any undefined behavior in this code.
When I am using sanitize option, clang can not detect any undefined behavior in
this code.
--
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/20171211/52d703d2/attachment.html>
More information about the llvm-bugs
mailing list