Skip to content

Commit 4eb3ce3

Browse files
committed
Add landing pads to invokes
Issue #236
1 parent 5e4637b commit 4eb3ce3

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/comp/middle/trans.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3799,15 +3799,32 @@ fn invoke_fastcall(bcx: &@block_ctxt, llfn: ValueRef,
37993799

38003800
let normal_bcx = new_sub_block_ctxt(bcx, "normal return");
38013801
let unwind_bcx = new_sub_block_ctxt(bcx, "unwind");
3802-
let retval = trans_build::FastInvoke(bcx, llfn, llargs,
3803-
normal_bcx.llbb,
3804-
unwind_bcx.llbb);
3802+
let retval = FastInvoke(bcx, llfn, llargs,
3803+
normal_bcx.llbb,
3804+
unwind_bcx.llbb);
38053805
trans_landing_pad(unwind_bcx);
38063806
ret rslt(normal_bcx, retval);
38073807
}
38083808

38093809
fn trans_landing_pad(bcx: &@block_ctxt) {
3810-
Unreachable(bcx);
3810+
// The landing pad return type (the type being propagated). Not sure what
3811+
// this represents but it's determined by the personality function and
3812+
// this is what the EH proposal example uses.
3813+
let llretty = T_struct([T_ptr(T_i8()), T_i32()]);
3814+
// The exception handling personality function. This is the C++
3815+
// personality function __gxx_personality_v0, wrapped in our naming
3816+
// convention.
3817+
let personality = bcx_ccx(bcx).upcalls.rust_personality;
3818+
// The only landing pad clause will be 'cleanup'
3819+
let clauses = 1u;
3820+
let llpad = LandingPad(bcx, llretty, personality, clauses);
3821+
// The landing pad result is used both for modifying the landing pad
3822+
// in the C API and as the exception value
3823+
let llretval = llpad;
3824+
// The landing pad block is a cleanup
3825+
SetCleanup(bcx, llpad);
3826+
// Continue unwinding
3827+
Resume(bcx, llretval);
38113828
}
38123829

38133830
fn trans_tup(cx: &@block_ctxt, elts: &[@ast::expr], id: ast::node_id) ->

src/comp/middle/trans_build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ fn Trap(cx: &@block_ctxt) -> ValueRef {
547547

548548
fn LandingPad(cx: &@block_ctxt, Ty: TypeRef, PersFn: ValueRef,
549549
NumClauses: uint) -> ValueRef {
550+
assert (!cx.terminated);
550551
ret str::as_buf("",
551552
{|buf|
552553
llvm::LLVMBuildLandingPad(B(cx),
@@ -561,6 +562,12 @@ fn SetCleanup(_cx: &@block_ctxt, LandingPad: ValueRef) {
561562
llvm::LLVMSetCleanup(LandingPad, lib::llvm::True);
562563
}
563564

565+
fn Resume(cx: &@block_ctxt, Exn: ValueRef) -> ValueRef {
566+
assert (!cx.terminated);
567+
cx.terminated = true;
568+
ret llvm::LLVMBuildResume(B(cx), Exn);
569+
}
570+
564571
//
565572
// Local Variables:
566573
// mode: rust

0 commit comments

Comments
 (0)