This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
bug in bit field treatment
- From: Boris Tobotras <tobotras at jet dot msk dot su>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 24 Jan 2002 12:53:51 +0300
- Subject: bug in bit field treatment
This sample shows the bug:
#include <stdlib.h>
struct test {
char q1: 4,
q2: 4;
int q3;
};
main( void )
{
struct test *q = ( test * )
((( char * ) malloc( sizeof( struct test ) * 10 )) + 2);
q->q1 = 1;
q->q2 = 2;
}
Verified on at least both SPARC and Alpha, gcc accesses q1/q2 as
aligned on int boundary. If however you change int q3 to be char, bug is
disappeared. SPARC assembly code for q->q1 = 1 follows:
ld [%fp-20], %o2
ld [%o2], %o1
sethi %hi(268434432), %o0
or %o0, 1023, %o0
and %o1, %o0, %o0
sethi %hi(268435456), %o1
or %o0, %o1, %o0
st %o0, [%o2]
Second ld craches the program. With "char q3", however, it
becomes:
ld [%fp-20], %o1
ldub [%o1], %o0
and %o0, 15, %o0
or %o0, 16, %o0
stb %o0, [%o1]
which is right. Tested with 2.95.3 and 3.0.2. Thanks,
--
Best regards, -- Boris.