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

            Bug ID: 115132
           Summary: Sibling calls optim should not be performed when
                    builtin_unwind_init is used
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: akrl at gcc dot gnu.org
  Target Milestone: ---

Hi all,

In GNU Emacs we use (in order to have all callee saved registers pushed on the
stack before entering in the garbage collector)  '__builtin_unwind_init'.

If sibling calls optimization is performed the call to gc is moved after the
register are popped again making '__builtin_unwind_init' ineffective.

test.c======

void gc ();

void foo (void)
{
  __builtin_unwind_init ();
  gc ();
}
=======

Expected result:

gcc -fno-optimize-sibling-calls -O2 test.c

=======
foo:
        push    rbp
        xor     eax, eax
        mov     rbp, rsp
        push    r15
        push    r14
        push    r13
        push    r12
        push    rbx
        sub     rsp, 8
        call    gc
        add     rsp, 8
        pop     rbx
        pop     r12
        pop     r13
        pop     r14
        pop     r15
        pop     rbp
        ret
========

gcc -02 test.c

========
foo:
        push    rbp
        xor     eax, eax
        mov     rbp, rsp
        push    r15
        push    r14
        push    r13
        push    r12
        push    rbx
        pop     rbx
        pop     r12
        pop     r13
        pop     r14
        pop     r15
        pop     rbp
        jmp     gc
========

I understand '__builtin_unwind_init' it's undocumented and this can be
categorized as a non-bug but AFAIU this optimization makes
'__builtin_unwind_init' unusable for its scope.

Another very possible scenario is that I don't understand correctly how
'__builtin_unwind_init' is supposed to be used.

I see this on trunk but this behavior is present since at least GCC13.

Note: Original Emacs bug <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=63365>

Thanks!

  Andrea

Reply via email to