This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/83357] New: [Gcc-optimization] wrong code for elements in a union pointed by two different types of global pointers
- From: "yangyibiao at nju dot edu.cn" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 11 Dec 2017 03:04:09 +0000
- Subject: [Bug tree-optimization/83357] New: [Gcc-optimization] wrong code for elements in a union pointed by two different types of global pointers
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83357
Bug ID: 83357
Summary: [Gcc-optimization] wrong code for elements in a union
pointed by two different types of global pointers
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: yangyibiao at nju dot edu.cn
Target Milestone: ---
$ 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);
}
$ gcc -O0 small.c; ./a.out
2
$ gcc -O3 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 in clang, clang can not detect any undefined
behavior in this code.