[Bug target/57344] New: wrong code with pragma pack(1) and -O1 on x86
dhazeghi at yahoo dot com
gcc-bugzilla@gcc.gnu.org
Mon May 20 21:38:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57344
Bug ID: 57344
Summary: wrong code with pragma pack(1) and -O1 on x86
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: dhazeghi at yahoo dot com
The following code produces wrong output on x86_64-linux-gnu in 32-bit mode,
when compiled at -O1 or higher optimizations. It appears that the behavior
changed between gcc 4.6 which works at all optimization levels, and 4.7 which
does not.
$ gcc-trunk -v
gcc version 4.9.0 20130520 (experimental) [trunk revision 199099] (GCC)
$ gcc-trunk -O0 -m32 wrong.c
$ ./a.out
-3161
$ gcc-trunk -O1 -m64 wrong.c
$ ./a.out
-3161
$ gcc-4.6 -O1 -m32 wrong.c
$ ./a.out
-3161
$ gcc-trunk -O1 -m32 wrong.c
$ ./a.out
2093991
$
--------------------------
int printf(const char *, ...);
#pragma pack(1)
struct S0
{
int f0:11;
int f1:22;
char f2;
int:0;
}
s[2];
int i;
int
main ()
{
struct S0 tmp = { 0, -3161L };
s[1] = tmp;
for (; i < 1; i++)
printf ("%d\n", s[1].f1);
return 0;
}
More information about the Gcc-bugs
mailing list