This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/56577] New: wrong code for aliased union on gcc 4.7 only
- From: "dhazeghi at yahoo dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 09 Mar 2013 02:02:32 +0000
- Subject: [Bug tree-optimization/56577] New: wrong code for aliased union on gcc 4.7 only
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56577
Bug #: 56577
Summary: wrong code for aliased union on gcc 4.7 only
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: dhazeghi@yahoo.com
The following code behaves differently at -O3 than at -O2 or below on 4.7 on
x86_64-linux. At -O3 it returns 1, whereas at -O2 and below it
returns 0, for both -m32 and -m64 targets.
It behaves consistently on gcc 4.6 at all optimization levels (returns 0). It
may be related to 56576 (derived from a similar testcase) but that bug is also
present on mainline.
$ gcc-4.7 --version
gcc-4.7 (GCC) 4.7.2
$ gcc-4.7 -O2 orig-reduced.c
$ ./a.out
$ echo $?
0
$ gcc-4.7 -O3 orig-reduced.c
$ ./a.out
$ echo $?
1
$ gcc-4.6 -O3 orig-reduced.c
$ ./a.out
$ echo $?
0
$ cat orig-reduced.c
/* gcc-4.7 -O3 -m32/-m64 (works with trunk or at -O2) */
union
{
int f0;
int f1;
long f2;
}
b, *g, **i = &g;
int a, m;
int *c = (int *)&b.f2, *e, *f = &a;
int d;
int h;
long **j = (long **)&c;
int k;
int **l = &e;
void fn1 ()
{
d = 0;
for (; d <= 3; d++)
{
k = 0;
for (; k <= 3; k++)
{
int *n = &b.f1;
*i = 0;
**j = 1;
*n = 0;
*l = 0;
}
m = *f;
a = 1;
for (; a >= 0; a--)
h &= 1;
}
}
int main ()
{
fn1 ();
return b.f0;
}