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

            Bug ID: 128861
           Summary: [14/15/16/17 Regression] [arm] ICE in
                    arm_expand_prologue with -mcmse -mfloat-abi=hard for a
                    cmse_nonsecure_entry function taking a float HFA
           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 an arm-none-eabi cross trunk build (gcc 17.0.0 20261119,
e632e263a5ca) and with 12.4.0, 12.5.0, 13.3.0, 13.4.0 and 14.1.0 through
16.1.0. 7.5.0, 8.5.0, 9.3.0, 10.5.0, 11.4.0, 12.3.0 and 13.2.0 work.
Target: arm-none-eabi (Cortex-M33 with CMSE and the hard-float ABI).

    struct hfa2 { float a, b; };

    __attribute__ ((cmse_nonsecure_entry)) float
    f (struct hfa2 h)
    {
      return h.a + h.b;
    }

    arm-none-eabi-gcc -O2 -mcpu=cortex-m33 -mthumb -mcmse -mfloat-abi=hard
-mfpu=fpv5-sp-d16 -c t.c

    during RTL pass: pro_and_epilogue
    t.c: In function 'f':
    t.c:7:1: internal compiler error: in arm_expand_prologue, at
config/arm/arm.cc:22705

Expected: successful compilation. 13.2.0 compiles it to vadd.f32 s0, s0, s1
followed by the usual register clearing and bxns. -O0 ICEs too.

Godbolt (trunk): https://godbolt.org/z/r8eW5bEhT

Cause: the PR114837 fix (r14-10122, backported as r13-8647, r12-10394 and
r11-11364) added a loop over the arguments of an entry function to
arm_expand_prologue, and the same loop to thumb1_expand_prologue. The loop
asserts REG_P (arg_rtx) for every argument. Under the hard-float PCS, an HFA
such as struct { float a, b; } is passed as a BLKmode PARALLEL of VFP
registers, so the assert fires. Only integer arguments narrower than 4 bytes
need re-widening.

Possible fix: in both loops, skip an argument whose rtx is not a REG instead of
asserting. With that change on trunk the testcase compiles to the same code as
13.2.0, narrow integer arguments after the HFA (f (struct hfa2, short, unsigned
char)) are still sign- and zero-extended, and the .c files in
gcc.target/arm/cmse compile to identical assembly at -O2 with -mcpu=cortex-m33
(hard, softfp and soft float ABI) and -mcpu=cortex-m23.

The same aggregate also ICEs when it is the return value of an entry function
(cmse_nonsecure_entry_clear_before_return) or an argument of a
cmse_nonsecure_call (cmse_nonsecure_call_inline_register_clear). The
call-argument case ICEs with 7.5.0, 8.5.0, 9.3.0, 10.5.0, 11.4.0, 12.3.0,
13.2.0, 16.1.0 and trunk; the return-value case ICEs with the same versions
except 7.5.0. The change above does not affect them.

Related: PR114837, PR122539 and PR95646.

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

Reply via email to