https://gcc.gnu.org/g:806799b32698fd509f03254132d6d29eba80ae5d
commit r17-6469-g806799b32698fd509f03254132d6d29eba80ae5d Author: Eric Botcazou <[email protected]> Date: Thu Nov 19 14:59:03 2026 +0100 SPARC: Fix internal error in function_arg_record_value This is an assertion failure in the function_arg_record_value routine of the SPARC back-end, but which comes from function_arg_slotno returning a slot for a structure containing a 1-element array of float passed as 7th argument to a function, while it should be passed on the stack on Linux. Fixed by finally redirecting the processing for all structures and unions in function_arg_record_value to the BLKmode path. Tested and compat-tested on SPARC64/Solaris, applied on the mainline. gcc/ * config/sparc/sparc.cc (sparc_pass_by_reference): Fix typos in comments. (function_arg_slotno): Redirect the processing for all structures and unions to the BLKmode path. Test TARGET_ARCH64. (sparc_function_arg_1): Minor cleanup. (sparc_return_in_memory): Fix typos in comments. gcc/testsuite/ * gcc.target/sparc/small-struct-2.c: New test. Diff: --- gcc/config/sparc/sparc.cc | 66 +++++++++++++++---------- gcc/testsuite/gcc.target/sparc/small-struct-2.c | 12 +++++ 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/gcc/config/sparc/sparc.cc b/gcc/config/sparc/sparc.cc index efc2e9467d72..ed16fa870333 100644 --- a/gcc/config/sparc/sparc.cc +++ b/gcc/config/sparc/sparc.cc @@ -6757,7 +6757,7 @@ sparc_pass_by_reference (cumulative_args_t, const function_arg_info &arg) Vector ABI (as implemented by the Sun VIS SDK) says that integer vectors are passed like floats of the same size, that is in registers up to 8 bytes. Pass all vector floats by reference - like structure and unions. */ + like structures and unions. */ return ((type && (AGGREGATE_TYPE_P (type) || VECTOR_FLOAT_TYPE_P (type))) || mode == SCmode /* Catch CDImode, TFmode, DCmode and TCmode. */ @@ -6777,7 +6777,7 @@ sparc_pass_by_reference (cumulative_args_t, const function_arg_info &arg) Vector ABI (as implemented by the Sun VIS SDK) says that integer vectors are passed like floats of the same size, that is in - registers (up to 16 bytes). Pass all vector floats like structure + registers (up to 16 bytes). Pass all vector floats like structures and unions. */ return ((type && (AGGREGATE_TYPE_P (type) || VECTOR_TYPE_P (type)) @@ -6911,9 +6911,13 @@ function_arg_slotno (const struct sparc_args *cum, machine_mode mode, else *ppadding = 0; + /* Skip libcalls. */ + if (!type) + ; + /* Vector types deserve special treatment because they are polymorphic wrt their mode, depending upon whether VIS instructions are enabled. */ - if (type && VECTOR_TYPE_P (type)) + else if (VECTOR_TYPE_P (type)) { if (SCALAR_FLOAT_TYPE_P (TREE_TYPE (type))) { @@ -6934,6 +6938,10 @@ function_arg_slotno (const struct sparc_args *cum, machine_mode mode, } } + /* Structures and unions are handled independently of their mode. */ + else if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE) + mclass = MODE_RANDOM; + switch (mclass) { case MODE_FLOAT: @@ -6968,7 +6976,7 @@ function_arg_slotno (const struct sparc_args *cum, machine_mode mode, if (mode == VOIDmode) return -1; - if (TARGET_64BIT && TARGET_FPU && named + if (TARGET_ARCH64 && TARGET_FPU && named && type && (TREE_CODE (type) == RECORD_TYPE || VECTOR_TYPE_P (type))) { @@ -7409,27 +7417,26 @@ sparc_function_arg_1 (cumulative_args_t cum_v, const function_arg_info &arg, const CUMULATIVE_ARGS *cum = get_cumulative_args (cum_v); const int regbase = incoming ? SPARC_INCOMING_INT_ARG_FIRST : SPARC_OUTGOING_INT_ARG_FIRST; + const tree type = arg.type; + const machine_mode mode = arg.mode; + const enum mode_class mclass = GET_MODE_CLASS (mode); + const bool named = arg.named; int slotno, regno, padding; - tree type = arg.type; - machine_mode mode = arg.mode; - enum mode_class mclass = GET_MODE_CLASS (mode); - bool named = arg.named; slotno = function_arg_slotno (cum, mode, type, named, incoming, ®no, &padding); - if (slotno == -1) - return 0; - /* Integer vectors are handled like floats as per the Sun VIS SDK. */ - if (type && VECTOR_INTEGER_TYPE_P (type)) - mclass = MODE_FLOAT; + /* Return zero if the argument is passed on the stack. */ + if (slotno == -1) + return NULL_RTX; - if (TARGET_ARCH32) + /* In the 32-bit ABI, all arguments use a single register. */ + else if (TARGET_ARCH32) return gen_rtx_REG (mode, regno); /* Structures up to 16 bytes in size are passed in arg slots on the stack and are promoted to registers if possible. */ - if (type && TREE_CODE (type) == RECORD_TYPE) + else if (type && TREE_CODE (type) == RECORD_TYPE) { const int size = int_size_in_bytes (type); gcc_assert (size <= 16); @@ -7455,16 +7462,21 @@ sparc_function_arg_1 (cumulative_args_t cum_v, const function_arg_info &arg, return function_arg_vector_value (size, slotno, named, regno); } - /* v9 fp args in reg slots beyond the int reg slots get passed in regs + /* Integer vectors are handled like floats as per the Sun VIS SDK. + V9 fp args in reg slots beyond the int reg slots get passed in regs but also have the slot allocated for them. If no prototype is in scope fp values in register slots get passed in two places, either fp regs and int regs or fp regs and memory. */ - else if ((mclass == MODE_FLOAT || mclass == MODE_COMPLEX_FLOAT) + else if (((type && VECTOR_INTEGER_TYPE_P (type)) + || mclass == MODE_FLOAT + || mclass == MODE_COMPLEX_FLOAT) && SPARC_FP_REG_P (regno)) { rtx reg = gen_rtx_REG (mode, regno); + if (cum->prototype_p || cum->libcall_p) return reg; + else { rtx v0, v1; @@ -7485,14 +7497,14 @@ sparc_function_arg_1 (cumulative_args_t cum_v, const function_arg_info &arg, v0 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx); v1 = gen_rtx_EXPR_LIST (VOIDmode, gen_rtx_REG (mode, intreg), const0_rtx); - return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1)); } else { v0 = gen_rtx_EXPR_LIST (VOIDmode, NULL_RTX, const0_rtx); v1 = gen_rtx_EXPR_LIST (VOIDmode, reg, const0_rtx); - return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1)); } + + return gen_rtx_PARALLEL (mode, gen_rtvec (2, v0, v1)); } } @@ -7503,10 +7515,14 @@ sparc_function_arg_1 (cumulative_args_t cum_v, const function_arg_info &arg, const int size = int_size_in_bytes (type); gcc_assert (size <= 16); - mode = int_mode_for_size (size * BITS_PER_UNIT, 0).else_blk (); + return + gen_rtx_REG (int_mode_for_size (size * BITS_PER_UNIT, 0).else_blk (), + regno); } - return gen_rtx_REG (mode, regno); + /* All other arguments use a single register. */ + else + return gen_rtx_REG (mode, regno); } /* Handle the TARGET_FUNCTION_ARG target hook. */ @@ -7683,8 +7699,8 @@ sparc_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED) Vector ABI (as implemented by the Sun VIS SDK) says that vector integers are returned like floats of the same size, that is in registers up to 8 bytes and in memory otherwise. Return all - vector floats in memory like structure and unions; note that - they always have BLKmode like the latter. */ + vector floats in memory like structures and unions; note that + they always have BLKmode. */ return (TYPE_MODE (type) == BLKmode || TYPE_MODE (type) == TFmode || (TREE_CODE (type) == VECTOR_TYPE @@ -7701,8 +7717,8 @@ sparc_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED) Vector ABI (as implemented by the Sun VIS SDK) says that vector integers are returned like floats of the same size, that is in - registers. Return all vector floats like structure and unions; - note that they always have BLKmode like the latter. */ + registers. Return all vector floats like structures and unions; + note that they always have BLKmode. */ return (TYPE_MODE (type) == BLKmode && (unsigned HOST_WIDE_INT) int_size_in_bytes (type) > 32); } diff --git a/gcc/testsuite/gcc.target/sparc/small-struct-2.c b/gcc/testsuite/gcc.target/sparc/small-struct-2.c new file mode 100644 index 000000000000..3e8003366eec --- /dev/null +++ b/gcc/testsuite/gcc.target/sparc/small-struct-2.c @@ -0,0 +1,12 @@ +/* PR target/128862 */ + +/* { dg-do compile } */ + +struct S { float f[1]; }; + +void g (int, int, int, int, int, int, struct S); + +void f (struct S s) +{ + g (1, 2, 3, 4, 5, 6, s); +}
