From bfb7b491cc13776cc4b44671d1605f8fb1da7514 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 26 Jul 2020 11:45:24 +0900 Subject: Restore the variable `pc` after `longjmp()` Changes made after `setjmp()` are destroyed and need reassignment. This problem is now caused by the addition of the `OP_JUW` instruction. When actually building on FreeBSD 12.1 with `clang10 -fsanitize=address`, mrbtest "NameError#name [15.2.31.2.1]" is failed. However, qualifying `pc` with `volatile` slows down significantly and increases the object code. Suppress them by qualifying only the variables that restore `pc`. --- src/vm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/vm.c b/src/vm.c index cc6f087f9..42280f0a1 100644 --- a/src/vm.c +++ b/src/vm.c @@ -966,7 +966,7 @@ prepare_tagged_break(mrb_state *mrb, uint32_t tag, struct RProc *proc, mrb_value #ifndef DIRECT_THREADED #define INIT_DISPATCH for (;;) { insn = BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); switch (insn) { -#define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops (); +#define CASE(insn,ops) case insn: pc0=pc++; FETCH_ ## ops (); pc_save = pc; #define NEXT break #define JUMP NEXT #define END_DISPATCH }} @@ -974,7 +974,7 @@ prepare_tagged_break(mrb_state *mrb, uint32_t tag, struct RProc *proc, mrb_value #else #define INIT_DISPATCH JUMP; return mrb_nil_value(); -#define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops (); +#define CASE(insn,ops) L_ ## insn: pc0=pc++; FETCH_ ## ops (); pc_save = pc; #define NEXT insn=BYTECODE_DECODER(*pc); CODE_FETCH_HOOK(mrb, irep, pc, regs); goto *optable[insn] #define JUMP NEXT @@ -1030,6 +1030,7 @@ mrb_vm_exec(mrb_state *mrb, const struct RProc *proc, const mrb_code *pc) { /* mrb_assert(MRB_PROC_CFUNC_P(proc)) */ const mrb_code *pc0 = pc; + const mrb_code *volatile pc_save = pc; const mrb_irep *irep = proc->body.irep; const mrb_pool_value *pool = irep->pool; const mrb_sym *syms = irep->syms; @@ -2834,6 +2835,7 @@ RETRY_TRY_BLOCK: ci = cipop(mrb); } exc_catched = TRUE; + pc = pc_save; goto RETRY_TRY_BLOCK; } MRB_END_EXC(&c_jmp); -- cgit v1.2.3