Skip to content

Commit

Permalink
Merge landing_pad and set_cleanup into cleanup_landing_pad
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Jan 24, 2022
1 parent 7a16450 commit f6ce771
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
// TODO(antoyo)
}

fn landing_pad(&mut self, _ty: Type<'gcc>, _pers_fn: RValue<'gcc>, _num_clauses: usize) -> RValue<'gcc> {
fn cleanup_landing_pad(&mut self, _ty: Type<'gcc>, _pers_fn: RValue<'gcc>) -> RValue<'gcc> {
let field1 = self.context.new_field(None, self.u8_type, "landing_pad_field_1");
let field2 = self.context.new_field(None, self.i32_type, "landing_pad_field_1");
let struct_type = self.context.new_struct_type(None, "landing_pad", &[field1, field2]);
Expand All @@ -1271,10 +1271,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
// rustc_codegen_ssa now calls the unwinding builder methods even on panic=abort.
}

fn set_cleanup(&mut self, _landing_pad: RValue<'gcc>) {
// TODO(antoyo)
}

fn resume(&mut self, _exn: RValue<'gcc>) {
unimplemented!();
}
Expand Down
34 changes: 18 additions & 16 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,25 +962,12 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}
}

fn landing_pad(
&mut self,
ty: &'ll Type,
pers_fn: &'ll Value,
num_clauses: usize,
) -> &'ll Value {
// Use LLVMSetPersonalityFn to set the personality. It supports arbitrary Consts while,
// LLVMBuildLandingPad requires the argument to be a Function (as of LLVM 12). The
// personality lives on the parent function anyway.
self.set_personality_fn(pers_fn);
unsafe {
llvm::LLVMBuildLandingPad(self.llbuilder, ty, None, num_clauses as c_uint, UNNAMED)
}
}

fn set_cleanup(&mut self, landing_pad: &'ll Value) {
fn cleanup_landing_pad(&mut self, ty: &'ll Type, pers_fn: &'ll Value) -> &'ll Value {
let landing_pad = self.landing_pad(ty, pers_fn, 1 /* FIXME should this be 0? */);
unsafe {
llvm::LLVMSetCleanup(landing_pad, llvm::True);
}
landing_pad
}

fn resume(&mut self, exn: &'ll Value) {
Expand Down Expand Up @@ -1477,4 +1464,19 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
None
}
}

pub(crate) fn landing_pad(
&mut self,
ty: &'ll Type,
pers_fn: &'ll Value,
num_clauses: usize,
) -> &'ll Value {
// Use LLVMSetPersonalityFn to set the personality. It supports arbitrary Consts while,
// LLVMBuildLandingPad requires the argument to be a Function (as of LLVM 12). The
// personality lives on the parent function anyway.
self.set_personality_fn(pers_fn);
unsafe {
llvm::LLVMBuildLandingPad(self.llbuilder, ty, None, num_clauses as c_uint, UNNAMED)
}
}
}
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1373,8 +1373,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

let llpersonality = self.cx.eh_personality();
let llretty = self.landing_pad_type();
let lp = bx.landing_pad(llretty, llpersonality, 1);
bx.set_cleanup(lp);
let lp = bx.cleanup_landing_pad(llretty, llpersonality);

let slot = self.get_personality_slot(&mut bx);
slot.storage_live(&mut bx);
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_codegen_ssa/src/traits/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,7 @@ pub trait BuilderMethods<'a, 'tcx>:
fn set_personality_fn(&mut self, personality: Self::Value);

// These are used by everyone except msvc
fn landing_pad(
&mut self,
ty: Self::Type,
pers_fn: Self::Value,
num_clauses: usize,
) -> Self::Value;
fn set_cleanup(&mut self, landing_pad: Self::Value);
fn cleanup_landing_pad(&mut self, ty: Self::Type, pers_fn: Self::Value) -> Self::Value;
fn resume(&mut self, exn: Self::Value);

// These are used only by msvc
Expand Down

0 comments on commit f6ce771

Please sign in to comment.