@@ -452,11 +452,11 @@ fn codegen_msvc_try<'ll>(
452
452
let ( llty, llfn) = get_rust_try_fn ( bx, & mut |mut bx| {
453
453
bx. set_personality_fn ( bx. eh_personality ( ) ) ;
454
454
455
- let mut normal = bx. build_sibling_block ( "normal" ) ;
456
- let mut catchswitch = bx. build_sibling_block ( "catchswitch" ) ;
457
- let mut catchpad_rust = bx. build_sibling_block ( "catchpad_rust" ) ;
458
- let mut catchpad_foreign = bx. build_sibling_block ( "catchpad_foreign" ) ;
459
- let mut caught = bx. build_sibling_block ( "caught" ) ;
455
+ let normal = bx. append_sibling_block ( "normal" ) ;
456
+ let catchswitch = bx. append_sibling_block ( "catchswitch" ) ;
457
+ let catchpad_rust = bx. append_sibling_block ( "catchpad_rust" ) ;
458
+ let catchpad_foreign = bx. append_sibling_block ( "catchpad_foreign" ) ;
459
+ let caught = bx. append_sibling_block ( "caught" ) ;
460
460
461
461
let try_func = llvm:: get_param ( bx. llfn ( ) , 0 ) ;
462
462
let data = llvm:: get_param ( bx. llfn ( ) , 1 ) ;
@@ -520,12 +520,13 @@ fn codegen_msvc_try<'ll>(
520
520
let ptr_align = bx. tcx ( ) . data_layout . pointer_align . abi ;
521
521
let slot = bx. alloca ( bx. type_i8p ( ) , ptr_align) ;
522
522
let try_func_ty = bx. type_func ( & [ bx. type_i8p ( ) ] , bx. type_void ( ) ) ;
523
- bx. invoke ( try_func_ty, try_func, & [ data] , normal. llbb ( ) , catchswitch. llbb ( ) , None ) ;
523
+ bx. invoke ( try_func_ty, try_func, & [ data] , normal, catchswitch, None ) ;
524
524
525
- normal. ret ( bx. const_i32 ( 0 ) ) ;
525
+ bx. switch_to_block ( normal) ;
526
+ bx. ret ( bx. const_i32 ( 0 ) ) ;
526
527
527
- let cs =
528
- catchswitch . catch_switch ( None , None , & [ catchpad_rust. llbb ( ) , catchpad_foreign. llbb ( ) ] ) ;
528
+ bx . switch_to_block ( catchswitch ) ;
529
+ let cs = bx . catch_switch ( None , None , & [ catchpad_rust, catchpad_foreign] ) ;
529
530
530
531
// We can't use the TypeDescriptor defined in libpanic_unwind because it
531
532
// might be in another DLL and the SEH encoding only supports specifying
@@ -558,21 +559,24 @@ fn codegen_msvc_try<'ll>(
558
559
// since our exception object effectively contains a Box.
559
560
//
560
561
// Source: MicrosoftCXXABI::getAddrOfCXXCatchHandlerType in clang
562
+ bx. switch_to_block ( catchpad_rust) ;
561
563
let flags = bx. const_i32 ( 8 ) ;
562
- let funclet = catchpad_rust . catch_pad ( cs, & [ tydesc, flags, slot] ) ;
563
- let ptr = catchpad_rust . load ( bx. type_i8p ( ) , slot, ptr_align) ;
564
+ let funclet = bx . catch_pad ( cs, & [ tydesc, flags, slot] ) ;
565
+ let ptr = bx . load ( bx. type_i8p ( ) , slot, ptr_align) ;
564
566
let catch_ty = bx. type_func ( & [ bx. type_i8p ( ) , bx. type_i8p ( ) ] , bx. type_void ( ) ) ;
565
- catchpad_rust . call ( catch_ty, catch_func, & [ data, ptr] , Some ( & funclet) ) ;
566
- catchpad_rust . catch_ret ( & funclet, caught. llbb ( ) ) ;
567
+ bx . call ( catch_ty, catch_func, & [ data, ptr] , Some ( & funclet) ) ;
568
+ bx . catch_ret ( & funclet, caught) ;
567
569
568
570
// The flag value of 64 indicates a "catch-all".
571
+ bx. switch_to_block ( catchpad_foreign) ;
569
572
let flags = bx. const_i32 ( 64 ) ;
570
573
let null = bx. const_null ( bx. type_i8p ( ) ) ;
571
- let funclet = catchpad_foreign . catch_pad ( cs, & [ null, flags, null] ) ;
572
- catchpad_foreign . call ( catch_ty, catch_func, & [ data, null] , Some ( & funclet) ) ;
573
- catchpad_foreign . catch_ret ( & funclet, caught. llbb ( ) ) ;
574
+ let funclet = bx . catch_pad ( cs, & [ null, flags, null] ) ;
575
+ bx . call ( catch_ty, catch_func, & [ data, null] , Some ( & funclet) ) ;
576
+ bx . catch_ret ( & funclet, caught) ;
574
577
575
- caught. ret ( bx. const_i32 ( 1 ) ) ;
578
+ bx. switch_to_block ( caught) ;
579
+ bx. ret ( bx. const_i32 ( 1 ) ) ;
576
580
} ) ;
577
581
578
582
// Note that no invoke is used here because by definition this function
@@ -613,30 +617,33 @@ fn codegen_gnu_try<'ll>(
613
617
// (%ptr, _) = landingpad
614
618
// call %catch_func(%data, %ptr)
615
619
// ret 1
616
- let mut then = bx. build_sibling_block ( "then" ) ;
617
- let mut catch = bx. build_sibling_block ( "catch" ) ;
620
+ let then = bx. append_sibling_block ( "then" ) ;
621
+ let catch = bx. append_sibling_block ( "catch" ) ;
618
622
619
623
let try_func = llvm:: get_param ( bx. llfn ( ) , 0 ) ;
620
624
let data = llvm:: get_param ( bx. llfn ( ) , 1 ) ;
621
625
let catch_func = llvm:: get_param ( bx. llfn ( ) , 2 ) ;
622
626
let try_func_ty = bx. type_func ( & [ bx. type_i8p ( ) ] , bx. type_void ( ) ) ;
623
- bx. invoke ( try_func_ty, try_func, & [ data] , then. llbb ( ) , catch. llbb ( ) , None ) ;
624
- then. ret ( bx. const_i32 ( 0 ) ) ;
627
+ bx. invoke ( try_func_ty, try_func, & [ data] , then, catch, None ) ;
628
+
629
+ bx. switch_to_block ( then) ;
630
+ bx. ret ( bx. const_i32 ( 0 ) ) ;
625
631
626
632
// Type indicator for the exception being thrown.
627
633
//
628
634
// The first value in this tuple is a pointer to the exception object
629
635
// being thrown. The second value is a "selector" indicating which of
630
636
// the landing pad clauses the exception's type had been matched to.
631
637
// rust_try ignores the selector.
638
+ bx. switch_to_block ( catch) ;
632
639
let lpad_ty = bx. type_struct ( & [ bx. type_i8p ( ) , bx. type_i32 ( ) ] , false ) ;
633
- let vals = catch . landing_pad ( lpad_ty, bx. eh_personality ( ) , 1 ) ;
640
+ let vals = bx . landing_pad ( lpad_ty, bx. eh_personality ( ) , 1 ) ;
634
641
let tydesc = bx. const_null ( bx. type_i8p ( ) ) ;
635
- catch . add_clause ( vals, tydesc) ;
636
- let ptr = catch . extract_value ( vals, 0 ) ;
642
+ bx . add_clause ( vals, tydesc) ;
643
+ let ptr = bx . extract_value ( vals, 0 ) ;
637
644
let catch_ty = bx. type_func ( & [ bx. type_i8p ( ) , bx. type_i8p ( ) ] , bx. type_void ( ) ) ;
638
- catch . call ( catch_ty, catch_func, & [ data, ptr] , None ) ;
639
- catch . ret ( bx. const_i32 ( 1 ) ) ;
645
+ bx . call ( catch_ty, catch_func, & [ data, ptr] , None ) ;
646
+ bx . ret ( bx. const_i32 ( 1 ) ) ;
640
647
} ) ;
641
648
642
649
// Note that no invoke is used here because by definition this function
@@ -674,57 +681,54 @@ fn codegen_emcc_try<'ll>(
674
681
// %catch_data[1] = %is_rust_panic
675
682
// call %catch_func(%data, %catch_data)
676
683
// ret 1
677
- let mut then = bx. build_sibling_block ( "then" ) ;
678
- let mut catch = bx. build_sibling_block ( "catch" ) ;
684
+ let then = bx. append_sibling_block ( "then" ) ;
685
+ let catch = bx. append_sibling_block ( "catch" ) ;
679
686
680
687
let try_func = llvm:: get_param ( bx. llfn ( ) , 0 ) ;
681
688
let data = llvm:: get_param ( bx. llfn ( ) , 1 ) ;
682
689
let catch_func = llvm:: get_param ( bx. llfn ( ) , 2 ) ;
683
690
let try_func_ty = bx. type_func ( & [ bx. type_i8p ( ) ] , bx. type_void ( ) ) ;
684
- bx. invoke ( try_func_ty, try_func, & [ data] , then. llbb ( ) , catch. llbb ( ) , None ) ;
685
- then. ret ( bx. const_i32 ( 0 ) ) ;
691
+ bx. invoke ( try_func_ty, try_func, & [ data] , then, catch, None ) ;
692
+
693
+ bx. switch_to_block ( then) ;
694
+ bx. ret ( bx. const_i32 ( 0 ) ) ;
686
695
687
696
// Type indicator for the exception being thrown.
688
697
//
689
698
// The first value in this tuple is a pointer to the exception object
690
699
// being thrown. The second value is a "selector" indicating which of
691
700
// the landing pad clauses the exception's type had been matched to.
701
+ bx. switch_to_block ( catch) ;
692
702
let tydesc = bx. eh_catch_typeinfo ( ) ;
693
703
let lpad_ty = bx. type_struct ( & [ bx. type_i8p ( ) , bx. type_i32 ( ) ] , false ) ;
694
- let vals = catch . landing_pad ( lpad_ty, bx. eh_personality ( ) , 2 ) ;
695
- catch . add_clause ( vals, tydesc) ;
696
- catch . add_clause ( vals, bx. const_null ( bx. type_i8p ( ) ) ) ;
697
- let ptr = catch . extract_value ( vals, 0 ) ;
698
- let selector = catch . extract_value ( vals, 1 ) ;
704
+ let vals = bx . landing_pad ( lpad_ty, bx. eh_personality ( ) , 2 ) ;
705
+ bx . add_clause ( vals, tydesc) ;
706
+ bx . add_clause ( vals, bx. const_null ( bx. type_i8p ( ) ) ) ;
707
+ let ptr = bx . extract_value ( vals, 0 ) ;
708
+ let selector = bx . extract_value ( vals, 1 ) ;
699
709
700
710
// Check if the typeid we got is the one for a Rust panic.
701
- let rust_typeid = catch . call_intrinsic ( "llvm.eh.typeid.for" , & [ tydesc] ) ;
702
- let is_rust_panic = catch . icmp ( IntPredicate :: IntEQ , selector, rust_typeid) ;
703
- let is_rust_panic = catch . zext ( is_rust_panic, bx. type_bool ( ) ) ;
711
+ let rust_typeid = bx . call_intrinsic ( "llvm.eh.typeid.for" , & [ tydesc] ) ;
712
+ let is_rust_panic = bx . icmp ( IntPredicate :: IntEQ , selector, rust_typeid) ;
713
+ let is_rust_panic = bx . zext ( is_rust_panic, bx. type_bool ( ) ) ;
704
714
705
715
// We need to pass two values to catch_func (ptr and is_rust_panic), so
706
716
// create an alloca and pass a pointer to that.
707
717
let ptr_align = bx. tcx ( ) . data_layout . pointer_align . abi ;
708
718
let i8_align = bx. tcx ( ) . data_layout . i8_align . abi ;
709
719
let catch_data_type = bx. type_struct ( & [ bx. type_i8p ( ) , bx. type_bool ( ) ] , false ) ;
710
- let catch_data = catch. alloca ( catch_data_type, ptr_align) ;
711
- let catch_data_0 = catch. inbounds_gep (
712
- catch_data_type,
713
- catch_data,
714
- & [ bx. const_usize ( 0 ) , bx. const_usize ( 0 ) ] ,
715
- ) ;
716
- catch. store ( ptr, catch_data_0, ptr_align) ;
717
- let catch_data_1 = catch. inbounds_gep (
718
- catch_data_type,
719
- catch_data,
720
- & [ bx. const_usize ( 0 ) , bx. const_usize ( 1 ) ] ,
721
- ) ;
722
- catch. store ( is_rust_panic, catch_data_1, i8_align) ;
723
- let catch_data = catch. bitcast ( catch_data, bx. type_i8p ( ) ) ;
720
+ let catch_data = bx. alloca ( catch_data_type, ptr_align) ;
721
+ let catch_data_0 =
722
+ bx. inbounds_gep ( catch_data_type, catch_data, & [ bx. const_usize ( 0 ) , bx. const_usize ( 0 ) ] ) ;
723
+ bx. store ( ptr, catch_data_0, ptr_align) ;
724
+ let catch_data_1 =
725
+ bx. inbounds_gep ( catch_data_type, catch_data, & [ bx. const_usize ( 0 ) , bx. const_usize ( 1 ) ] ) ;
726
+ bx. store ( is_rust_panic, catch_data_1, i8_align) ;
727
+ let catch_data = bx. bitcast ( catch_data, bx. type_i8p ( ) ) ;
724
728
725
729
let catch_ty = bx. type_func ( & [ bx. type_i8p ( ) , bx. type_i8p ( ) ] , bx. type_void ( ) ) ;
726
- catch . call ( catch_ty, catch_func, & [ data, catch_data] , None ) ;
727
- catch . ret ( bx. const_i32 ( 1 ) ) ;
730
+ bx . call ( catch_ty, catch_func, & [ data, catch_data] , None ) ;
731
+ bx . ret ( bx. const_i32 ( 1 ) ) ;
728
732
} ) ;
729
733
730
734
// Note that no invoke is used here because by definition this function
0 commit comments