To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

test_exception.rs 20.6 KB
Newer Older
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1
// Copyright 2017 The Australian National University
2
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
3
4
5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
6
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
9
10
11
12
13
14
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15
16
17
extern crate log;
extern crate libloading;

18
19
20
21
22
23
24
use mu::ast::types::*;
use mu::ast::ir::*;
use mu::ast::inst::*;
use mu::ast::op::*;
use mu::vm::*;
use mu::compiler::*;
use mu::utils::LinkedHashMap;
25

qinsoon's avatar
qinsoon committed
26
27
use mu::linkutils;
use mu::linkutils::aot;
28
29

use test_compiler::test_call::gen_ccall_exit;
30
31
32
33

use std::sync::Arc;

#[test]
34
fn test_exception_throw_catch_simple() {
qinsoon's avatar
qinsoon committed
35
    VM::start_logging_trace();
36
    let vm = Arc::new(throw_catch_simple());
37

qinsoon's avatar
qinsoon committed
38
    let compiler = Compiler::new(CompilerPolicy::default(), &vm);
39

40
    let func_throw = vm.id_of("throw_exception");
41
    let func_catch = vm.id_of("catch_exception");
42
43
44
    {
        let funcs = vm.funcs().read().unwrap();
        let func_vers = vm.func_vers().read().unwrap();
45

46
47
        {
            let func = funcs.get(&func_throw).unwrap().read().unwrap();
48
49
50
51
52
53
            let mut func_ver = func_vers
                .get(&func.cur_ver.unwrap())
                .unwrap()
                .write()
                .unwrap();

54
55
56
57
            compiler.compile(&mut func_ver);
        }
        {
            let func = funcs.get(&func_catch).unwrap().read().unwrap();
58
59
60
61
62
63
            let mut func_ver = func_vers
                .get(&func.cur_ver.unwrap())
                .unwrap()
                .write()
                .unwrap();

64
65
66
            compiler.compile(&mut func_ver);
        }
    }
67

qinsoon's avatar
qinsoon committed
68
    vm.set_primordial_thread(func_catch, true, vec![]);
69
    backend::emit_context(&vm);
70
71
72
73

    let executable = aot::link_primordial(
        vec![Mu("throw_exception"), Mu("catch_exception")],
        "throw_catch_simple_test",
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
74
        &vm,
75
    );
qinsoon's avatar
qinsoon committed
76
    linkutils::exec_path(executable);
77
78
}

79
80
81
82
83
84
85
86
87
fn declare_commons(vm: &VM) {
    typedef!    ((vm) int64      = mu_int(64));
    typedef!    ((vm) ref_int64  = mu_ref(int64));
    typedef!    ((vm) iref_int64 = mu_iref(int64));

    constdef!   ((vm) <int64> int64_0 = Constant::Int(0));
    constdef!   ((vm) <int64> int64_1 = Constant::Int(1));
}

88
fn throw_catch_simple() -> VM {
89
    let vm = VM::new();
90

91
    declare_commons(&vm);
92

93
    create_throw_exception_func(&vm);
94
    create_catch_exception_func(&vm, true);
95

96
97
98
    vm
}

99
fn create_catch_exception_func(vm: &VM, use_exception_arg: bool) {
100
101
102
    // .typedef @funcref_throw_exception <@throw_exception_sig>
    let throw_exception_sig = vm.get_func_sig(vm.id_of("throw_exception_sig"));
    let throw_exception_id = vm.id_of("throw_exception");
103
104
105
106
107
108
109

    typedef!        ((vm) funcref_throw_exception = mu_funcref(throw_exception_sig));
    constdef!       ((vm) <funcref_throw_exception> const_funcref_throw_exception = Constant::FuncRef(throw_exception_id));

    funcsig!        ((vm) catch_exception_sig = () -> ());
    funcdecl!       ((vm) <catch_exception_sig> catch_exception);
    funcdef!        ((vm) <catch_exception_sig> catch_exception VERSION catch_exception_v1);
110

111
    // %blk_0():
112
113
114
115
116
117
118
119
120
121
122
123
124
125
    block!          ((vm, catch_exception_v1) blk_0);

    block!          ((vm, catch_exception_v1) blk_normal_cont);
    block!          ((vm, catch_exception_v1) blk_exn_cont);

    consta!         ((vm, catch_exception_v1) const_funcref_throw_exception_local = const_funcref_throw_exception);
    inst!           ((vm, catch_exception_v1) blk_0_term:
        CALL (const_funcref_throw_exception_local) FUNC(0) (vec![]) CallConvention::Mu,
            normal: blk_normal_cont (vec![]),
            exc   : blk_exn_cont    (vec![])
    );

    define_block!   ((vm, catch_exception_v1) blk_0() {
        blk_0_term
126
    });
127

128
    // %blk_normal_cont():
129
130
131
132
133
134
    inst!           ((vm, catch_exception_v1) blk_normal_cont_threadexit:
        THREADEXIT
    );

    define_block!   ((vm, catch_exception_v1) blk_normal_cont() {
        blk_normal_cont_threadexit
135
    });
136

137
    // %blk_exn_cont() %EXN:
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    let ref_int64 = vm.get_type(vm.id_of("ref_int64"));
    ssa!            ((vm, catch_exception_v1) <ref_int64> exn_arg);
    inst!           ((vm, catch_exception_v1) blk_exn_cont_threadexit:
        THREADEXIT
    );

    if use_exception_arg {
        define_block!((vm, catcH_exception_v1) blk_exn_cont() [exn_arg] {
            blk_exn_cont_threadexit
        });
    } else {
        define_block!((vm, catch_exception_v1) blk_exn_cont() {
            blk_exn_cont_threadexit
        });
    }

    define_func_ver!((vm) catch_exception_v1 (entry: blk_0) {
        blk_0, blk_normal_cont, blk_exn_cont
156
157
158
    });
}

159
fn create_throw_exception_func(vm: &VM) {
160
161
162
163
164
165
166
    let int64 = vm.get_type(vm.id_of("int64"));
    let ref_int64 = vm.get_type(vm.id_of("ref_int64"));
    let iref_int64 = vm.get_type(vm.id_of("iref_int64"));

    funcsig!    ((vm) throw_exception_sig = () -> ());
    funcdecl!   ((vm) <throw_exception_sig> throw_exception);
    funcdef!    ((vm) <throw_exception_sig> throw_exception VERSION throw_exception_v1);
167

168
    // %blk_0():
169
    block!      ((vm, throw_exception_v1) blk_0);
170

171
    // %exception_obj = NEW <@int64>
172
173
174
175
176
    ssa!        ((vm, throw_exception_v1) <ref_int64> exception_obj);
    inst!       ((vm, throw_exception_v1) blk_0_new:
        exception_obj = NEW <int64>
    );

177
    // %exception_obj_iref = GETIREF <@int64> %exception_obj
178
179
180
181
    ssa!        ((vm, throw_exception_v1) <iref_int64> exception_obj_iref);
    inst!       ((vm, throw_exception_v1) blk_0_getiref:
        exception_obj_iref = GETIREF exception_obj
    );
182

183
184
    // STORE <@int64> %exception_obj_iref @int64_1
    let const_int64_1 = vm.get_const(vm.id_of("int64_1"));
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
    consta!     ((vm, throw_exception_v1) int64_1_local = const_int64_1);
    inst!       ((vm, throw_exception_v1) blk_0_store:
        STORE exception_obj_iref int64_1_local (is_ptr: false, order: MemoryOrder::Relaxed)
    );

    // THROW exception_obj
    inst!       ((vm, throw_exception_v1) blk_0_throw:
        THROW exception_obj
    );

    define_block!((vm, throw_exception_v1) blk_0() {
        blk_0_new,
        blk_0_getiref,
        blk_0_store,
        blk_0_throw
200
    });
201
202
203

    define_func_ver!((vm) throw_exception_v1(entry: blk_0) {
        blk_0
204
    });
205
}
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

#[test]
fn test_exception_throw_catch_dont_use_exception_arg() {
    VM::start_logging_trace();
    let vm = Arc::new(throw_catch_dont_use_exception_arg());

    let compiler = Compiler::new(CompilerPolicy::default(), &vm);

    let func_throw = vm.id_of("throw_exception");
    let func_catch = vm.id_of("catch_exception");
    {
        let funcs = vm.funcs().read().unwrap();
        let func_vers = vm.func_vers().read().unwrap();

        {
            let func = funcs.get(&func_throw).unwrap().read().unwrap();
222
223
224
225
226
            let mut func_ver = func_vers
                .get(&func.cur_ver.unwrap())
                .unwrap()
                .write()
                .unwrap();
227
228
229
230
231

            compiler.compile(&mut func_ver);
        }
        {
            let func = funcs.get(&func_catch).unwrap().read().unwrap();
232
233
234
235
236
            let mut func_ver = func_vers
                .get(&func.cur_ver.unwrap())
                .unwrap()
                .write()
                .unwrap();
237
238
239
240
241

            compiler.compile(&mut func_ver);
        }
    }

qinsoon's avatar
qinsoon committed
242
    vm.set_primordial_thread(func_catch, true, vec![]);
243
244
    backend::emit_context(&vm);

245
246
247
    let executable = aot::link_primordial(
        vec![Mu("throw_exception"), Mu("catch_exception")],
        "throw_catch_simple_test",
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
248
        &vm,
249
    );
qinsoon's avatar
qinsoon committed
250
    linkutils::exec_path(executable);
251
252
253
254
255
}

fn throw_catch_dont_use_exception_arg() -> VM {
    let vm = VM::new();

256
    declare_commons(&vm);
257
258
259
260
261

    create_throw_exception_func(&vm);
    create_catch_exception_func(&vm, false);

    vm
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
}

#[test]
fn test_exception_throw_catch_and_add() {
    VM::start_logging_trace();
    let vm = Arc::new(throw_catch_and_add());

    let compiler = Compiler::new(CompilerPolicy::default(), &vm);

    let func_throw = vm.id_of("throw_exception");
    let func_catch = vm.id_of("catch_and_add");
    {
        let funcs = vm.funcs().read().unwrap();
        let func_vers = vm.func_vers().read().unwrap();

        {
            let func = funcs.get(&func_throw).unwrap().read().unwrap();
279
280
281
282
283
            let mut func_ver = func_vers
                .get(&func.cur_ver.unwrap())
                .unwrap()
                .write()
                .unwrap();
284
285
286
287
288

            compiler.compile(&mut func_ver);
        }
        {
            let func = funcs.get(&func_catch).unwrap().read().unwrap();
289
290
291
292
293
            let mut func_ver = func_vers
                .get(&func.cur_ver.unwrap())
                .unwrap()
                .write()
                .unwrap();
294
295
296
297
298

            compiler.compile(&mut func_ver);
        }
    }

qinsoon's avatar
qinsoon committed
299
    vm.set_primordial_thread(func_catch, true, vec![]);
300
301
    backend::emit_context(&vm);

302
303
304
    let executable = aot::link_primordial(
        vec![Mu("throw_exception"), Mu("catch_and_add")],
        "throw_catch_and_add",
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
305
        &vm,
306
    );
qinsoon's avatar
qinsoon committed
307
    let output = linkutils::exec_path_nocheck(executable);
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399

    // throw 1, add 0, 1, 2, 3, 4
    assert!(output.status.code().is_some());
    assert_eq!(output.status.code().unwrap(), 11);
}

fn throw_catch_and_add() -> VM {
    let vm = VM::new();

    declare_commons(&vm);

    create_throw_exception_func(&vm);
    create_catch_exception_and_add(&vm);

    vm
}

fn create_catch_exception_and_add(vm: &VM) {
    let throw_exception_sig = vm.get_func_sig(vm.id_of("throw_exception_sig"));
    let throw_exception_id = vm.id_of("throw_exception");

    let int64 = vm.get_type(vm.id_of("int64"));
    constdef!   ((vm) <int64> int64_0 = Constant::Int(0));
    constdef!   ((vm) <int64> int64_1 = Constant::Int(1));
    constdef!   ((vm) <int64> int64_2 = Constant::Int(2));
    constdef!   ((vm) <int64> int64_3 = Constant::Int(3));
    constdef!   ((vm) <int64> int64_4 = Constant::Int(4));
    constdef!   ((vm) <int64> int64_5 = Constant::Int(5));

    typedef!    ((vm) type_funcref_throw_exception  = mu_funcref(throw_exception_sig));
    constdef!   ((vm) <type_funcref_throw_exception> const_funcref_throw_exception = Constant::FuncRef(throw_exception_id));

    funcsig!    ((vm) catch_exception_sig = () -> ());
    funcdecl!   ((vm) <catch_exception_sig> catch_and_add);
    funcdef!    ((vm) <catch_exception_sig> catch_and_add VERSION catch_and_add_v1);

    // blk_entry
    consta!     ((vm, catch_and_add_v1) int0_local = int64_0);
    consta!     ((vm, catch_and_add_v1) int1_local = int64_1);
    consta!     ((vm, catch_and_add_v1) int2_local = int64_2);
    consta!     ((vm, catch_and_add_v1) int3_local = int64_3);
    consta!     ((vm, catch_and_add_v1) int4_local = int64_4);

    block!      ((vm, catch_and_add_v1) blk_entry);
    block!      ((vm, catch_and_add_v1) blk_main);
    inst!       ((vm, catch_and_add_v1) blk_entry_branch:
        BRANCH blk_main (int0_local, int1_local, int2_local, int3_local, int4_local)
    );

    define_block!   ((vm, catch_and_add_v1) blk_entry () {
        blk_entry_branch
    });

    ssa!        ((vm, catch_and_add_v1) <int64> v0);
    ssa!        ((vm, catch_and_add_v1) <int64> v1);
    ssa!        ((vm, catch_and_add_v1) <int64> v2);
    ssa!        ((vm, catch_and_add_v1) <int64> v3);
    ssa!        ((vm, catch_and_add_v1) <int64> v4);

    // blk_main
    consta!     ((vm, catch_and_add_v1) funcref_throw_local = const_funcref_throw_exception);
    block!      ((vm, catch_and_add_v1) blk_normal);
    block!      ((vm, catch_and_add_v1) blk_exception);
    inst!       ((vm, catch_and_add_v1) blk_main_call:
        CALL (funcref_throw_local, v0, v1, v2, v3, v4) FUNC(0) (vec![]) CallConvention::Mu,
            normal: blk_normal (vec![]),
            exc   : blk_exception (vec![
                DestArg::Normal(1),
                DestArg::Normal(2),
                DestArg::Normal(3),
                DestArg::Normal(4),
                DestArg::Normal(5),
            ])
    );
    define_block!   ((vm, catch_and_add_v1) blk_main(v0, v1, v2, v3, v4) {
        blk_main_call
    });

    // blk_normal
    inst!       ((vm, catch_and_add_v1) blk_normal_threadexit:
        THREADEXIT
    );
    define_block!   ((vm, catch_and_add_v1) blk_normal() {
        blk_normal_threadexit
    });

    // blk_exception
    ssa!        ((vm, catch_and_add_v1) <int64> ev0);
    ssa!        ((vm, catch_and_add_v1) <int64> ev1);
    ssa!        ((vm, catch_and_add_v1) <int64> ev2);
    ssa!        ((vm, catch_and_add_v1) <int64> ev3);
    ssa!        ((vm, catch_and_add_v1) <int64> ev4);
400
    let ref_int64 = vm.get_type(vm.id_of("ref_int64"));
401
402
    let iref_int64 = vm.get_type(vm.id_of("iref_int64"));
    ssa!        ((vm, catch_and_add_v1) <ref_int64> exc_arg);
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

    inst!       ((vm, catch_and_add_v1) blk_exception_px0:
        PRINTHEX ev0
    );
    inst!       ((vm, catch_and_add_v1) blk_exception_px1:
        PRINTHEX ev1
    );
    inst!       ((vm, catch_and_add_v1) blk_exception_px2:
        PRINTHEX ev2
    );
    inst!       ((vm, catch_and_add_v1) blk_exception_px3:
        PRINTHEX ev3
    );
    inst!       ((vm, catch_and_add_v1) blk_exception_px4:
        PRINTHEX ev4
    );
419
420
421
422
423
424
425
426
427
    // load and print exc_arg
    ssa!        ((vm, catch_and_add_v1) <iref_int64> exc_iref);
    inst!       ((vm, catch_and_add_v1) blk_exception_getiref:
        exc_iref = GETIREF exc_arg
    );
    ssa!        ((vm, catch_and_add_v1) <int64> exc_val);
    inst!       ((vm, catch_and_add_v1) blk_exception_load_exc:
        exc_val = LOAD exc_iref (is_ptr: false, order: MemoryOrder::SeqCst)
    );
428
    inst!       ((vm, catch_and_add_v1) blk_exception_px5:
429
        PRINTHEX exc_val
430
431
432
433
    );

    ssa!        ((vm, catch_and_add_v1) <int64> res0);
    inst!       ((vm, catch_and_add_v1) blk_exception_add0:
434
        res0 = BINOP (BinOp::Add) exc_val ev0
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
    );

    ssa!        ((vm, catch_and_add_v1) <int64> res1);
    inst!       ((vm, catch_and_add_v1) blk_exception_add1:
        res1 = BINOP (BinOp::Add) res0 ev1
    );

    ssa!        ((vm, catch_and_add_v1) <int64> res2);
    inst!       ((vm, catch_and_add_v1) blk_exception_add2:
        res2 = BINOP (BinOp::Add) res1 ev2
    );

    ssa!        ((vm, catch_and_add_v1) <int64> res3);
    inst!       ((vm, catch_and_add_v1) blk_exception_add3:
        res3 = BINOP (BinOp::Add) res2 ev3
    );

    ssa!        ((vm, catch_and_add_v1) <int64> res4);
    inst!       ((vm, catch_and_add_v1) blk_exception_add4:
        res4 = BINOP (BinOp::Add) res3 ev4
    );

    let blk_exception_exit = gen_ccall_exit(res4.clone(), &mut catch_and_add_v1, &vm);

    inst!       ((vm, catch_and_add_v1) blk_exception_ret:
        RET (res4)
    );

    define_block!   ((vm, catch_and_add_v1) blk_exception(ev0, ev1, ev2, ev3, ev4) [exc_arg] {
        blk_exception_px0,
        blk_exception_px1,
        blk_exception_px2,
        blk_exception_px3,
        blk_exception_px4,
469
470
471

        blk_exception_getiref,
        blk_exception_load_exc,
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
        blk_exception_px5,

        blk_exception_add0,
        blk_exception_add1,
        blk_exception_add2,
        blk_exception_add3,
        blk_exception_add4,

        blk_exception_exit,
        blk_exception_ret
    });

    define_func_ver!((vm) catch_and_add_v1 (entry: blk_entry) {
        blk_entry, blk_main, blk_normal, blk_exception
    });
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
}

#[test]
fn test_exception_throw_catch_twice() {
    VM::start_logging_trace();
    let vm = Arc::new(throw_catch_twice());

    let compiler = Compiler::new(CompilerPolicy::default(), &vm);

    let func_throw = vm.id_of("throw_exception");
    let func_catch = vm.id_of("catch_twice");
    {
        let funcs = vm.funcs().read().unwrap();
        let func_vers = vm.func_vers().read().unwrap();

        {
            let func = funcs.get(&func_throw).unwrap().read().unwrap();
504
505
506
507
508
            let mut func_ver = func_vers
                .get(&func.cur_ver.unwrap())
                .unwrap()
                .write()
                .unwrap();
509
510
511
512
513

            compiler.compile(&mut func_ver);
        }
        {
            let func = funcs.get(&func_catch).unwrap().read().unwrap();
514
515
516
517
518
            let mut func_ver = func_vers
                .get(&func.cur_ver.unwrap())
                .unwrap()
                .write()
                .unwrap();
519
520
521
522
523

            compiler.compile(&mut func_ver);
        }
    }

qinsoon's avatar
qinsoon committed
524
    vm.set_primordial_thread(func_catch, true, vec![]);
525
526
    backend::emit_context(&vm);

527
528
529
    let executable = aot::link_primordial(
        vec![Mu("throw_exception"), Mu("catch_twice")],
        "throw_catch_twice",
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
530
        &vm,
531
    );
qinsoon's avatar
qinsoon committed
532
    let output = linkutils::exec_path_nocheck(executable);
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551

    // throw 1 twice, add 1 and 1 (equals 2)
    assert!(output.status.code().is_some());
    assert_eq!(output.status.code().unwrap(), 2);
}

fn throw_catch_twice() -> VM {
    let vm = VM::new();

    declare_commons(&vm);

    create_throw_exception_func(&vm);
    create_catch_twice(&vm);

    vm
}

fn create_catch_twice(vm: &VM) {
    let throw_exception_sig = vm.get_func_sig(vm.id_of("throw_exception_sig"));
552
    let throw_exception_id = vm.id_of("throw_exception");
553

554
    let ref_int64 = vm.get_type(vm.id_of("ref_int64"));
555
    let iref_int64 = vm.get_type(vm.id_of("iref_int64"));
556
    let int64 = vm.get_type(vm.id_of("int64"));
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649

    typedef!    ((vm) type_funcref_throw_exception = mu_funcref(throw_exception_sig));
    constdef!   ((vm) <type_funcref_throw_exception> const_funcref_throw_exception = Constant::FuncRef(throw_exception_id));

    funcsig!    ((vm) catch_exception_sig = () -> ());
    funcdecl!   ((vm) <catch_exception_sig> catch_twice);
    funcdef!    ((vm) <catch_exception_sig> catch_twice VERSION catch_twice_v1);

    // blk_entry
    block!      ((vm, catch_twice_v1) blk_entry);
    block!      ((vm, catch_twice_v1) blk_normal);
    block!      ((vm, catch_twice_v1) blk_exception1);
    consta!     ((vm, catch_twice_v1) funcref_throw_local = const_funcref_throw_exception);
    inst!       ((vm, catch_twice_v1) blk_entry_call:
        CALL (funcref_throw_local) FUNC(0) (vec![]) CallConvention::Mu,
            normal: blk_normal (vec![]),
            exc   : blk_exception1 (vec![])
    );

    define_block!((vm, catch_twice_v1) blk_entry() {
        blk_entry_call
    });

    // blk_normal
    inst!       ((vm, catch_twice_v1) blk_normal_threadexit:
        THREADEXIT
    );
    define_block!((vm, catch_twice_v1) blk_normal() {
        blk_normal_threadexit
    });

    // blk_exception1
    block!      ((vm, catch_twice_v1) blk_exception2);
    ssa!        ((vm, catch_twice_v1) <ref_int64> exc_arg1);
    inst!       ((vm, catch_twice_v1) blk_exception1_call:
        CALL (funcref_throw_local, exc_arg1) FUNC(0) (vec![]) CallConvention::Mu,
            normal: blk_normal (vec![]),
            exc   : blk_exception2 (vec![DestArg::Normal(1)])
    );
    define_block!((vm, catch_twice_v1) blk_exception1() [exc_arg1] {
        blk_exception1_call
    });

    // blk_exception2
    ssa!        ((vm, catch_twice_v1) <ref_int64> blk_exception2_exc_arg1);
    ssa!        ((vm, catch_twice_v1) <ref_int64> exc_arg2);

    ssa!        ((vm, catch_twice_v1) <iref_int64> blk_exception2_iref_exc1);
    inst!       ((vm, catch_twice_v1) blk_exception2_getiref1:
        blk_exception2_iref_exc1 = GETIREF blk_exception2_exc_arg1
    );
    ssa!        ((vm, catch_twice_v1) <int64> exc_arg1_val);
    inst!       ((vm, catch_twice_v1) blk_exception2_load1:
        exc_arg1_val = LOAD blk_exception2_iref_exc1 (is_ptr: false, order: MemoryOrder::SeqCst)
    );

    ssa!        ((vm, catch_twice_v1) <iref_int64> blk_exception2_iref_exc2);
    inst!       ((vm, catch_twice_v1) blk_exception2_getiref2:
        blk_exception2_iref_exc2 = GETIREF exc_arg2
    );
    ssa!        ((vm, catch_twice_v1) <int64> exc_arg2_val);
    inst!       ((vm, catch_twice_v1) blk_exception2_load2:
        exc_arg2_val = LOAD blk_exception2_iref_exc2 (is_ptr: false, order: MemoryOrder::SeqCst)
    );

    ssa!        ((vm, catch_twice_v1) <int64> res);
    inst!       ((vm, catch_twice_v1) blk_exception2_add:
        res = BINOP (BinOp::Add) exc_arg1_val exc_arg2_val
    );

    let blk_exception2_exit = gen_ccall_exit(res.clone(), &mut catch_twice_v1, &vm);

    inst!       ((vm, catch_twice_v1) blk_exception2_ret:
        RET (res)
    );

    define_block!   ((vm, catch_twice_v1) blk_exception2(blk_exception2_exc_arg1) [exc_arg2] {
        blk_exception2_getiref1,
        blk_exception2_load1,
        blk_exception2_getiref2,
        blk_exception2_load2,

        blk_exception2_add,
        blk_exception2_exit,
        blk_exception2_ret
    });

    define_func_ver!((vm) catch_twice_v1 (entry: blk_entry) {
        blk_entry,
        blk_normal,
        blk_exception1,
        blk_exception2
    });
650
}