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

            Bug ID: 99271
           Summary: [10/11 regression] Wrong code for Arm-v8-m.main CMSE
                    calling __gnu_cmse_nonsecure_call
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rearnsha at gcc dot gnu.org
  Target Milestone: ---
            Target: arm

The code fragment:

typedef void (*f)(int) __attribute__((cmse_nonsecure_call));

void bar(f func, int a)
{
  func(a);
}

When compiled with -O2 -mcmse -march=armv8-m.main -mthumb

Incorrectly optimizes the code sequence so that the register used for the
function pointer is not correctly initialized.  The problem was introduced in
r10-6017, so affects gcc-10 and gcc-11.

Current code:

        mov     r3, r0
        mov     r0, r1
        push    {r4, lr}
        lsrs    r3, r3, #1
        lsls    r3, r3, #1
        mov     r1, r3
        mov     r2, r3
        bl      __gnu_cmse_nonsecure_call  // r4 not initialized above.
        pop     {r4, pc}

Correct code

        push    {r4, lr}
        mov     r4, r0
        mov     r0, r1
        lsrs    r4, r4, #1
        lsls    r4, r4, #1
        mov     r1, r4
        mov     r2, r4
        mov     r3, r4
        bl      __gnu_cmse_nonsecure_call // r4 = function with LSB cleared.
        pop     {r4, pc}

Reply via email to