1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-05 11:40:20 +02:00
guile/tests/jmp0.c
Andy Wingo 35cd7fac8b Fix jmp-shortening on x64 when target within instruction.
* lightening/x86.c (jit_try_shorten): If the address is within the
  last instruction, don't shorten.  If the intstruction is a jump, we
  could elide it entirely in some cases, but we don't know if the user
  captured the PC before calling jit_patch_here.  Better to leave this
  to the user.

Thanks to Helmut Eller for the bug report and test case in
https://gitlab.com/wingo/lightening/-/issues/17.
2021-01-07 11:04:17 +01:00

24 lines
553 B
C

#include "test.h"
static void
run_test(jit_state_t *j, uint8_t *arena_base, size_t arena_size)
{
jit_begin(j, arena_base, arena_size);
size_t align = jit_enter_jit_abi(j, 0, 0, 0);
jit_load_args_1(j, jit_operand_gpr (JIT_OPERAND_ABI_WORD, JIT_R0));
jit_reloc_t r = jit_jmp(j);
jit_patch_here(j, r);
jit_leave_jit_abi(j, 0, 0, align);
jit_retr(j, JIT_R0);
jit_word_t (*f)(jit_word_t) = jit_end(j, NULL);
ASSERT(f(42) == 42);
ASSERT(f(-1) == -1);
}
int
main (int argc, char *argv[])
{
return main_helper(argc, argv, run_test);
}