@@ -956,29 +956,24 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
956956 unsafe { llvm:: LLVMBuildInsertValue ( self . llbuilder , agg_val, elt, idx as c_uint , UNNAMED ) }
957957 }
958958
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 ) {
969960 unsafe {
970- llvm:: LLVMBuildLandingPad ( self . llbuilder , ty , None , num_clauses as c_uint , UNNAMED )
961+ llvm:: LLVMSetPersonalityFn ( self . llfn ( ) , personality ) ;
971962 }
972963 }
973964
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? */ ) ;
975967 unsafe {
976968 llvm:: LLVMSetCleanup ( landing_pad, llvm:: True ) ;
977969 }
970+ landing_pad
978971 }
979972
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+ }
982977 }
983978
984979 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> {
995990 Funclet :: new ( ret. expect ( "LLVM does not have support for cleanuppad" ) )
996991 }
997992
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+ }
1006998 }
1007999
10081000 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> {
10231015 & mut self ,
10241016 parent : Option < & ' ll Value > ,
10251017 unwind : Option < & ' ll BasicBlock > ,
1026- num_handlers : usize ,
1018+ handlers : & [ & ' ll BasicBlock ] ,
10271019 ) -> & ' ll Value {
10281020 let name = cstr ! ( "catchswitch" ) ;
10291021 let ret = unsafe {
10301022 llvm:: LLVMRustBuildCatchSwitch (
10311023 self . llbuilder ,
10321024 parent,
10331025 unwind,
1034- num_handlers as c_uint ,
1026+ handlers . len ( ) as c_uint ,
10351027 name. as_ptr ( ) ,
10361028 )
10371029 } ;
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+ }
10501035 }
1036+ ret
10511037 }
10521038
10531039 // Atomic Operations
@@ -1478,4 +1464,19 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
14781464 None
14791465 }
14801466 }
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+ }
14811482}
0 commit comments