Skip to content

Commit fff6296

Browse files
committed
Destruct landing_pad return value before passing it to cg_ssa
1 parent 703d95e commit fff6296

File tree

4 files changed

+25
-31
lines changed

4 files changed

+25
-31
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1119,18 +1119,18 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11191119
// TODO(antoyo)
11201120
}
11211121

1122-
fn cleanup_landing_pad(&mut self, _ty: Type<'gcc>, _pers_fn: RValue<'gcc>) -> RValue<'gcc> {
1123-
let field1 = self.context.new_field(None, self.u8_type.make_pointer(), "landing_pad_field_1");
1124-
let field2 = self.context.new_field(None, self.i32_type, "landing_pad_field_1");
1125-
let struct_type = self.context.new_struct_type(None, "landing_pad", &[field1, field2]);
1126-
self.current_func().new_local(None, struct_type.as_type(), "landing_pad")
1127-
.to_rvalue()
1122+
fn cleanup_landing_pad(&mut self, _pers_fn: RValue<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
1123+
(
1124+
self.current_func().new_local(None, self.u8_type.make_pointer(), "landing_pad0")
1125+
.to_rvalue(),
1126+
self.current_func().new_local(None, self.i32_type, "landing_pad1").to_rvalue(),
1127+
)
11281128
// TODO(antoyo): Properly implement unwinding.
11291129
// the above is just to make the compilation work as it seems
11301130
// rustc_codegen_ssa now calls the unwinding builder methods even on panic=abort.
11311131
}
11321132

1133-
fn resume(&mut self, _exn: RValue<'gcc>) {
1133+
fn resume(&mut self, _exn0: RValue<'gcc>, _exn1: RValue<'gcc>) {
11341134
// TODO(bjorn3): Properly implement unwinding.
11351135
self.unreachable();
11361136
}

compiler/rustc_codegen_llvm/src/builder.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -961,15 +961,20 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
961961
}
962962
}
963963

964-
fn cleanup_landing_pad(&mut self, ty: &'ll Type, pers_fn: &'ll Value) -> &'ll Value {
964+
fn cleanup_landing_pad(&mut self, pers_fn: &'ll Value) -> (&'ll Value, &'ll Value) {
965+
let ty = self.type_struct(&[self.type_i8p(), self.type_i32()], false);
965966
let landing_pad = self.landing_pad(ty, pers_fn, 1 /* FIXME should this be 0? */);
966967
unsafe {
967968
llvm::LLVMSetCleanup(landing_pad, llvm::True);
968969
}
969-
landing_pad
970+
(self.extract_value(landing_pad, 0), self.extract_value(landing_pad, 1))
970971
}
971972

972-
fn resume(&mut self, exn: &'ll Value) {
973+
fn resume(&mut self, exn0: &'ll Value, exn1: &'ll Value) {
974+
let ty = self.type_struct(&[self.type_i8p(), self.type_i32()], false);
975+
let mut exn = self.const_undef(ty);
976+
exn = self.insert_value(exn, exn0, 0);
977+
exn = self.insert_value(exn, exn1, 1);
973978
unsafe {
974979
llvm::LLVMBuildResume(self.llbuilder, exn);
975980
}

compiler/rustc_codegen_ssa/src/mir/block.rs

+8-19
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
289289
bx.cleanup_ret(funclet, None);
290290
} else {
291291
let slot = self.get_personality_slot(bx);
292-
let lp0 = slot.project_field(bx, 0);
293-
let lp0 = bx.load_operand(lp0).immediate();
294-
let lp1 = slot.project_field(bx, 1);
295-
let lp1 = bx.load_operand(lp1).immediate();
292+
let exn0 = slot.project_field(bx, 0);
293+
let exn0 = bx.load_operand(exn0).immediate();
294+
let exn1 = slot.project_field(bx, 1);
295+
let exn1 = bx.load_operand(exn1).immediate();
296296
slot.storage_dead(bx);
297297

298-
let mut lp = bx.const_undef(self.landing_pad_type());
299-
lp = bx.insert_value(lp, lp0, 0);
300-
lp = bx.insert_value(lp, lp1, 1);
301-
bx.resume(lp);
298+
bx.resume(exn0, exn1);
302299
}
303300
}
304301

@@ -1635,24 +1632,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16351632
let mut cleanup_bx = Bx::build(self.cx, cleanup_llbb);
16361633

16371634
let llpersonality = self.cx.eh_personality();
1638-
let llretty = self.landing_pad_type();
1639-
let lp = cleanup_bx.cleanup_landing_pad(llretty, llpersonality);
1635+
let (exn0, exn1) = cleanup_bx.cleanup_landing_pad(llpersonality);
16401636

16411637
let slot = self.get_personality_slot(&mut cleanup_bx);
16421638
slot.storage_live(&mut cleanup_bx);
1643-
Pair(cleanup_bx.extract_value(lp, 0), cleanup_bx.extract_value(lp, 1))
1644-
.store(&mut cleanup_bx, slot);
1639+
Pair(exn0, exn1).store(&mut cleanup_bx, slot);
16451640

16461641
cleanup_bx.br(llbb);
16471642
cleanup_llbb
16481643
}
16491644
}
16501645

1651-
fn landing_pad_type(&self) -> Bx::Type {
1652-
let cx = self.cx;
1653-
cx.type_struct(&[cx.type_i8p(), cx.type_i32()], false)
1654-
}
1655-
16561646
fn unreachable_block(&mut self) -> Bx::BasicBlock {
16571647
self.unreachable_block.unwrap_or_else(|| {
16581648
let llbb = Bx::append_block(self.cx, self.llfn, "unreachable");
@@ -1672,8 +1662,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16721662
self.set_debug_loc(&mut bx, mir::SourceInfo::outermost(self.mir.span));
16731663

16741664
let llpersonality = self.cx.eh_personality();
1675-
let llretty = self.landing_pad_type();
1676-
bx.cleanup_landing_pad(llretty, llpersonality);
1665+
bx.cleanup_landing_pad(llpersonality);
16771666

16781667
let (fn_abi, fn_ptr) = common::build_langcall(&bx, None, LangItem::PanicNoUnwind);
16791668
let fn_ty = bx.fn_decl_backend_type(&fn_abi);

compiler/rustc_codegen_ssa/src/traits/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ pub trait BuilderMethods<'a, 'tcx>:
271271
fn set_personality_fn(&mut self, personality: Self::Value);
272272

273273
// These are used by everyone except msvc
274-
fn cleanup_landing_pad(&mut self, ty: Self::Type, pers_fn: Self::Value) -> Self::Value;
275-
fn resume(&mut self, exn: Self::Value);
274+
fn cleanup_landing_pad(&mut self, pers_fn: Self::Value) -> (Self::Value, Self::Value);
275+
fn resume(&mut self, exn0: Self::Value, exn1: Self::Value);
276276

277277
// These are used only by msvc
278278
fn cleanup_pad(&mut self, parent: Option<Self::Value>, args: &[Self::Value]) -> Self::Funclet;

0 commit comments

Comments
 (0)