[Bug other/59039] Undocumented __builtin_longjmp/__builtin_setjmp

2013-11-07 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59039

--- Comment #1 from Richard Biener rguenth at gcc dot gnu.org ---
__builtin_longjmp/setjmp are just longjmp(3) setjmp(3) with their constraints.
They should not be used directly but setjmp.h should be.

The file looks scary.


[Bug other/59039] Undocumented __builtin_longjmp/__builtin_setjmp

2013-11-07 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59039

--- Comment #2 from Richard Biener rguenth at gcc dot gnu.org ---
I suppose

// alloca() to force generation of frame pointer.  The argument to alloca
// is contrived to prevent the compiler from optimizing it away.  This
// code should never actually be executed.
int* dummy = (int*) alloca((sizeof(int) + (std::size_t) m_start_proc) 
0x1);
*dummy = 0xface;

is optimized away.  Try using volatile int *.


[Bug other/59039] Undocumented __builtin_longjmp/__builtin_setjmp

2013-11-07 Thread hjl.tools at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59039

H.J. Lu hjl.tools at gmail dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2013-11-07
 Ever confirmed|0   |1

--- Comment #3 from H.J. Lu hjl.tools at gmail dot com ---
(In reply to Richard Biener from comment #1)
 __builtin_longjmp/setjmp are just longjmp(3) setjmp(3) with their
 constraints.
 They should not be used directly but setjmp.h should be.

That was my first impression. But I saw

[hjl@gnu-hsw-1 tmp]$ cat y.c
#include setjmp.h

extern jmp_buf buf;

void
foo ()
{
  __builtin_setjmp (buf);
}

void
bar ()
{
  __builtin_longjmp (buf, 1);
}
[hjl@gnu-hsw-1 tmp]$ gcc -S -O2 y.c
[hjl@gnu-hsw-1 tmp]$ cat y.s
.filey.c
.text
.p2align 4,,15
.globlfoo
.typefoo, @function
foo:
.LFB0:
.cfi_startproc
movq%rsp, buf(%rip)
movq$.L2, buf+8(%rip)
movq%rsp, buf+16(%rip)
ret
.L2:
.L4:
.cfi_endproc
.LFE0:
.sizefoo, .-foo
.p2align 4,,15
.globlbar
.typebar, @function
bar:
.LFB1:
.cfi_startproc
pushq%rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movqbuf+8(%rip), %rax
movq%rsp, %rbp
.cfi_def_cfa_register 6
movqbuf(%rip), %rbp
movqbuf+16(%rip), %rsp
jmp*%rax
.cfi_endproc
.LFE1:
.sizebar, .-bar

__builtin_longjmp/setjmp only save/restore BP, SP and PC on
x86, x32 and x86-64.