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

--- Comment #17 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #16)
> Patch posted with all of the testcases included:
> https://gcc.gnu.org/pipermail/gcc-patches/2024-April/650080.html

Not nearly enough testcases... What about:

void g(void);
int f(long offset, void *handler)
{
  g();
  if (offset > 5)
    return arr[offset];
  __builtin_eh_return (offset, handler);
}

With -O2 -fomit-frame-pointer:

f:
.LFB0:
        .cfi_startproc
        stp     x30, x0, [sp, -64]!
        .cfi_def_cfa_offset 64
        .cfi_offset 30, -64
        .cfi_offset 0, -56
        stp     x1, x2, [sp, 16]
        stp     x3, x19, [sp, 32]
        .cfi_offset 1, -48
        .cfi_offset 2, -40
        .cfi_offset 3, -32
        .cfi_offset 19, -24
        mov     x19, x0
        str     x20, [sp, 48]
        .cfi_offset 20, -16
        mov     x20, x1
        bl      g
        cmp     x19, 5
        ble     .L8
        mov     w0, w19
        ldp     x19, x20, [sp, 40]
        ldp     x30, x0, [sp], 64    ****** oops
        .cfi_remember_state
        .cfi_restore 0
        .cfi_restore 30
        .cfi_restore 19
        .cfi_restore 20
        .cfi_def_cfa_offset 0
        ret
.L8:
        .cfi_restore_state
        mov     x5, x19
        ldp     x1, x2, [sp, 16]
        mov     x6, x20
        ldp     x3, x19, [sp, 32]
        ldr     x20, [sp, 48]
        ldp     x30, x0, [sp], 64
        .cfi_restore 0
        .cfi_restore 30
        .cfi_restore 20
        .cfi_restore 3
        .cfi_restore 19
        .cfi_restore 1
        .cfi_restore 2
        .cfi_def_cfa_offset 0
        add     sp, sp, x5
        br      x6
        .cfi_endproc

So I don't believe you should change aarch64_pop_regs at all - it's too late to
change things and just adds unnecessary complexity and more bugs. The best
option would be to handle eh_return explicitly and insert the extra push/pops
rather than treating them like a generic callee-save (because clearly they are
not anymore).

Reply via email to