This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: On alignment


On Sat, 22 Mar 2003 09:12:32 +0000 (GMT), Andrew Haley <aph at redhat dot com> wrote:

> Jason Merrill writes:
>  > Can you give me an example of a case that needs an aligned attribute?  What
>  > is the Java frontend doing that makes this necessary?
>
> http://gcc.gnu.org/ml/gcc-patches/2003-03/msg00429.html

OK, you're trying to suppress the tail padding optimization.  It occurred
to me that another way to express that could be

  struct B : A {
    // force normal alignment
    char : 0 __attribute ((__aligned (__alignof (A))));
    short bs;
  };

but of course that doesn't work properly either; user-specified alignment
is currently ignored on a zero-length bitfield.  But that's a one-line fix,
and shouldn't create a compatibility problem, since there would have been
no point in specifying such an alignment before.  Would that work for you?

We may well still want to fix the other bugs, but perhaps not in 3.3.  I'm
still interested in other opinions.

Jason

*** stor-layout.c.~1~	2003-01-26 04:02:25.000000000 -0500
--- stor-layout.c	2003-03-24 19:26:55.000000000 -0500
*************** update_alignment_for_field (rli, field, 
*** 758,764 ****
  	 within the structure.  */
        if (! integer_zerop (DECL_SIZE (field)))
  	rli->record_align = MAX (rli->record_align, desired_align);
!       else if (! DECL_PACKED (field))
  	desired_align = TYPE_ALIGN (type);
  
        /* A named bit field of declared type `int'
--- 758,764 ----
  	 within the structure.  */
        if (! integer_zerop (DECL_SIZE (field)))
  	rli->record_align = MAX (rli->record_align, desired_align);
!       else if (! DECL_PACKED (field) && !user_align)
  	desired_align = TYPE_ALIGN (type);
  
        /* A named bit field of declared type `int'

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]