]> gcc.gnu.org Git - gcc.git/commit
aarch64: Fix ABI handling of aligned enums [PR109661]
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 3 May 2023 16:43:48 +0000 (17:43 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 3 May 2023 16:43:48 +0000 (17:43 +0100)
commit1c26adba4b95f9a79f3aa57637d34cff7982d832
treee809399ce03481b70537193e1e1ef8284c7f13f1
parent3a4a39b391e63e5be04cb06ee4cd5400bef63dfc
aarch64: Fix ABI handling of aligned enums [PR109661]

aarch64_function_arg_alignment has traditionally taken the alignment
of a scalar type T from TYPE_ALIGN (TYPE_MAIN_VARIANT (T)).  This is
supposed to discard any user alignment and give the alignment of the
underlying fundamental type.

PR109661 shows that this did the wrong thing for enums with
a defined underlying type, because:

(1) The enum itself could be aligned, using attributes.
(2) The enum would pick up any user alignment on the underlying type.

We get the right behaviour if we look at the TYPE_MAIN_VARIANT
of the underlying type instead.

As always, this affects register and stack arguments differently,
because:

(a) The code that handles register arguments only considers the
    alignment of types that occupy two registers, whereas the
    stack alignment is applied regardless of size.

(b) The code that handles register arguments tests the alignment
    for equality with 16 bytes, so that (unexpected) greater alignments
    are ignored.  The code that handles stack arguments instead caps the
    alignment to 16 bytes.

There is now (since GCC 13) an assert to trap the difference between
(a) and (b), which is how the new incompatiblity showed up.

Clang alredy handled the testcases correctly, so this patch aligns
the GCC behaviour with the Clang behaviour.

I'm planning to remove the asserts on the branches, since we don't
want to change the ABI there.

gcc/
PR target/109661
* config/aarch64/aarch64.cc (aarch64_function_arg_alignment): Add
a new ABI break parameter for GCC 14.  Set it to the alignment
of enums that have an underlying type.  Take the true alignment
of such enums from the TYPE_ALIGN of the underlying type's
TYPE_MAIN_VARIANT.
(aarch64_function_arg_boundary): Update accordingly.
(aarch64_layout_arg, aarch64_gimplify_va_arg_expr): Likewise.
Warn about ABI differences.

gcc/testsuite/
* g++.target/aarch64/pr109661-1.C: New test.
* g++.target/aarch64/pr109661-2.C: Likewise.
* g++.target/aarch64/pr109661-3.C: Likewise.
* g++.target/aarch64/pr109661-4.C: Likewise.
* gcc.target/aarch64/pr109661-1.c: Likewise.
gcc/config/aarch64/aarch64.cc
gcc/testsuite/g++.target/aarch64/pr109661-1.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr109661-2.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr109661-3.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr109661-4.C [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr109661-1.c [new file with mode: 0644]
This page took 0.065977 seconds and 6 git commands to generate.