https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128862

            Bug ID: 128862
           Summary: [sparc64] ICE in function_arg_record_value passing
                    struct { float a[1]; } as 7th argument
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lzy20000419 at outlook dot com
  Target Milestone: ---

Fails with a sparc64-linux-gnu cross trunk build (gcc 17.0.0 20261119,
e632e263a5ca) and with 9.5.0, 10.5.0, 11.5.0 and 12.2.0 through 16.1.0.
Target: sparc64-linux-gnu.

    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);
    }

    sparc64-linux-gnu-gcc -O2 -c t.c

    during RTL pass: expand
    t.c: In function 'f':
    t.c:8:3: internal compiler error: in function_arg_record_value, at
config/sparc/sparc.cc:7293

Expected: successful compilation, with the 7th argument passed on the stack.
Every -O level fails. The callee side (float h (int, int, int, int, int, int,
struct S s) { return s.f[0]; }), struct { double d[1]; } and struct { _Complex
float c[1]; } fail the same way. struct { float f; } and struct { float f[2]; }
work.

Godbolt (16.1.0): https://godbolt.org/z/brnGjM8aj

Cause (config/sparc/sparc.cc): the struct has SFmode, so function_arg_slotno
takes the MODE_FLOAT case. That case only checks the FP slots and accepts slot
6. function_arg_record_value then classifies the fields. On Linux an array
field is not FP-eligible (that needs SUN_V9_ABI_COMPATIBILITY), so the record
needs an integer register. None is left at slot 6, nregs is 0, and gcc_assert
(nregs > 0) fails. The MODE_RANDOM case already returns -1 in this situation
(the PR77759 fix).

Possible fix: in the MODE_FLOAT case of function_arg_slotno, classify a
RECORD_TYPE with traverse_record_type / classify_registers as the MODE_RANDOM
case does, and return -1 when it has no FP field and slotno >=
SPARC_INT_ARG_MAX. With that change on trunk the testcase and the callee-side
testcase compile at -O0 and -O2, a test passing struct { float f[1]; }, struct
{ double d[1]; } and struct { float f[1]; } as 7th to 9th arguments runs
correctly under qemu-sparc64, the arguments use the same stack slots as clang
--target=sparc64-linux-gnu (mixed gcc/clang caller and callee both work), and
the gcc.target/sparc, gcc.dg/compat, gcc.dg/torture and gcc.c-torture/execute
.c files compile to identical -O2 assembly.

Related: PR77759 and PR69072.

Disclaimer: This test case was found with LLM-assisted targeted testing, and
the report was written with LLM assistance.

Reply via email to