From 3a9346cb299151cce4d46ebcf20c0f4bb76c697a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 18 Apr 2018 20:55:25 -0700 Subject: compiler: bugfix: miscompiled unwind-protect. * share/txr/stdlib/compiler.tl (compiler comp-unwind-protect): The protected code must terminate with an end instruction. It cannot just branch to the skip label because then we keep executing the following unprotected code still under the unwind protect. How it works is that the protected code ends with end. Then the cleanup fragment at the cleanup offset is executed, also terminating with an end (that one we have in place). We don't need the skip label because the instruction pointer advances after executing the end instruction after the cleanup fragment. --- share/txr/stdlib/compiler.tl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'share') diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 5d68e0f5..1ac0c3af 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -518,8 +518,7 @@ (let* ((treg me.(alloc-treg)) (pfrag me.(compile oreg env prot-form)) (cfrag me.(comp-progn treg env cleanup-body)) - (lclean (gensym "l")) - (lskip (gensym "l"))) + (lclean (gensym "l"))) me.(free-treg treg) (cond ((null pfrag.code) @@ -531,11 +530,10 @@ (t (new (frag pfrag.oreg ^((uwprot ,lclean) ,*pfrag.code - (jmp ,lskip) + (end nil) ,lclean ,*cfrag.code - (end nil) - ,lskip) + (end nil)) (uni pfrag.fvars pfrag.fvars) (uni cfrag.fvars cfrag.fvars)))))))) -- cgit v1.2.3