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

--- Comment #13 from James Clarke <jrtc27 at jrtc27 dot com> ---
(In reply to Eric Botcazou from comment #11)
> > > 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.

That's a bad example; if you change "l0" to "o5", GCC will still let you do it,
and doesn't spill the value anywhere either. GCC assumes if you give a
register, you know that the register really won't be clobbered by any function
calls in between. Yes you might not be aware of the issue with setjmp in this
instance, but that's your problem if you write this code.

> > 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.

Ok, true.

Reply via email to