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

            Bug ID: 89357
           Summary: alignas for automatic variables with alignment greater
                    than 16 fails
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kretz at kde dot org
  Target Milestone: ---
            Target: aarch64-*-*, arm-*-*

Test case (cf. https://godbolt.org/z/ubJge4):

void g(int &);

auto f0() {
  __attribute__((aligned(128))) int x;
  g(x);
}

auto f1() {
  alignas(128) int x;
  g(x);
}

In f0, x is aligned on 128 Bytes, in f1 it is aligned on 16 Bytes. GCC emits
the warning "requested alignment 128 is larger than 16 [-Wattributes]". The
warning is not helpful as it only states an obvious fact (128 > 16). In any
case, it is unclear why the alignment is rejected in the first place.

http://eel.is/c++draft/dcl.align#2.2 says "[...] the implementation does not
support that alignment in the context of the declaration, the program is
ill-formed". Thus, compiling with alignment of 16 is non-conforming. If the
alignment is unsupported this needs to be a error.

My preferred solution would be to just align x in f1 to 128 Bytes. Why should
alignas and the aligned attribute behave differently?

On x86, power, mips, and msp430 (tested on Compiler Explorer) f0 and f1 are
equivalent.

Reply via email to