@@ -956,29 +956,24 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
956
956
unsafe { llvm:: LLVMBuildInsertValue ( self . llbuilder , agg_val, elt, idx as c_uint , UNNAMED ) }
957
957
}
958
958
959
- fn landing_pad (
960
- & mut self ,
961
- ty : & ' ll Type ,
962
- pers_fn : & ' ll Value ,
963
- num_clauses : usize ,
964
- ) -> & ' ll Value {
965
- // Use LLVMSetPersonalityFn to set the personality. It supports arbitrary Consts while,
966
- // LLVMBuildLandingPad requires the argument to be a Function (as of LLVM 12). The
967
- // personality lives on the parent function anyway.
968
- self . set_personality_fn ( pers_fn) ;
959
+ fn set_personality_fn ( & mut self , personality : & ' ll Value ) {
969
960
unsafe {
970
- llvm:: LLVMBuildLandingPad ( self . llbuilder , ty , None , num_clauses as c_uint , UNNAMED )
961
+ llvm:: LLVMSetPersonalityFn ( self . llfn ( ) , personality ) ;
971
962
}
972
963
}
973
964
974
- fn set_cleanup ( & mut self , landing_pad : & ' ll Value ) {
965
+ fn cleanup_landing_pad ( & mut self , ty : & ' ll Type , pers_fn : & ' ll Value ) -> & ' ll Value {
966
+ let landing_pad = self . landing_pad ( ty, pers_fn, 1 /* FIXME should this be 0? */ ) ;
975
967
unsafe {
976
968
llvm:: LLVMSetCleanup ( landing_pad, llvm:: True ) ;
977
969
}
970
+ landing_pad
978
971
}
979
972
980
- fn resume ( & mut self , exn : & ' ll Value ) -> & ' ll Value {
981
- unsafe { llvm:: LLVMBuildResume ( self . llbuilder , exn) }
973
+ fn resume ( & mut self , exn : & ' ll Value ) {
974
+ unsafe {
975
+ llvm:: LLVMBuildResume ( self . llbuilder , exn) ;
976
+ }
982
977
}
983
978
984
979
fn cleanup_pad ( & mut self , parent : Option < & ' ll Value > , args : & [ & ' ll Value ] ) -> Funclet < ' ll > {
@@ -995,14 +990,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
995
990
Funclet :: new ( ret. expect ( "LLVM does not have support for cleanuppad" ) )
996
991
}
997
992
998
- fn cleanup_ret (
999
- & mut self ,
1000
- funclet : & Funclet < ' ll > ,
1001
- unwind : Option < & ' ll BasicBlock > ,
1002
- ) -> & ' ll Value {
1003
- let ret =
1004
- unsafe { llvm:: LLVMRustBuildCleanupRet ( self . llbuilder , funclet. cleanuppad ( ) , unwind) } ;
1005
- ret. expect ( "LLVM does not have support for cleanupret" )
993
+ fn cleanup_ret ( & mut self , funclet : & Funclet < ' ll > , unwind : Option < & ' ll BasicBlock > ) {
994
+ unsafe {
995
+ llvm:: LLVMRustBuildCleanupRet ( self . llbuilder , funclet. cleanuppad ( ) , unwind)
996
+ . expect ( "LLVM does not have support for cleanupret" ) ;
997
+ }
1006
998
}
1007
999
1008
1000
fn catch_pad ( & mut self , parent : & ' ll Value , args : & [ & ' ll Value ] ) -> Funclet < ' ll > {
@@ -1023,31 +1015,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
1023
1015
& mut self ,
1024
1016
parent : Option < & ' ll Value > ,
1025
1017
unwind : Option < & ' ll BasicBlock > ,
1026
- num_handlers : usize ,
1018
+ handlers : & [ & ' ll BasicBlock ] ,
1027
1019
) -> & ' ll Value {
1028
1020
let name = cstr ! ( "catchswitch" ) ;
1029
1021
let ret = unsafe {
1030
1022
llvm:: LLVMRustBuildCatchSwitch (
1031
1023
self . llbuilder ,
1032
1024
parent,
1033
1025
unwind,
1034
- num_handlers as c_uint ,
1026
+ handlers . len ( ) as c_uint ,
1035
1027
name. as_ptr ( ) ,
1036
1028
)
1037
1029
} ;
1038
- ret. expect ( "LLVM does not have support for catchswitch" )
1039
- }
1040
-
1041
- fn add_handler ( & mut self , catch_switch : & ' ll Value , handler : & ' ll BasicBlock ) {
1042
- unsafe {
1043
- llvm:: LLVMRustAddHandler ( catch_switch, handler) ;
1044
- }
1045
- }
1046
-
1047
- fn set_personality_fn ( & mut self , personality : & ' ll Value ) {
1048
- unsafe {
1049
- llvm:: LLVMSetPersonalityFn ( self . llfn ( ) , personality) ;
1030
+ let ret = ret. expect ( "LLVM does not have support for catchswitch" ) ;
1031
+ for handler in handlers {
1032
+ unsafe {
1033
+ llvm:: LLVMRustAddHandler ( ret, handler) ;
1034
+ }
1050
1035
}
1036
+ ret
1051
1037
}
1052
1038
1053
1039
// Atomic Operations
@@ -1478,4 +1464,19 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1478
1464
None
1479
1465
}
1480
1466
}
1467
+
1468
+ pub ( crate ) fn landing_pad (
1469
+ & mut self ,
1470
+ ty : & ' ll Type ,
1471
+ pers_fn : & ' ll Value ,
1472
+ num_clauses : usize ,
1473
+ ) -> & ' ll Value {
1474
+ // Use LLVMSetPersonalityFn to set the personality. It supports arbitrary Consts while,
1475
+ // LLVMBuildLandingPad requires the argument to be a Function (as of LLVM 12). The
1476
+ // personality lives on the parent function anyway.
1477
+ self . set_personality_fn ( pers_fn) ;
1478
+ unsafe {
1479
+ llvm:: LLVMBuildLandingPad ( self . llbuilder , ty, None , num_clauses as c_uint , UNNAMED )
1480
+ }
1481
+ }
1481
1482
}
0 commit comments