Skip to content

Commit 7a16450

Browse files
committed
Merge add_handler into catch_switch
Some codegen backends may require all handlers to be immediately known
1 parent e9646fa commit 7a16450

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,11 +1291,12 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12911291
unimplemented!();
12921292
}
12931293

1294-
fn catch_switch(&mut self, _parent: Option<RValue<'gcc>>, _unwind: Option<Block<'gcc>>, _num_handlers: usize) -> RValue<'gcc> {
1295-
unimplemented!();
1296-
}
1297-
1298-
fn add_handler(&mut self, _catch_switch: RValue<'gcc>, _handler: Block<'gcc>) {
1294+
fn catch_switch(
1295+
&mut self,
1296+
_parent: Option<RValue<'gcc>>,
1297+
_unwind: Option<Block<'gcc>>,
1298+
_handlers: &[Block<'gcc>],
1299+
) -> RValue<'gcc> {
12991300
unimplemented!();
13001301
}
13011302

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,25 +1028,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10281028
&mut self,
10291029
parent: Option<&'ll Value>,
10301030
unwind: Option<&'ll BasicBlock>,
1031-
num_handlers: usize,
1031+
handlers: &[&'ll BasicBlock],
10321032
) -> &'ll Value {
10331033
let name = cstr!("catchswitch");
10341034
let ret = unsafe {
10351035
llvm::LLVMRustBuildCatchSwitch(
10361036
self.llbuilder,
10371037
parent,
10381038
unwind,
1039-
num_handlers as c_uint,
1039+
handlers.len() as c_uint,
10401040
name.as_ptr(),
10411041
)
10421042
};
1043-
ret.expect("LLVM does not have support for catchswitch")
1044-
}
1045-
1046-
fn add_handler(&mut self, catch_switch: &'ll Value, handler: &'ll BasicBlock) {
1047-
unsafe {
1048-
llvm::LLVMRustAddHandler(catch_switch, handler);
1043+
let ret = ret.expect("LLVM does not have support for catchswitch");
1044+
for handler in handlers {
1045+
unsafe {
1046+
llvm::LLVMRustAddHandler(ret, handler);
1047+
}
10491048
}
1049+
ret
10501050
}
10511051

10521052
// Atomic Operations

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,8 @@ fn codegen_msvc_try<'ll>(
525525

526526
normal.ret(bx.const_i32(0));
527527

528-
let cs = catchswitch.catch_switch(None, None, 2);
529-
catchswitch.add_handler(cs, catchpad_rust.llbb());
530-
catchswitch.add_handler(cs, catchpad_foreign.llbb());
528+
let cs =
529+
catchswitch.catch_switch(None, None, &[catchpad_rust.llbb(), catchpad_foreign.llbb()]);
531530

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

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
13461346
let mut cp_bx = self.new_block(&format!("cp_funclet{:?}", bb));
13471347
ret_llbb = cs_bx.llbb();
13481348

1349-
let cs = cs_bx.catch_switch(None, None, 1);
1350-
cs_bx.add_handler(cs, cp_bx.llbb());
1349+
let cs = cs_bx.catch_switch(None, None, &[cp_bx.llbb()]);
13511350

13521351
// The "null" here is actually a RTTI type descriptor for the
13531352
// 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
@@ -441,9 +441,8 @@ pub trait BuilderMethods<'a, 'tcx>:
441441
&mut self,
442442
parent: Option<Self::Value>,
443443
unwind: Option<Self::BasicBlock>,
444-
num_handlers: usize,
444+
handlers: &[Self::BasicBlock],
445445
) -> Self::Value;
446-
fn add_handler(&mut self, catch_switch: Self::Value, handler: Self::BasicBlock);
447446

448447
fn atomic_cmpxchg(
449448
&mut self,

0 commit comments

Comments
 (0)