From a317c17f5ddfc3f749d349de01eeea5cad3eb162 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 8 Feb 2022 23:36:30 +0100 Subject: compiler: fix incorrect loop break targets When patching jump targets for break statments while compiling for-loop statments, we need jump beyond the instructions popping intermediate loop variables off the stack but before the pop instructions removing local loop body variables to prevent a stack position mismatch between compiler and vm. Before that change, local loop body variables remained on the stack, breaking the expected stack layout. Fixes: b3d758b compiler: ("fix for/break miscompilation") Signed-off-by: Jo-Philipp Wich --- compiler.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'compiler.c') diff --git a/compiler.c b/compiler.c index 3582386..f69ee2d 100644 --- a/compiler.c +++ b/compiler.c @@ -2242,10 +2242,10 @@ uc_compiler_compile_for_in(uc_compiler_t *compiler, bool local, uc_token_t *kvar if (vvar) uc_compiler_emit_insn(compiler, 0, I_POP); - uc_compiler_leave_scope(compiler); - /* patch up break/continue */ uc_compiler_backpatch(compiler, chunk->count, skip_jmp + 5); + + uc_compiler_leave_scope(compiler); } static void @@ -2355,10 +2355,10 @@ uc_compiler_compile_for_count(uc_compiler_t *compiler, bool local, uc_token_t *v if (test_off) uc_compiler_set_jmpaddr(compiler, test_off, chunk->count); - uc_compiler_leave_scope(compiler); - /* patch up break/continue */ uc_compiler_backpatch(compiler, chunk->count, incr_off); + + uc_compiler_leave_scope(compiler); } static void -- cgit v1.2.3