This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/47796] New: The code to write to a bit_field data strucuture will be removed unexpectedly with gcc 4.5.1 -O2 option
- From: "qihua.dai at intel dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 18 Feb 2011 03:41:03 +0000
- Subject: [Bug c/47796] New: The code to write to a bit_field data strucuture will be removed unexpectedly with gcc 4.5.1 -O2 option
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47796
Summary: The code to write to a bit_field data strucuture will
be removed unexpectedly with gcc 4.5.1 -O2 option
Product: gcc
Version: 4.5.1
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: qihua.dai@intel.com
Created attachment 23393
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23393
sample code for this problem
The code "tmp.a = 0xc;" and "tmp.d = 0x1;" is to write to a bit_field data
strucuture. They will be removed unexpectedly with gcc 4.5.1 -O2 option if
there is the same code in "if" condition before them, and using unsigned int
pointer to access the bit_field data strcuture after them. See below:
{
......
if(rev==0x0)
{
......
}
else
{
tmp.a = 0xc;
tmp.d = 0x1;
pData = (unsigned int *)pTmp;
data = *pData;
......
}
tmp.a = 0xc; // this code line is removed unexpected after -O2 optimization
tmp.d = 0x1; // this code line is removed unexpected after -O2 optimization
pData = (unsigned int *)pTmp;
data = *pData;
......
}
This issue only occurs when using -O2 gcc 4.5 option for bit_field c code.
On Fedora 11 (kernel 2.6.29.4-167). gcc 4.4.0 has no this problem.
On Fedora 14 (kernel 2.6.35.6-45). gcc 4.5.1 has no this problem.
Attached file includes the sample code tmp.c, and its assemle files built with
-O0 and -O2.
tmp_bit_field_O0.s is assemble file generated by -O0
tmp_bit_field_O2.s is assemble file generated by -O2
reproduce steps:
1, gcc -O0 tmp.c
2, ./a.out
3, the correct result below is printed:
data = 0x8000000c
rev_data = 0x11
4, gcc -O2 tmp.c
5, ./a.out
6, the incorrect result below is printed:
data = 0x0
rev_data = 0x11