From b424d30a1b5de1b0a38482624b47ea610c10a12e Mon Sep 17 00:00:00 2001 From: Alasdair Date: Sat, 9 Jun 2018 02:42:19 +0100 Subject: Fix issue with catch block return values not being compiled correctly This should fix the issue raised in commit 45554f Adds a test loop_exception that tests throwing exceptions in loops, various looping constructs, and returning values from try/catch blocks. Also modified the test-suite to test C compiled output both with and without optimisations --- src/c_backend.ml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/c_backend.ml b/src/c_backend.ml index f58093b0..baa6129a 100644 --- a/src/c_backend.ml +++ b/src/c_backend.ml @@ -1586,15 +1586,18 @@ let rec compile_aexp ctx (AE_aux (aexp_aux, env, l)) = in [iblock case_instrs; ilabel try_label] in + assert (ctyp_equal ctyp (ctyp_of_typ typ)); [icomment "begin try catch"; - idecl ctyp try_return_id], - ctyp, - (fun clexp -> itry_block (aexp_setup @ [aexp_call clexp] @ aexp_cleanup)), - [ijump (F_unary ("!", F_have_exception), CT_bool) handled_exception_label] + idecl ctyp try_return_id; + itry_block (aexp_setup @ [aexp_call (CL_id try_return_id)] @ aexp_cleanup); + ijump (F_unary ("!", F_have_exception), CT_bool) handled_exception_label] @ List.concat (List.map compile_case cases) - @ [imatch_failure ()] - @ [ilabel handled_exception_label] - @ [icopy CL_have_exception (F_lit (V_bool false), CT_bool)] + @ [imatch_failure (); + ilabel handled_exception_label; + icopy CL_have_exception (F_lit (V_bool false), CT_bool)], + ctyp, + (fun clexp -> icopy clexp (F_id try_return_id, ctyp)), + [] | AE_if (aval, then_aexp, else_aexp, if_typ) -> let if_ctyp = ctyp_of_typ ctx if_typ in -- cgit v1.2.3