@@ -405,13 +405,15 @@ fn codegen_msvc_try(
405
405
dest : & ' ll Value ,
406
406
) {
407
407
let llfn = get_rust_try_fn ( bx, & mut |mut bx| {
408
+ let cx = bx. cx ;
409
+
408
410
bx. set_personality_fn ( bx. eh_personality ( ) ) ;
409
411
410
- let mut normal = bx. build_sibling_block ( "normal" ) ;
411
- let mut catchswitch = bx. build_sibling_block ( "catchswitch" ) ;
412
+ let normal = bx. build_sibling_block ( "normal" ) ;
413
+ let catchswitch = bx. build_sibling_block ( "catchswitch" ) ;
412
414
let mut catchpad_rust = bx. build_sibling_block ( "catchpad_rust" ) ;
413
415
let mut catchpad_foreign = bx. build_sibling_block ( "catchpad_foreign" ) ;
414
- let mut caught = bx. build_sibling_block ( "caught" ) ;
416
+ let caught = bx. build_sibling_block ( "caught" ) ;
415
417
416
418
let try_func = llvm:: get_param ( bx. llfn ( ) , 0 ) ;
417
419
let data = llvm:: get_param ( bx. llfn ( ) , 1 ) ;
@@ -476,9 +478,9 @@ fn codegen_msvc_try(
476
478
let slot = bx. alloca ( bx. type_i8p ( ) , ptr_align) ;
477
479
bx. invoke ( try_func, & [ data] , normal. llbb ( ) , catchswitch. llbb ( ) , None , None ) ;
478
480
479
- normal. ret ( bx . const_i32 ( 0 ) ) ;
481
+ normal. ret ( cx . const_i32 ( 0 ) ) ;
480
482
481
- let cs =
483
+ let ( _ , cs ) =
482
484
catchswitch. catch_switch ( None , None , & [ catchpad_rust. llbb ( ) , catchpad_foreign. llbb ( ) ] ) ;
483
485
484
486
// We can't use the TypeDescriptor defined in libpanic_unwind because it
@@ -495,14 +497,14 @@ fn codegen_msvc_try(
495
497
//
496
498
// When modifying, make sure that the type_name string exactly matches
497
499
// the one used in src/libpanic_unwind/seh.rs.
498
- let type_info_vtable = bx . declare_global ( "??_7type_info@@6B@" , bx . type_i8p ( ) ) ;
499
- let type_name = bx . const_bytes ( b"rust_panic\0 " ) ;
500
+ let type_info_vtable = cx . declare_global ( "??_7type_info@@6B@" , cx . type_i8p ( ) ) ;
501
+ let type_name = cx . const_bytes ( b"rust_panic\0 " ) ;
500
502
let type_info =
501
- bx . const_struct ( & [ type_info_vtable, bx . const_null ( bx . type_i8p ( ) ) , type_name] , false ) ;
502
- let tydesc = bx . declare_global ( "__rust_panic_type_info" , bx . val_ty ( type_info) ) ;
503
+ cx . const_struct ( & [ type_info_vtable, cx . const_null ( cx . type_i8p ( ) ) , type_name] , false ) ;
504
+ let tydesc = cx . declare_global ( "__rust_panic_type_info" , cx . val_ty ( type_info) ) ;
503
505
unsafe {
504
506
llvm:: LLVMRustSetLinkage ( tydesc, llvm:: Linkage :: LinkOnceODRLinkage ) ;
505
- llvm:: SetUniqueComdat ( bx . llmod , tydesc) ;
507
+ llvm:: SetUniqueComdat ( cx . llmod , tydesc) ;
506
508
llvm:: LLVMSetInitializer ( tydesc, type_info) ;
507
509
}
508
510
@@ -512,20 +514,20 @@ fn codegen_msvc_try(
512
514
// since our exception object effectively contains a Box.
513
515
//
514
516
// Source: MicrosoftCXXABI::getAddrOfCXXCatchHandlerType in clang
515
- let flags = bx . const_i32 ( 8 ) ;
517
+ let flags = cx . const_i32 ( 8 ) ;
516
518
let funclet = catchpad_rust. catch_pad ( cs, & [ tydesc, flags, slot] ) ;
517
519
let ptr = catchpad_rust. load ( slot, ptr_align) ;
518
520
catchpad_rust. call ( catch_func, & [ data, ptr] , Some ( & funclet) , None ) ;
519
521
catchpad_rust. catch_ret ( & funclet, caught. llbb ( ) ) ;
520
522
521
523
// The flag value of 64 indicates a "catch-all".
522
- let flags = bx . const_i32 ( 64 ) ;
523
- let null = bx . const_null ( bx . type_i8p ( ) ) ;
524
+ let flags = cx . const_i32 ( 64 ) ;
525
+ let null = cx . const_null ( cx . type_i8p ( ) ) ;
524
526
let funclet = catchpad_foreign. catch_pad ( cs, & [ null, flags, null] ) ;
525
527
catchpad_foreign. call ( catch_func, & [ data, null] , Some ( & funclet) , None ) ;
526
528
catchpad_foreign. catch_ret ( & funclet, caught. llbb ( ) ) ;
527
529
528
- caught. ret ( bx . const_i32 ( 1 ) ) ;
530
+ caught. ret ( cx . const_i32 ( 1 ) ) ;
529
531
} ) ;
530
532
531
533
// Note that no invoke is used here because by definition this function
@@ -553,7 +555,9 @@ fn codegen_gnu_try(
553
555
catch_func : & ' ll Value ,
554
556
dest : & ' ll Value ,
555
557
) {
556
- let llfn = get_rust_try_fn ( bx, & mut |mut bx| {
558
+ let llfn = get_rust_try_fn ( bx, & mut |bx| {
559
+ let cx = bx. cx ;
560
+
557
561
// Codegens the shims described above:
558
562
//
559
563
// bx:
@@ -566,28 +570,28 @@ fn codegen_gnu_try(
566
570
// (%ptr, _) = landingpad
567
571
// call %catch_func(%data, %ptr)
568
572
// ret 1
569
- let mut then = bx. build_sibling_block ( "then" ) ;
573
+ let then = bx. build_sibling_block ( "then" ) ;
570
574
let mut catch = bx. build_sibling_block ( "catch" ) ;
571
575
572
576
let try_func = llvm:: get_param ( bx. llfn ( ) , 0 ) ;
573
577
let data = llvm:: get_param ( bx. llfn ( ) , 1 ) ;
574
578
let catch_func = llvm:: get_param ( bx. llfn ( ) , 2 ) ;
575
579
bx. invoke ( try_func, & [ data] , then. llbb ( ) , catch. llbb ( ) , None , None ) ;
576
- then. ret ( bx . const_i32 ( 0 ) ) ;
580
+ then. ret ( cx . const_i32 ( 0 ) ) ;
577
581
578
582
// Type indicator for the exception being thrown.
579
583
//
580
584
// The first value in this tuple is a pointer to the exception object
581
585
// being thrown. The second value is a "selector" indicating which of
582
586
// the landing pad clauses the exception's type had been matched to.
583
587
// rust_try ignores the selector.
584
- let lpad_ty = bx . type_struct ( & [ bx . type_i8p ( ) , bx . type_i32 ( ) ] , false ) ;
585
- let vals = catch. landing_pad ( lpad_ty, bx . eh_personality ( ) , 1 ) ;
586
- let tydesc = bx . const_null ( bx . type_i8p ( ) ) ;
588
+ let lpad_ty = cx . type_struct ( & [ cx . type_i8p ( ) , cx . type_i32 ( ) ] , false ) ;
589
+ let vals = catch. landing_pad ( lpad_ty, cx . eh_personality ( ) , 1 ) ;
590
+ let tydesc = cx . const_null ( cx . type_i8p ( ) ) ;
587
591
catch. add_clause ( vals, tydesc) ;
588
592
let ptr = catch. extract_value ( vals, 0 ) ;
589
593
catch. call ( catch_func, & [ data, ptr] , None , None ) ;
590
- catch. ret ( bx . const_i32 ( 1 ) ) ;
594
+ catch. ret ( cx . const_i32 ( 1 ) ) ;
591
595
} ) ;
592
596
593
597
// Note that no invoke is used here because by definition this function
@@ -607,7 +611,9 @@ fn codegen_emcc_try(
607
611
catch_func : & ' ll Value ,
608
612
dest : & ' ll Value ,
609
613
) {
610
- let llfn = get_rust_try_fn ( bx, & mut |mut bx| {
614
+ let llfn = get_rust_try_fn ( bx, & mut |bx| {
615
+ let cx = bx. cx ;
616
+
611
617
// Codegens the shims described above:
612
618
//
613
619
// bx:
@@ -625,48 +631,48 @@ fn codegen_emcc_try(
625
631
// %catch_data[1] = %is_rust_panic
626
632
// call %catch_func(%data, %catch_data)
627
633
// ret 1
628
- let mut then = bx. build_sibling_block ( "then" ) ;
634
+ let then = bx. build_sibling_block ( "then" ) ;
629
635
let mut catch = bx. build_sibling_block ( "catch" ) ;
630
636
631
637
let try_func = llvm:: get_param ( bx. llfn ( ) , 0 ) ;
632
638
let data = llvm:: get_param ( bx. llfn ( ) , 1 ) ;
633
639
let catch_func = llvm:: get_param ( bx. llfn ( ) , 2 ) ;
634
640
bx. invoke ( try_func, & [ data] , then. llbb ( ) , catch. llbb ( ) , None , None ) ;
635
- then. ret ( bx . const_i32 ( 0 ) ) ;
641
+ then. ret ( cx . const_i32 ( 0 ) ) ;
636
642
637
643
// Type indicator for the exception being thrown.
638
644
//
639
645
// The first value in this tuple is a pointer to the exception object
640
646
// being thrown. The second value is a "selector" indicating which of
641
647
// the landing pad clauses the exception's type had been matched to.
642
- let tydesc = bx . eh_catch_typeinfo ( ) ;
643
- let lpad_ty = bx . type_struct ( & [ bx . type_i8p ( ) , bx . type_i32 ( ) ] , false ) ;
644
- let vals = catch. landing_pad ( lpad_ty, bx . eh_personality ( ) , 2 ) ;
648
+ let tydesc = cx . eh_catch_typeinfo ( ) ;
649
+ let lpad_ty = cx . type_struct ( & [ cx . type_i8p ( ) , cx . type_i32 ( ) ] , false ) ;
650
+ let vals = catch. landing_pad ( lpad_ty, cx . eh_personality ( ) , 2 ) ;
645
651
catch. add_clause ( vals, tydesc) ;
646
- catch. add_clause ( vals, bx . const_null ( bx . type_i8p ( ) ) ) ;
652
+ catch. add_clause ( vals, cx . const_null ( cx . type_i8p ( ) ) ) ;
647
653
let ptr = catch. extract_value ( vals, 0 ) ;
648
654
let selector = catch. extract_value ( vals, 1 ) ;
649
655
650
656
// Check if the typeid we got is the one for a Rust panic.
651
- let llvm_eh_typeid_for = bx . get_intrinsic ( "llvm.eh.typeid.for" ) ;
657
+ let llvm_eh_typeid_for = cx . get_intrinsic ( "llvm.eh.typeid.for" ) ;
652
658
let rust_typeid = catch. call ( llvm_eh_typeid_for, & [ tydesc] , None , None ) ;
653
659
let is_rust_panic = catch. icmp ( IntPredicate :: IntEQ , selector, rust_typeid) ;
654
- let is_rust_panic = catch. zext ( is_rust_panic, bx . type_bool ( ) ) ;
660
+ let is_rust_panic = catch. zext ( is_rust_panic, cx . type_bool ( ) ) ;
655
661
656
662
// We need to pass two values to catch_func (ptr and is_rust_panic), so
657
663
// create an alloca and pass a pointer to that.
658
- let ptr_align = bx . tcx ( ) . data_layout . pointer_align . abi ;
659
- let i8_align = bx . tcx ( ) . data_layout . i8_align . abi ;
664
+ let ptr_align = cx . tcx . data_layout . pointer_align . abi ;
665
+ let i8_align = cx . tcx . data_layout . i8_align . abi ;
660
666
let catch_data =
661
- catch. alloca ( bx . type_struct ( & [ bx . type_i8p ( ) , bx . type_bool ( ) ] , false ) , ptr_align) ;
662
- let catch_data_0 = catch. inbounds_gep ( catch_data, & [ bx . const_usize ( 0 ) , bx . const_usize ( 0 ) ] ) ;
667
+ catch. alloca ( cx . type_struct ( & [ cx . type_i8p ( ) , cx . type_bool ( ) ] , false ) , ptr_align) ;
668
+ let catch_data_0 = catch. inbounds_gep ( catch_data, & [ cx . const_usize ( 0 ) , cx . const_usize ( 0 ) ] ) ;
663
669
catch. store ( ptr, catch_data_0, ptr_align) ;
664
- let catch_data_1 = catch. inbounds_gep ( catch_data, & [ bx . const_usize ( 0 ) , bx . const_usize ( 1 ) ] ) ;
670
+ let catch_data_1 = catch. inbounds_gep ( catch_data, & [ cx . const_usize ( 0 ) , cx . const_usize ( 1 ) ] ) ;
665
671
catch. store ( is_rust_panic, catch_data_1, i8_align) ;
666
- let catch_data = catch. bitcast ( catch_data, bx . type_i8p ( ) ) ;
672
+ let catch_data = catch. bitcast ( catch_data, cx . type_i8p ( ) ) ;
667
673
668
674
catch. call ( catch_func, & [ data, catch_data] , None , None ) ;
669
- catch. ret ( bx . const_i32 ( 1 ) ) ;
675
+ catch. ret ( cx . const_i32 ( 1 ) ) ;
670
676
} ) ;
671
677
672
678
// Note that no invoke is used here because by definition this function
0 commit comments