[Bug c/51628] __attribute__((packed)) is unsafe in some cases
rguenther at suse dot de
gcc-bugzilla@gcc.gnu.org
Wed Apr 3 09:20:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51628
--- Comment #22 from rguenther at suse dot de <rguenther at suse dot de> 2013-04-03 09:20:21 UTC ---
On Wed, 3 Apr 2013, ebotcazou at gcc dot gnu.org wrote:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51628
>
> --- Comment #21 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2013-04-03 08:51:44 UTC ---
> > One of the C frontend issues is that the type of the address of
> > the field of the packed struct is int *, not int attribute((aligned(1)))
> > *. And this is so because nothing adjusts the type of the FIELD_DECL
> > to be a less aligned type. That is, we have
> >
> > <field_decl 0x7ffff6d245f0 i
> > type <integer_type 0x7ffff6d175e8 int public SI
> > size <integer_cst 0x7ffff6d1a0c0 constant 32>
> > unit size <integer_cst 0x7ffff6d1a0e0 constant 4>
> > align 32 symtab 0 alias set -1 canonical type 0x7ffff6d175e8
> > precision 32 min <integer_cst 0x7ffff6d1a060 -2147483648> max <integer_cst
> > 0x7ffff6d1a080 2147483647>
> > pointer_to_this <pointer_type 0x7ffff6d1f2a0>>
> > packed SI file t.c line 2 col 9 size <integer_cst 0x7ffff6d1a0c0 32>
> > unit size <integer_cst 0x7ffff6d1a0e0 4>
> > align 8 offset_align 128
> > offset <integer_cst 0x7ffff6d02d80 type <integer_type 0x7ffff6d17000
> > sizetype> constant 0>
> > bit offset <integer_cst 0x7ffff6d02e00 type <integer_type
> > 0x7ffff6d170a8 bitsizetype> constant 0> context <record_type
> > 0x7ffff6e1c3f0 Foo>>
>
> This is on x86, right? If the alignment of the field cannot be guaranteed to
> be that of its type, then it should be made a bit-field. Maybe it's already
> made a bit-field on strict-alignment targets.
Note the FIELD_DECL is perfectly ok (align 8), it is its TREE_TYPE
that is "bogus", and this type is used when building the pointer type
used for taking the address of it (so you could argue _that_ is the
bug - it shouldn't literally take TREE_TYPE of a FIELD_DECL when
building the address of a COMPONENT_REF - the COMPONENT_REF
surely only caring about the type of the value not the storage).
Richard.
More information about the Gcc-bugs
mailing list