aarch64: Fix -fpack-struct + <arm_neon.h> [PR103147]
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 5 Apr 2022 16:31:35 +0000 (17:31 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 5 Apr 2022 16:31:35 +0000 (17:31 +0100)
commit14814e20161d7b6a4e9cac244c7013fa56f71f55
tree318912f70236fbabbff538bebc1aa62955087ec8
parente8bc70cc17b0105e2c463a98c9ff76039d03ff60
aarch64: Fix -fpack-struct + <arm_neon.h> [PR103147]

This PR is about -fpack-struct causing a crash when <arm_neon.h>
is included.  The new register_tuple_type code was expecting a
normal unpacked structure layout instead of a packed one.

For SVE we got around this by temporarily suppressing -fpack-struct,
so that the tuple types always have their normal ABI.  However:

(a) The SVE ACLE tuple types are defined to be abstract.  The fact
    that GCC uses structures is an internal implementation detail.

(b) In contrast, the ACLE explicitly defines the Advanced SIMD
    tuple types to be particular structures.

(c) Clang and previous versions of GCC are consistent in applying
    -fpack-struct to these tuple structures.

This patch therefore honours -fpack-struct and -fpack-struct=.  It also
adds tests for some other combinations, such as -mgeneral-regs-only and
-fpack-struct -mstrict-align.

gcc/
PR target/103147
* config/aarch64/aarch64-protos.h (aarch64_simd_switcher): New class.
* config/aarch64/aarch64-sve-builtins.h (sve_switcher): Inherit
from aarch64_simd_switcher.
* config/aarch64/aarch64-builtins.cc (aarch64_simd_tuple_modes):
New variable.
(aarch64_lookup_simd_builtin_type): Use it instead of TYPE_MODE.
(register_tuple_type): Add more asserts.  Expect the alignment
of the structure to be subject to flag_pack_struct and
maximum_field_alignment.  Set aarch64_simd_tuple_modes.
(aarch64_simd_switcher::aarch64_simd_switcher): New function.
(aarch64_simd_switcher::~aarch64_simd_switcher): Likewise.
(handle_arm_neon_h): Hold an aarch64_simd_switcher throughout.
(aarch64_general_init_builtins): Hold an aarch64_simd_switcher
while calling aarch64_init_simd_builtins.
* config/aarch64/aarch64-sve-builtins.cc (sve_switcher::sve_switcher)
(sve_switcher::~sve_switcher): Remove code now performed by
aarch64_simd_switcher.

gcc/testsuite/
PR target/103147
* gcc.target/aarch64/pr103147-1.c: New test.
* gcc.target/aarch64/pr103147-2.c: Likewise.
* gcc.target/aarch64/pr103147-3.c: Likewise.
* gcc.target/aarch64/pr103147-4.c: Likewise.
* gcc.target/aarch64/pr103147-5.c: Likewise.
* gcc.target/aarch64/pr103147-6.c: Likewise.
* gcc.target/aarch64/pr103147-7.c: Likewise.
* gcc.target/aarch64/pr103147-8.c: Likewise.
* gcc.target/aarch64/pr103147-9.c: Likewise.
* gcc.target/aarch64/pr103147-10.c: Likewise.
* g++.target/aarch64/pr103147-1.C: Likewise.
* g++.target/aarch64/pr103147-2.C: Likewise.
* g++.target/aarch64/pr103147-3.C: Likewise.
* g++.target/aarch64/pr103147-4.C: Likewise.
* g++.target/aarch64/pr103147-5.C: Likewise.
* g++.target/aarch64/pr103147-6.C: Likewise.
* g++.target/aarch64/pr103147-7.C: Likewise.
* g++.target/aarch64/pr103147-8.C: Likewise.
* g++.target/aarch64/pr103147-9.C: Likewise.
* g++.target/aarch64/pr103147-10.C: Likewise.
24 files changed:
gcc/config/aarch64/aarch64-builtins.cc
gcc/config/aarch64/aarch64-protos.h
gcc/config/aarch64/aarch64-sve-builtins.cc
gcc/config/aarch64/aarch64-sve-builtins.h
gcc/testsuite/g++.target/aarch64/pr103147-1.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-10.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-2.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-3.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-4.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-5.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-6.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-7.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-8.C [new file with mode: 0644]
gcc/testsuite/g++.target/aarch64/pr103147-9.C [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-10.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-3.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-4.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-5.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-6.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-7.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-8.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr103147-9.c [new file with mode: 0644]