https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125023
Bug ID: 125023
Summary: x86_64: Inconsistent ABI behaviour when passing a
structure with a zero-sized multidimensional array by
value.
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: sergey_v_kaplun at mail dot ru
Target Milestone: ---
When passing the small structure with a zero-sized multidimensional array by
value, the behaviour is inconsistent -- it may be passed through the stack or
in registers depending on the size of the sub-array due to
`classify_argument()`
checks.
Clang already handles all such multidimensional arrays consistently through
registers.
See an example:
C: https://godbolt.org/z/eh6r148MG
C++: https://godbolt.org/z/Ms3jxcn6f
Side note: (I understand that the issue is very specific, so it may be better
not fixed to be backward-compatible with older GCC versions but OTOH
incompatible with Clang).
The testcase:
/* { dg-do compile } */
/* { dg-options "-O1 -msse" } */
typedef struct
{
float x;
float hole[0][2][2];
float y;
} float_hole;
float
sum (float_hole h) /* { dg-message "the ABI of passing struct with a zero-sized
array member has changed in GCC 16.1" } */
{
return h.x + h.y;
}
/* Check that pass-by-value structure is placed in registers, not on stack. */
/* { dg-final { scan-assembler-not "rsp" } } */
/* { dg-final { scan-assembler "movdqa" } } */