https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43798

--- Comment #18 from Zdenek Sojka <zsojka at seznam dot cz> ---
>From my (of course limited) experience, such behavior is unexpected by the
user. The user really wants:

typedef
struct  __attribute__((aligned(16))) {
    unsigned long long w[3];
} UINT192;

OR

typedef
struct {
    unsigned long long w[3];
} __attribute__((aligned(16))) UINT192;

BUT if he writes

typedef __attribute__((aligned(16)))
struct {
    unsigned long long w[3];
} UINT192;

OR

typedef
struct {
    unsigned long long w[3];
} UINT192 __attribute__((aligned(16)));

he then gets this broken code (array elements not aligned to 16).



Currently, you get an error for:

typedef __attribute__((__aligned__(64)))
struct {
    int a;
} SMALL ;

SMALL s[2];

$ gcc tst.c
tst.c:64:1: error: alignment of array elements is greater than element size
 SMALL s[2];
 ^~~~~

BUT not for:

typedef __attribute__((__aligned__(64)))
struct {
    int a[100];
} BIG;

BIG b[2];

even though this is leads to the same kind bugs as using SMALL.
(b[1] is not aligned to 64)
_Alignof(BIG)=64, sizeof(BIG)=400
_Alignof(b)=64, sizeof(b)=832 (why?)

I think a warning for declaration of both SMALL and BIG, or at least when
declaring "BIG b[2]", would be reasonable.

Reply via email to