Alignment of unions containing vector types

David Robinson drtr@enjura.com
Sat May 25 03:39:00 GMT 2002


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);
}





More information about the Gcc-bugs mailing list