Skip to content

Commit 546f323

Browse files
committed
Effects: test miscompilation of exception handlers
1 parent c4aed13 commit 546f323

File tree

1 file changed

+56
-18
lines changed

1 file changed

+56
-18
lines changed

compiler/tests-compiler/effects_exceptions.ml

Lines changed: 56 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
3636
Some (open_in "toto", n, m)
3737
with Not_found ->
3838
None
39+
40+
let handler_is_loop f g l =
41+
try f ()
42+
with exn ->
43+
let rec loop l =
44+
match g l with
45+
| `Fallback l' -> loop l'
46+
| `Raise exn -> raise exn
47+
in
48+
loop l
49+
50+
let handler_is_merge_node g =
51+
let s = try g () with _ -> "" in
52+
s ^ "aaa"
3953
|}
4054
in
4155
print_fun_decl code (Some "exceptions");
@@ -44,27 +58,51 @@ let%expect_test "test-compiler/lib-effects/test1.ml" =
4458

4559
function exceptions(s,cont)
4660
{try
47-
{var _h_=runtime.caml_int_of_string(s),n=_h_}
48-
catch(_l_)
49-
{var _a_=caml_wrap_exception(_l_);
50-
if(_a_[1] !== Stdlib[7]){var raise$1=caml_pop_trap();return raise$1(_a_)}
51-
var n=0,_b_=0}
61+
{var _n_=runtime.caml_int_of_string(s),n=_n_}
62+
catch(_r_)
63+
{var _g_=caml_wrap_exception(_r_);
64+
if(_g_[1] !== Stdlib[7]){var raise$1=caml_pop_trap();return raise$1(_g_)}
65+
var n=0,_h_=0}
5266
try
53-
{if(caml_string_equal(s,cst$0))throw Stdlib[8];var _g_=7,m=_g_}
54-
catch(_k_)
55-
{var _c_=caml_wrap_exception(_k_);
56-
if(_c_ !== Stdlib[8]){var raise$0=caml_pop_trap();return raise$0(_c_)}
57-
var m=0,_d_=0}
58-
runtime.caml_push_trap
59-
(function(_j_)
60-
{if(_j_ === Stdlib[8])return cont(0);
67+
{if(caml_string_equal(s,cst$0))throw Stdlib[8];var _m_=7,m=_m_}
68+
catch(_q_)
69+
{var _i_=caml_wrap_exception(_q_);
70+
if(_i_ !== Stdlib[8]){var raise$0=caml_pop_trap();return raise$0(_i_)}
71+
var m=0,_j_=0}
72+
caml_push_trap
73+
(function(_p_)
74+
{if(_p_ === Stdlib[8])return cont(0);
6175
var raise=caml_pop_trap();
62-
return raise(_j_)});
76+
return raise(_p_)});
6377
if(caml_string_equal(s,cst))
64-
{var _e_=Stdlib[8],raise=caml_pop_trap();return raise(_e_)}
65-
var _f_=Stdlib[79];
78+
{var _k_=Stdlib[8],raise=caml_pop_trap();return raise(_k_)}
79+
var _l_=Stdlib[79];
6680
return caml_cps_call2
67-
(_f_,
81+
(_l_,
6882
cst_toto,
69-
function(_i_){caml_pop_trap();return cont([0,[0,_i_,n,m]])})}
83+
function(_o_){caml_pop_trap();return cont([0,[0,_o_,n,m]])})}
84+
//end |}];
85+
print_fun_decl code (Some "handler_is_loop");
86+
[%expect {|
87+
function handler_is_loop(f,g,l,cont)
88+
{function _e_(l)
89+
{return caml_cps_call2
90+
(g,
91+
l,
92+
function(match)
93+
{if(72330306 <= match[1])
94+
{var l=match[2];return caml_cps_exact_call1(_e_,l)}
95+
var exn=match[2],raise=caml_pop_trap();
96+
return raise(exn)})}
97+
caml_push_trap(_e_);
98+
var _d_=0;
99+
return caml_cps_call2(f,_d_,function(_f_){caml_pop_trap();return cont(_f_)})}
100+
//end |}];
101+
print_fun_decl code (Some "handler_is_merge_node");
102+
[%expect {|
103+
function handler_is_merge_node(g,cont)
104+
{function _b_(s){return caml_cps_call3(Stdlib[28],s,cst_aaa,cont)}
105+
caml_push_trap(_b_);
106+
var _a_=0;
107+
return caml_cps_call2(g,_a_,function(_c_){caml_pop_trap();return _b_(_c_)})}
70108
//end |}]

0 commit comments

Comments
 (0)