Skip to content

Commit b0cf0e8

Browse files
committed
WIP
1 parent 889a33a commit b0cf0e8

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

src/builder.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
467467

468468
try_block.end_with_jump(None, then);
469469

470-
self.block.add_try_catch(None, try_block, catch);
470+
if self.cleanup_blocks.borrow().contains(&catch) {
471+
self.block.add_try_finally(None, try_block, catch);
472+
}
473+
else {
474+
// 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
476+
println!("Try/catch in {:?}", self.current_func());
477+
self.block.add_try_catch(None, try_block, catch);
478+
}
471479

472480
self.block.end_with_jump(None, then);
473481

@@ -1202,12 +1210,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12021210
fn cleanup_landing_pad(&mut self, _ty: Type<'gcc>, pers_fn: RValue<'gcc>) -> RValue<'gcc> {
12031211
self.set_personality_fn(pers_fn);
12041212

1213+
self.cleanup_blocks.borrow_mut().insert(self.block);
1214+
12051215
// FIXME: we're probably not creating a real cleanup pad here.
1206-
// FIXME: FIXME: FIXME: It seems to be the actual problem:
1216+
// FIXME: It seems to be the actual problem:
12071217
// libunwind finds a catch, so returns _URC_HANDLER_FOUND instead of _URC_CONTINUE_UNWIND.
12081218
// TODO: can we generate a goto from the finally to the cleanup landing pad?
1209-
// TODO: TODO: TODO: add this block to a cleanup_blocks variable and generate a try/finally instead if
1219+
// TODO: add this block to a cleanup_blocks variable and generate a try/finally instead if
12101220
// the catch block for it is a cleanup block.
1221+
// => NO, a cleanup is only called during unwinding.
12111222
//
12121223
// TODO: look at TRY_CATCH_IS_CLEANUP, CLEANUP_POINT_EXPR, WITH_CLEANUP_EXPR, CLEANUP_EH_ONLY.
12131224
let eh_pointer_builtin = self.cx.context.get_target_builtin_function("__builtin_eh_pointer");
@@ -1223,13 +1234,14 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12231234
self.block.add_assignment(None, value.access_field(None, field1), ptr);
12241235
self.block.add_assignment(None, value.access_field(None, field2), zero); // TODO: set the proper value here (the type of exception?).
12251236

1237+
/*
12261238
// Resume.
12271239
let param = self.context.new_parameter(None, ptr.get_type(), "exn");
12281240
// TODO: should we call __builtin_unwind_resume instead?
12291241
// FIXME: should probably not called resume because it could be executed (I believe) in
12301242
// normal (no exception) cases
12311243
let unwind_resume = self.context.new_function(None, FunctionType::Extern, self.type_void(), &[param], "_Unwind_Resume", false);
1232-
self.block.add_eval(None, self.context.new_call(None, unwind_resume, &[ptr]));
1244+
self.block.add_eval(None, self.context.new_call(None, unwind_resume, &[ptr]));*/
12331245

12341246
value.to_rvalue()
12351247
}

src/callee.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,9 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>,
2525
let sym = tcx.symbol_name(instance).name;
2626

2727
if let Some(&func) = cx.function_instances.borrow().get(&instance) {
28-
if sym == "rust_eh_personality" {
29-
println!("Cached");
30-
}
3128
return func;
3229
}
3330

34-
if sym == "rust_eh_personality" {
35-
println!("Not cached");
36-
}
37-
3831
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
3932

4033
let func =
@@ -179,9 +172,6 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>,
179172
};
180173

181174
//if !dont_cache {
182-
if sym == "rust_eh_personality" {
183-
println!("Caching here");
184-
}
185175
cx.function_instances.borrow_mut().insert(instance, func);
186176
//}
187177

src/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ pub struct CodegenCx<'gcc, 'tcx> {
120120
/// they can be dereferenced later.
121121
/// FIXME(antoyo): fix the rustc API to avoid having this hack.
122122
pub structs_as_pointer: RefCell<FxHashSet<RValue<'gcc>>>,
123+
124+
pub cleanup_blocks: RefCell<FxHashSet<Block<'gcc>>>,
123125
}
124126

125127
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -250,6 +252,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
250252
rust_try_fn: Cell::new(None),
251253
pointee_infos: Default::default(),
252254
structs_as_pointer: Default::default(),
255+
cleanup_blocks: Default::default(),
253256
}
254257
}
255258

src/mono_item.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
3535

3636
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
3737
self.linkage.set(base::linkage_to_gcc(linkage));
38-
if symbol_name == "rust_eh_personality" {
39-
println!("********************* Generating real rust_eh_personality: {:?}", base::linkage_to_gcc(linkage));
40-
}
4138
let decl = self.declare_fn(symbol_name, &fn_abi, false);
4239
//let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
4340

@@ -64,9 +61,6 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
6461
// TODO(antoyo): use inline attribute from there in linkage.set() above.
6562

6663
self.functions.borrow_mut().insert(symbol_name.to_string(), decl);
67-
if symbol_name == "rust_eh_personality" {
68-
println!("Caching here 2");
69-
}
7064
self.function_instances.borrow_mut().insert(instance, unsafe { std::mem::transmute(decl) });
7165
}
7266
}

0 commit comments

Comments
 (0)