https://gcc.gnu.org/g:27d9bccf905fd54ee6403c0d1d169a838a30fccc
commit r17-6653-g27d9bccf905fd54ee6403c0d1d169a838a30fccc Author: Eric Botcazou <[email protected]> Date: Tue Nov 24 20:05:15 2026 +0100 SPARC: Fix instruction not satisfying its constraints This is an internal error in recog coming from an invalid floating-point hard register created by the SPARC back-end to pass a 12-byte structure in slot 15. gcc/ PR target/128992 * config/sparc/sparc.cc (compute_fp_layout): Take into account the offset of the field in the slot. gcc/testsuite/ * gcc.target/sparc/20261124-1.c: New test. Diff: --- gcc/config/sparc/sparc.cc | 5 ++-- gcc/testsuite/gcc.target/sparc/20261124-1.c | 43 +++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc index ca2994e0fd78..4330698dee2f 100644 --- a/gcc/config/sparc/sparc.cc +++ b/gcc/config/sparc/sparc.cc @@ -7031,6 +7031,7 @@ compute_fp_layout (const_tree field, int bitpos, assign_data_t *data, int *pnregs, machine_mode *pmode) { const int this_slotno = data->slotno + bitpos / BITS_PER_WORD; + const int this_offset = (bitpos % BITS_PER_WORD) / BITS_PER_UNIT; machine_mode mode = DECL_MODE (field); int nregs, nslots; @@ -7056,12 +7057,12 @@ compute_fp_layout (const_tree field, int bitpos, assign_data_t *data, else nregs = 1; - nslots = CEIL_NWORDS (nregs * GET_MODE_SIZE (mode)); + nslots = CEIL_NWORDS (this_offset + nregs * GET_MODE_SIZE (mode)); if (nslots > SPARC_FP_ARG_MAX - this_slotno) { nslots = SPARC_FP_ARG_MAX - this_slotno; - nregs = (nslots * UNITS_PER_WORD) / GET_MODE_SIZE (mode); + nregs = (nslots * UNITS_PER_WORD - this_offset) / GET_MODE_SIZE (mode); /* We need to pass this field (partly) on the stack. */ data->stack = 1; diff --git a/gcc/testsuite/gcc.target/sparc/20261124-1.c b/gcc/testsuite/gcc.target/sparc/20261124-1.c new file mode 100644 index 000000000000..33205e24851c --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/20261124-1.c @@ -0,0 +1,43 @@ +/* PR target/128992 */ + +/* { dg-do run } */ +/* { dg-require-effective-target lp64 } */ +/* { dg-options "-std=gnu99" } */ + +extern void abort (void); + +/* Pass a 12-byte structure partially in slot #15 and on the stack. */ + +struct S1 { float f1; _Complex float f2; }; + +void f1 (int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8, + int p9, int p10, int p11, int p12, int p13, int p14, int p15, + struct S1 s1) +{ + register float f30 asm ("f30"); + register float f31 asm ("f31"); + + if (f30 != 4.0f) + abort (); + + if (f31 != 5.0f) + abort (); + + if (s1.f1 != 4.0f) + abort (); + + if (__real__ s1.f2 != 5.0f) + abort (); + + if (__imag__ s1.f2 != 6.0f) + abort (); +} + +int main (void) +{ + struct S1 s1 = { 4.0f, 5.0f + 6.0fi }; + + f1 (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, s1); + + return 0; +}
