Tests t007 and t177 from the C++ struct-layout-1 compat tests fail when using
GCC 4.3.3 as ALT compilers when testing trunk.  The failure for one, check 932
in test t007, is due to a change from

  r132614 | ebotcazou | 2008-02-25 09:55:26 +0000 (Mon, 25 Feb 2008) | 4 lines

        * stor-layout.c (layout_decl): Do not bump the alignment of a
        bit-field to more than byte alignment if it is packed.

Here's a smaller C testcase that shows the change:

------------------------------------------------------------------------
#include <stdio.h>

struct S932
{
  long int a;
  short int b;
  struct
  {
    __attribute__ ((aligned (2))) int d:32;
  } __attribute__ ((packed)) c;
  unsigned short int e;
};
struct S932 s932;

int
main ()
{
  void *p1, *p2;
  p1 = &s932;
  p2 = &s932.e;
  printf ("offset of e  = %lu\n", (unsigned long ) (p2 - p1));
  printf ("size of s932 = %lu\n", (unsigned long) sizeof (s932));
  return 0;
}
------------------------------------------------------------------------

For 4.3.3 the output is:

offset of e  = 12
size of s932 = 16

For trunk the output is:

offset of e  = 10
size of s932 = 12

I see this on powerpc64-unknown-linux-gnu with -m32 and -m64, but it looks as
if it would affect all targets.

Recently, warning option -Wpacked-bitfield-compat was added in

  r143718 | nemet | 2009-01-27 18:55:20 -0800 (Tue, 27 Jan 2009) | 7 lines

        * c.opt (Wpacked-bitfield-compat): Change init value to -1.
        * c-opts.c (c_common_post_options): If -W*packed-bitfield-compat
        was not supplied then set warn_packed_bitfield_compat to the
        default value of 1.
        * stor-layout.c (place_field): Check warn_packed_bitfield_compat
        against 1.

I'd like to see this message, which is on by default, for the change introduced
in r132614.  I haven't figured out how to determine if the offset for a field
has changed, just the alignment.  I'll attach my current patch, where the
message should be "Perhaps the alignment of packed bit-field <x> has changed in
GCC 4.4", which is not terribly useful.  The testsuite changes from that patch
will be needed if the message is used for t005 and t177.

I'll be out of touch for the next week and will be delighted if someone else
fixes this.


-- 
           Summary: unreported change to packed bitfields
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janis at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39514

Reply via email to