Skip to content

Commit a4b74e3

Browse files
committed
Fix unwinding
1 parent 71d7e56 commit a4b74e3

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

src/builder.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
472472
}
473473
else {
474474
// FIXME: FIXME: FIXME: Seems like bad (_URC_NO_REASON) return code, perhaps because the cleanup pad was created properly.
475-
// FIXME: Wrong personality function: __gcc_personality_v0
476475
println!("Try/catch in {:?}", self.current_func());
477476
self.block.add_try_catch(None, try_block, catch);
478477
}
@@ -1220,15 +1219,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12201219

12211220
self.cleanup_blocks.borrow_mut().insert(self.block);
12221221

1223-
// FIXME: we're probably not creating a real cleanup pad here.
1224-
// FIXME: It seems to be the actual problem:
1225-
// libunwind finds a catch, so returns _URC_HANDLER_FOUND instead of _URC_CONTINUE_UNWIND.
1226-
// TODO: can we generate a goto from the finally to the cleanup landing pad?
1227-
// TODO: add this block to a cleanup_blocks variable and generate a try/finally instead if
1228-
// the catch block for it is a cleanup block.
1229-
// => NO, a cleanup is only called during unwinding.
1230-
//
1231-
// TODO: look at TRY_CATCH_IS_CLEANUP, CLEANUP_POINT_EXPR, WITH_CLEANUP_EXPR, CLEANUP_EH_ONLY.
12321222
let eh_pointer_builtin = self.cx.context.get_target_builtin_function("__builtin_eh_pointer");
12331223
let zero = self.cx.context.new_rvalue_zero(self.int_type);
12341224
let ptr = self.cx.context.new_call(None, eh_pointer_builtin, &[zero]);
@@ -1242,21 +1232,14 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12421232
self.block.add_assignment(None, value.access_field(None, field1), ptr);
12431233
self.block.add_assignment(None, value.access_field(None, field2), zero); // TODO: set the proper value here (the type of exception?).
12441234

1245-
/*
1246-
// Resume.
1247-
let param = self.context.new_parameter(None, ptr.get_type(), "exn");
1248-
// TODO: should we call __builtin_unwind_resume instead?
1249-
// FIXME: should probably not called resume because it could be executed (I believe) in
1250-
// normal (no exception) cases
1251-
let unwind_resume = self.context.new_function(None, FunctionType::Extern, self.type_void(), &[param], "_Unwind_Resume", false);
1252-
self.block.add_eval(None, self.context.new_call(None, unwind_resume, &[ptr]));*/
1253-
12541235
value.to_rvalue()
12551236
}
12561237

12571238
fn resume(&mut self, exn: RValue<'gcc>) {
1239+
// TODO: check if this is normal that we need to dereference the value.
1240+
let exn = exn.dereference(None).to_rvalue();
12581241
let param = self.context.new_parameter(None, exn.get_type(), "exn");
1259-
// TODO: should we call __builtin_unwind_resume instead?
1242+
// TODO(antoyo): should we call __builtin_unwind_resume instead? This might actually be the same.
12601243
let unwind_resume = self.context.new_function(None, FunctionType::Extern, self.type_void(), &[param], "_Unwind_Resume", false);
12611244
self.llbb().add_eval(None, self.context.new_call(None, unwind_resume, &[exn]));
12621245
self.unreachable();

src/intrinsic/mod.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,16 +1179,10 @@ fn codegen_gnu_try<'gcc>(bx: &mut Builder<'_, 'gcc, '_>, try_func: RValue<'gcc>,
11791179

11801180
// Type indicator for the exception being thrown.
11811181
//
1182-
// The first value in this tuple is a pointer to the exception object
1183-
// being thrown. The second value is a "selector" indicating which of
1184-
// the landing pad clauses the exception's type had been matched to.
1185-
// rust_try ignores the selector.
1182+
// The value is a pointer to the exception object
1183+
// being thrown.
11861184
bx.switch_to_block(catch);
1187-
/*let lpad_ty = bx.type_struct(&[bx.type_i8p(), bx.type_i32()], false);
1188-
let vals = bx.landing_pad(lpad_ty, bx.eh_personality(), 1);
1189-
let tydesc = bx.const_null(bx.type_i8p());
1190-
bx.add_clause(vals, tydesc);
1191-
let ptr = bx.extract_value(vals, 0);*/
1185+
bx.set_personality_fn(bx.eh_personality());
11921186

11931187
let eh_pointer_builtin = bx.cx.context.get_target_builtin_function("__builtin_eh_pointer");
11941188
let zero = bx.cx.context.new_rvalue_zero(bx.int_type);

0 commit comments

Comments
 (0)