This commit is contained in:
Antoni Boucher 2022-11-20 10:36:15 -05:00
parent 889a33a500
commit b0cf0e8c06
4 changed files with 19 additions and 20 deletions

View File

@ -467,7 +467,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
try_block.end_with_jump(None, then);
self.block.add_try_catch(None, try_block, catch);
if self.cleanup_blocks.borrow().contains(&catch) {
self.block.add_try_finally(None, try_block, catch);
}
else {
// FIXME: FIXME: FIXME: Seems like bad (_URC_NO_REASON) return code, perhaps because the cleanup pad was created properly.
// FIXME: Wrong personality function: __gcc_personality_v0
println!("Try/catch in {:?}", self.current_func());
self.block.add_try_catch(None, try_block, catch);
}
self.block.end_with_jump(None, then);
@ -1202,12 +1210,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
fn cleanup_landing_pad(&mut self, _ty: Type<'gcc>, pers_fn: RValue<'gcc>) -> RValue<'gcc> {
self.set_personality_fn(pers_fn);
self.cleanup_blocks.borrow_mut().insert(self.block);
// FIXME: we're probably not creating a real cleanup pad here.
// FIXME: FIXME: FIXME: It seems to be the actual problem:
// FIXME: It seems to be the actual problem:
// libunwind finds a catch, so returns _URC_HANDLER_FOUND instead of _URC_CONTINUE_UNWIND.
// TODO: can we generate a goto from the finally to the cleanup landing pad?
// TODO: TODO: TODO: add this block to a cleanup_blocks variable and generate a try/finally instead if
// TODO: add this block to a cleanup_blocks variable and generate a try/finally instead if
// the catch block for it is a cleanup block.
// => NO, a cleanup is only called during unwinding.
//
// TODO: look at TRY_CATCH_IS_CLEANUP, CLEANUP_POINT_EXPR, WITH_CLEANUP_EXPR, CLEANUP_EH_ONLY.
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> {
self.block.add_assignment(None, value.access_field(None, field1), ptr);
self.block.add_assignment(None, value.access_field(None, field2), zero); // TODO: set the proper value here (the type of exception?).
/*
// Resume.
let param = self.context.new_parameter(None, ptr.get_type(), "exn");
// TODO: should we call __builtin_unwind_resume instead?
// FIXME: should probably not called resume because it could be executed (I believe) in
// normal (no exception) cases
let unwind_resume = self.context.new_function(None, FunctionType::Extern, self.type_void(), &[param], "_Unwind_Resume", false);
self.block.add_eval(None, self.context.new_call(None, unwind_resume, &[ptr]));
self.block.add_eval(None, self.context.new_call(None, unwind_resume, &[ptr]));*/
value.to_rvalue()
}

View File

@ -25,16 +25,9 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>,
let sym = tcx.symbol_name(instance).name;
if let Some(&func) = cx.function_instances.borrow().get(&instance) {
if sym == "rust_eh_personality" {
println!("Cached");
}
return func;
}
if sym == "rust_eh_personality" {
println!("Not cached");
}
let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());
let func =
@ -179,9 +172,6 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>,
};
//if !dont_cache {
if sym == "rust_eh_personality" {
println!("Caching here");
}
cx.function_instances.borrow_mut().insert(instance, func);
//}

View File

@ -120,6 +120,8 @@ pub struct CodegenCx<'gcc, 'tcx> {
/// they can be dereferenced later.
/// FIXME(antoyo): fix the rustc API to avoid having this hack.
pub structs_as_pointer: RefCell<FxHashSet<RValue<'gcc>>>,
pub cleanup_blocks: RefCell<FxHashSet<Block<'gcc>>>,
}
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@ -250,6 +252,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
rust_try_fn: Cell::new(None),
pointee_infos: Default::default(),
structs_as_pointer: Default::default(),
cleanup_blocks: Default::default(),
}
}

View File

@ -35,9 +35,6 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
self.linkage.set(base::linkage_to_gcc(linkage));
if symbol_name == "rust_eh_personality" {
println!("********************* Generating real rust_eh_personality: {:?}", base::linkage_to_gcc(linkage));
}
let decl = self.declare_fn(symbol_name, &fn_abi, false);
//let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
@ -64,9 +61,6 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
// TODO(antoyo): use inline attribute from there in linkage.set() above.
self.functions.borrow_mut().insert(symbol_name.to_string(), decl);
if symbol_name == "rust_eh_personality" {
println!("Caching here 2");
}
self.function_instances.borrow_mut().insert(instance, unsafe { std::mem::transmute(decl) });
}
}