Alignment of unions containing vector types
Tim Prince
tprince@computer.org
Sat May 25 10:12:00 GMT 2002
On Saturday 25 May 2002 03:38, David Robinson wrote:
> Summary:
>
> GCC 3.1 does not correctly set the alignment required for a union
> containing one of the new vector types.
>
> Version: gcc 3.1 compiled for i686-pc-linux-gnu, on Redhat 7.2, Linux
> kernel 2.4.18, CPU PentiumIII-M.
>
> The program produces:
> alignof(v2si_u): 4
> alignof(v2si): 8; x: 0xbffffa30
>
> David Robinson (drtr@enjura.com)
>
> Source:
> #include <stdio.h>
> #include <stdlib.h>
>
> typedef int _v2si __attribute__ ((mode(V2SI)));
>
> typedef union
> {
> _v2si v;
> int i[2];
> } v2si_u;
>
>
> typedef union
> {
> _v2si v;
> int i[2];
> } v2si __attribute__ ((aligned(__alignof__(_v2si))));
>
>
> int
> main(int argc, char **argv)
> {
> v2si x;
>
> printf("alignof(v2si_u): %d\n", __alignof__(v2si_u));
> printf("alignof(v2si): %d; x: %p\n", __alignof__(x), &x);
>
> exit(0);
> }
AFAIK, gcc is not expected to be capable of forcing alignments in main(). I
think the documentation on this might be improved. I don't know whether it
is considered a bug if the option -mpreferred-stack-boundary=4 has to be
issued specifically in order for called functions to observe alignments.
--
Tim Prince
More information about the Gcc-bugs
mailing list