Commit 7e4aeb32 by Jason Merrill Committed by Jason Merrill

re PR middle-end/27945 (Packed struct of variable length has wrong size)

        PR middle-end/27945
        * stor-layout.c (layout_decl): Do pack variable size fields.

From-SVN: r128380
parent 257fafe0
2007-09-11 Jason Merrill <jason@redhat.com>
PR middle-end/27945
* stor-layout.c (layout_decl): Do pack variable size fields.
2007-09-11 Maxim Kuvyrkov <maxim@codesourcery.com> 2007-09-11 Maxim Kuvyrkov <maxim@codesourcery.com>
* config/m68k/predicates.md (movsi_const0_operand, * config/m68k/predicates.md (movsi_const0_operand,
...@@ -414,18 +414,11 @@ layout_decl (tree decl, unsigned int known_align) ...@@ -414,18 +414,11 @@ layout_decl (tree decl, unsigned int known_align)
else else
do_type_align (type, decl); do_type_align (type, decl);
/* If the field is of variable size, we can't misalign it since we /* If the field is packed and not explicitly aligned, give it the
have no way to make a temporary to align the result. But this minimum alignment. Note that do_type_align may set
isn't an issue if the decl is not addressable. Likewise if it DECL_USER_ALIGN, so we need to check old_user_align instead. */
is of unknown size.
Note that do_type_align may set DECL_USER_ALIGN, so we need to
check old_user_align instead. */
if (packed_p if (packed_p
&& !old_user_align && !old_user_align)
&& (DECL_NONADDRESSABLE_P (decl)
|| DECL_SIZE_UNIT (decl) == 0
|| TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST))
DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT); DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
if (! packed_p && ! DECL_USER_ALIGN (decl)) if (! packed_p && ! DECL_USER_ALIGN (decl))
......
/* { dg-do run } */
/* { dg-options "" } */
extern int printf (const char *, ...);
extern void abort ();
int func(int levels)
{
struct bar {
unsigned char a;
int b[levels];
} __attribute__ ((__packed__)) bar;
struct foo {
unsigned char a;
int b[4];
} __attribute__ ((__packed__)) foo;
printf("foo %d\n", sizeof(foo));
printf("bar %d\n", sizeof(bar));
if (sizeof (foo) != sizeof (bar))
abort ();
}
int main()
{
func(4);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment