The following testcase has a different result with 4.6 and -O1/2/3
gcc4.5: all optimizations:
r1: 15 r2: 2
gcc4.6: -O0
r1: 15 r2: 2
gcc4.6: -O1,-O2..
r1: 47 r2: 2
#include <stdio.h>
int tester(char *bytes)
{
union {
struct {
unsigned int r1:4;
unsigned int r2:4;
} fmt;
char value[1];
} ovl;
ovl.value[0] = bytes[0];
printf("r1: %d r2: %d\n", ovl.fmt.r1, ovl.fmt.r2);
return 0;
}
int main()
{
char buff = 0x2f;
return tester(&buff);
}
--
Summary: miscompile with bitfield and optimization
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: borntraeger at de dot ibm dot com
GCC build triplet: i686-pc-linux-gnu and s390x-ibm-linux-gnu
GCC host triplet: i686-pc-linux-gnu and s390x-ibm-linux-gnu
GCC target triplet: i686-pc-linux-gnu and s390x-ibm-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45017