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

--- Comment #11 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> > Again you're wrong, the call-saved registers are properly preserved if you
> > don't clobber the stack pointer, just write a small test or simply tweak
> > yours.
> 
> Yes, I know that.

OK, at least something we agree on. :-)

> But GCC doesn't rely on that for *any other use* of the input and local 
> registers; they are spilled to the stack and reloaded after the setjmp when
> needed.

No, that's also wrong, try:

int main(void)
{
  register int i asm ("l0") = 1;
  setjmp(jb);
  printf("%d\n", i);

  if (c < 10)
    bar();

  return 0;
}

main:
        save    %sp, -176, %sp
        mov     1, %l0
        sethi   %hi(jb), %g1
        or      %g1, %lo(jb), %o0
        call    _setjmp, 0
         nop
        mov     %l0, %g1
        sra     %g1, 0, %g1
        mov     %g1, %o1
        sethi   %hi(.LC0), %g1
        or      %g1, %lo(.LC0), %o0
        call    printf, 0
         nop

GCC really expects all call-saved registers to be preserved.

> Also the fact that alloca clobbers the stack pointer
> is an implementation detail; for example, LLVM allocates all the space up
> front in the function prologue in this case, which means it would not run
> into this issue (and in fact it also spills its PIC base register).

This should also work with libc's alloca and it clobbers the stack pointer.

Reply via email to