[Bug c/59039] Undocumented __builtin_longjmp/__builtin_setjmp
sandra at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Nov 26 23:49:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59039
sandra at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |sandra at gcc dot gnu.org
--- Comment #30 from sandra at gcc dot gnu.org ---
I've been looking at this issue. The proposed patch has a number of problems,
notably that it uses "@code{setjmp} buffer" to describe the argument that is
*not* the same as the buffer you would pass to the setjmp function. (It's a
different flavor of buffer.)
I'm also thinking that "@code{__builtin_setjmp} and @code{__builtin_longjmp}
may not be used in the same function with the same @code{setjmp} buffer"
doesn't accurately capture the restriction. If builtin_setjmp uses its
containing function's prologue/epilogue to do the register saves and restores
(comment 25), it seems like that also implies that builtin_longjmp can only be
called from functions called directly or indirectly from that containing
function. And indeed, at least on nios2-elf this program wanders off into the
weeds:
#include <stdint.h>
int
my_setjmp (intptr_t *buf)
{
return __builtin_setjmp (buf);
}
void
my_longjmp (intptr_t *buf)
{
__builtin_longjmp (buf, 1);
}
int
main (void)
{
intptr_t buf[5];
int ret;
ret = my_setjmp (buf);
if (ret == 0)
my_longjmp (buf);
return ret;
}
whereas calling __builtin_setjmp directly from main works and returns 1 as
expected.
More information about the Gcc-bugs
mailing list