Skip to content

Commit a297a5b

Browse files
committed
rustc_codegen_ssa: take the handlers directly in catch_switch.
1 parent 2523a29 commit a297a5b

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -997,25 +997,25 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
997997
&mut self,
998998
parent: Option<&'ll Value>,
999999
unwind: Option<&'ll BasicBlock>,
1000-
num_handlers: usize,
1000+
handlers: &[&'ll BasicBlock],
10011001
) -> &'ll Value {
10021002
let name = cstr!("catchswitch");
10031003
let ret = unsafe {
10041004
llvm::LLVMRustBuildCatchSwitch(
10051005
self.llbuilder,
10061006
parent,
10071007
unwind,
1008-
num_handlers as c_uint,
1008+
handlers.len() as c_uint,
10091009
name.as_ptr(),
10101010
)
10111011
};
1012-
ret.expect("LLVM does not have support for catchswitch")
1013-
}
1014-
1015-
fn add_handler(&mut self, catch_switch: &'ll Value, handler: &'ll BasicBlock) {
1016-
unsafe {
1017-
llvm::LLVMRustAddHandler(catch_switch, handler);
1012+
let catch_switch = ret.expect("LLVM does not have support for catchswitch");
1013+
for &handler in handlers {
1014+
unsafe {
1015+
llvm::LLVMRustAddHandler(catch_switch, handler);
1016+
}
10181017
}
1018+
catch_switch
10191019
}
10201020

10211021
fn set_personality_fn(&mut self, personality: &'ll Value) {

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,8 @@ fn codegen_msvc_try(
465465

466466
normal.ret(bx.const_i32(0));
467467

468-
let cs = catchswitch.catch_switch(None, None, 2);
469-
catchswitch.add_handler(cs, catchpad_rust.llbb());
470-
catchswitch.add_handler(cs, catchpad_foreign.llbb());
468+
let cs =
469+
catchswitch.catch_switch(None, None, &[catchpad_rust.llbb(), catchpad_foreign.llbb()]);
471470

472471
// We can't use the TypeDescriptor defined in libpanic_unwind because it
473472
// might be in another DLL and the SEH encoding only supports specifying

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ fn create_funclets<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
317317
let mut cp_bx = bx.build_sibling_block(&format!("cp_funclet{:?}", bb));
318318
ret_llbb = cs_bx.llbb();
319319

320-
let cs = cs_bx.catch_switch(None, None, 1);
321-
cs_bx.add_handler(cs, cp_bx.llbb());
320+
let cs = cs_bx.catch_switch(None, None, &[cp_bx.llbb()]);
322321

323322
// The "null" here is actually a RTTI type descriptor for the
324323
// C++ personality function, but `catch (...)` has no type so

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,8 @@ pub trait BuilderMethods<'a, 'tcx>:
253253
&mut self,
254254
parent: Option<Self::Value>,
255255
unwind: Option<Self::BasicBlock>,
256-
num_handlers: usize,
256+
handlers: &[Self::BasicBlock],
257257
) -> Self::Value;
258-
fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
259258
fn set_personality_fn(&mut self, personality: Self::Value);
260259

261260
fn atomic_cmpxchg(

0 commit comments

Comments
 (0)