public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: On alignment
@ 2003-03-25 16:48 Kevin B. Hendricks
  2003-03-25 18:39 ` Jason Merrill
  0 siblings, 1 reply; 51+ messages in thread
From: Kevin B. Hendricks @ 2003-03-25 16:48 UTC (permalink / raw)
  To: gcc, aph, jason

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

FWIW: 

If I am not mistaken, a similar approach was used by OpenOffice.org when trying to support 
both gcc 2.9.5X components and gcc 3.X components 

Here is a piece of the cppu component test code:

#define CPPU_GCC3_ALIGN( base_struct ) __attribute__ ((aligned (__alignof__ (base_struct))))

struct C1
{
    signed short n1;
};

struct C2 : public C1
{
    signed long n2 CPPU_GCC3_ALIGN( C1 );
};

...

struct M
{
        signed long     n;
        signed short    o;
};

struct N : public M
{
        signed short    p CPPU_GCC3_ALIGN( M );
};

Kevin

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: On alignment
@ 2003-04-23 19:47 Robert Dewar
  0 siblings, 0 replies; 51+ messages in thread
From: Robert Dewar @ 2003-04-23 19:47 UTC (permalink / raw)
  To: jamie, joern.rennecke; +Cc: aph, gcc, jason, schwab

> Well, what about struct bar { double x; int y; double z; } ?
> giving it an alignment of 8 doesn't improve things, as one double will
> always be misaligned.  OTOH it is odd to have a lower alignment for
> bar than for foo, even though the start of bar has the same structure
> as the entirety of foo.

Yes, but so what, just because you can find an example where you can't
improve things is no reason not to improve things when you can :-)

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: On alignment
@ 2003-04-23 19:34 Joern Rennecke
  0 siblings, 0 replies; 51+ messages in thread
From: Joern Rennecke @ 2003-04-23 19:34 UTC (permalink / raw)
  To: Jamie Lokier; +Cc: Andreas Schwab, Andrew Haley, Jason Merrill, gcc

> For the same reason, "struct foo { double x; }" as a standalone
> variable should have alignment 8, not 4.  Andrew's test shows it has
> an alignment of 4.

Well, what about struct bar { double x; int y; double z; } ?
giving it an alignment of 8 doesn't improve things, as one double will
always be misaligned.  OTOH it is odd to have a lower alignment for
bar than for foo, even though the start of bar has the same structure
as the entirety of foo.

-- 
--------------------------
SuperH (UK) Ltd.
2410 Aztec West / Almondsbury / BRISTOL / BS32 4QX
T:+44 1454 465658

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: On alignment
@ 2003-04-22 17:19 Robert Dewar
  0 siblings, 0 replies; 51+ messages in thread
From: Robert Dewar @ 2003-04-22 17:19 UTC (permalink / raw)
  To: aph, jason; +Cc: dewar, gcc, nathan

> It's the same in C.  Weird or not, that's what the SVR4 psABI says, so
> that's what we do.

Of course this is an excellent example of a case where for stand alone
objects of the type, the alignment should be increased to get efficient
execution. This increase for stand alone objects of course is compatibole
with the SVR4 ABI.

^ permalink raw reply	[flat|nested] 51+ messages in thread
* Re: On alignment
@ 2003-04-22 14:43 Robert Dewar
  2003-04-22 15:13 ` Andrew Haley
  0 siblings, 1 reply; 51+ messages in thread
From: Robert Dewar @ 2003-04-22 14:43 UTC (permalink / raw)
  To: aph, nathan; +Cc: gcc, jason

> That packing rule is part of the i86 psABI

It's still mighty odd, and of course in Ada you have to override this rule
since it conflicts with the Ada standard, which requires that the default
minimum alignment of a composite be not less than the alignment of any
component.

^ permalink raw reply	[flat|nested] 51+ messages in thread
* On alignment
@ 2003-03-21  0:25 Jason Merrill
  2003-03-21 11:49 ` Andrew Haley
  2003-03-21 15:39 ` Michael Matz
  0 siblings, 2 replies; 51+ messages in thread
From: Jason Merrill @ 2003-03-21  0:25 UTC (permalink / raw)
  To: gcc; +Cc: Andrew Haley, Jakub Jelinek, Jason Merrill

Andrew Haley recently pointed me at an alignment bug:

  http://gcc.gnu.org/ml/gcc/2003-03/msg01196.html

Here, the presence of an aligned attribute is giving the field alignment of
8, even though only 4 was requested.  This worked in 2.95, but has been
broken in all 3.x releases (i.e. since Jakub's *_USER_ALIGN changes).

This happens because DECL_USER_ALIGN overrides BIGGEST_FIELD_ALIGNMENT.
The right way to handle this is to clear DECL_USER_ALIGN when rounding up
DECL_ALIGN to TYPE_ALIGN; the code in layout_decl gets this right, but
check_field_decl in the C++ frontend and finish_struct in the C frontend
get it wrong.

Do people think this bug is worth fixing?  The behavior is rather
surprising, but changing it might break binary compatibility for affected
code--of which there's not likely to be very much, but there could be some.
Code which really wants, say, aligment of 4 for long long could say
__attribute__ ((packed, aligned (4))).  On the other hand, the change would
restore binary compatibility with 2.95 for C code.

Jason

Asides: it seems to me that there's no reason for the frontends to be
messing with this sort of thing without a good reason; record layout should
be handled in stor-layout.c as much as possible.  Most of the existing code
in the C and C++ frontends that touch DECL_ALIGN is redundant.

Also, I noticed that EMPTY_FIELD_BOUNDARY is only handled in the frontend,
and that it is ignored on targets which define PCC_BITFIELD_TYPE_MATTERS,
though that is not made clear in tm.texi.  I plan to clean these bits up
while I'm looking at this stuff.

^ permalink raw reply	[flat|nested] 51+ messages in thread

end of thread, other threads:[~2003-05-08  9:58 UTC | newest]

Thread overview: 51+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-25 16:48 On alignment Kevin B. Hendricks
2003-03-25 18:39 ` Jason Merrill
2003-03-25 18:41   ` Jason Merrill
2003-03-25 19:14     ` Kevin B. Hendricks
2003-03-25 19:57       ` Jason Merrill
2003-04-22 11:36         ` Andrew Haley
2003-04-22 12:05           ` Nathan Sidwell
2003-04-22 12:37             ` Andrew Haley
2003-04-22 13:15           ` Andreas Schwab
2003-04-23 13:32             ` Jamie Lokier
2003-04-23 16:07               ` Jason Merrill
2003-04-23 17:41               ` Tom Tromey
2003-04-23 18:06                 ` Jason Merrill
2003-04-23 18:42                   ` Tom Tromey
2003-04-23 19:13                     ` Jason Merrill
2003-04-23 19:43                       ` Gabriel Dos Reis
2003-04-23 20:23                         ` Tom Tromey
2003-04-23 21:45                           ` Gabriel Dos Reis
2003-04-24  7:00                           ` Jason Merrill
2003-04-24 11:45                             ` Andrew Haley
2003-05-01 23:50                               ` Tom Tromey
2003-05-02 13:08                                 ` Gabriel Dos Reis
2003-05-05 14:56                                   ` Jason Merrill
2003-05-08  9:58                                     ` Gabriel Dos Reis
2003-04-23 19:33                     ` Gabriel Dos Reis
2003-04-24  1:32                     ` Jamie Lokier
2003-03-25 21:27       ` Tom Tromey
2003-03-26 12:58         ` Andrew Haley
2003-03-26 22:26           ` Mark Mitchell
2003-03-25 18:57   ` Tom Tromey
  -- strict thread matches above, loose matches on Subject: below --
2003-04-23 19:47 Robert Dewar
2003-04-23 19:34 Joern Rennecke
2003-04-22 17:19 Robert Dewar
2003-04-22 14:43 Robert Dewar
2003-04-22 15:13 ` Andrew Haley
2003-04-22 16:22   ` Jason Merrill
2003-04-22 16:26     ` Nicola Pero
2003-04-22 17:19       ` Andrew Haley
2003-04-22 18:46       ` Jason Merrill
2003-04-22 17:17     ` Andrew Haley
2003-03-21  0:25 Jason Merrill
2003-03-21 11:49 ` Andrew Haley
2003-03-21 15:18   ` Andrew Haley
2003-03-21 19:31   ` Tom Tromey
2003-03-21 15:39 ` Michael Matz
2003-03-21 15:41   ` Andrew Haley
2003-03-22  0:25     ` Jason Merrill
2003-03-22  9:35       ` Tom Tromey
2003-03-22 10:31       ` Andrew Haley
2003-03-25  2:52         ` Jason Merrill
2003-03-25 10:16           ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).