From cfde527ad69eb76204218a3193bb0c534003c7a0 Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Sun, 28 Feb 2021 06:31:00 +0000 Subject: [PATCH] Don't call _setjmp through a function pointer (Bug#46824) This is because _setjmp returns twice; any stack modifications performed after the first return are still visible after the second return, causing havoc. Code like this stack_var = value1; if (_setjmp()) { assert (stack_var == value1); } else { stack_var = value2; longjmp() } will fail. I'm not sure whether the fix will actually avoid the problem given libgccjit's idiosyncracies. --- src/comp.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/comp.c b/src/comp.c index a8b8ef95fa14d..8031f4bd67d56 100644 --- a/src/comp.c +++ b/src/comp.c @@ -1929,8 +1929,18 @@ emit_setjmp (gcc_jit_rvalue *buf) { #ifndef WINDOWSNT gcc_jit_rvalue *args[] = {buf}; - return emit_call (intern_c_string (STR (SETJMP_NAME)), comp.int_type, 1, args, - false); + gcc_jit_param *params[] = { + gcc_jit_context_new_param (comp.ctxt, NULL, comp.void_ptr_type, "buf"), + }; + return gcc_jit_context_new_call (comp.ctxt, + NULL, + gcc_jit_context_new_function + (comp.ctxt, NULL, GCC_JIT_FUNCTION_IMPORTED, + comp.int_type, "_setjmp", + ARRAYELTS (params), params, + false), + 1, + args); #else /* _setjmp (buf, __builtin_frame_address (0)) */ gcc_jit_rvalue *args[2]; -- 2.30.1