[Bug c/94338] struct member alignment is not carried over to alignment of struct variable

huaixin.chx@alibaba-inc.com gcc-bugzilla@gcc.gnu.org
Fri Mar 27 13:36:06 GMT 2020


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

--- Comment #10 from huaixin chang <huaixin.chx@alibaba-inc.com> ---
(In reply to Richard Biener from comment #9)
> Btw,
> 
> struct X {
>     long a __attribute__((__aligned__(128)));
>     long b __attribute__((__aligned__(128)));
> };
> struct X A __attribute__((__aligned__(4)));
> 
> is not diagnosed (this is what your testcase is, decomposed).
> 
> I can't reproduce the diagnostics you describe in comment#5

I am sorry that I made a mistake in testing typedef described in comment#5.

I spelled __aligned__ into __aligned, got warned "warning: '__aligned'
attribute directive ignored [-Wattributes]", and thought I got diagnosed
because of reduction in alignment. As a result, neither type foo nor object A
is reduced in alignment with the code describe in comment#5.

I have tested typedef again, and found that it behaves the same with using
struct under gcc 9.2.1. That is to say, no matter I define A using struct like:

-----------------------------------
struct X {
    long a __attribute__((__aligned__(128)));
    long b __attribute__((__aligned__(128)));
};
struct X A __attribute__((__aligned__(4)));

or use typedef and reduce the alignment of type foo like:
-----------------------------------
typedef struct {
        long a __attribute__((__aligned__(128)));
        long b __attribute__((__aligned__(128)));
} foo __attribute__((__aligned(4)));

foo A;

or use typedef and reduce the alignment of A like:
-----------------------------------
typedef struct {
        long a __attribute__((__aligned__(128)));
        long b __attribute__((__aligned__(128)));
} foo;

foo A __attribute__((__aligned__(4)));

I got no warn on compiling and it behaves like this.
-----------------------------------
address of A 0x42003c
alignof A 4
address of A.a 0x42003c
alignof A.a 128
address of A.b 0x4200bc
alignof A.b 128
address of B 0x420038


More information about the Gcc-bugs mailing list