diff options
| author | Antoni Boucher <bouanto@zoho.com> | 2022-11-20 10:36:15 -0500 |
|---|---|---|
| committer | Antoni Boucher <bouanto@zoho.com> | 2023-01-02 14:57:38 -0500 |
| commit | b0cf0e8c0653aab2c89de7b5e1ef34a24bf8ea80 (patch) | |
| tree | 6b3dc5c5c837fb703060e595e36d1eb5da66c259 | |
| parent | 889a33a500982cfc2c79ceff1b2caf86c0adbeaa (diff) | |
| download | rust-b0cf0e8c0653aab2c89de7b5e1ef34a24bf8ea80.tar.gz rust-b0cf0e8c0653aab2c89de7b5e1ef34a24bf8ea80.zip | |
WIP
| -rw-r--r-- | src/builder.rs | 20 | ||||
| -rw-r--r-- | src/callee.rs | 10 | ||||
| -rw-r--r-- | src/context.rs | 3 | ||||
| -rw-r--r-- | src/mono_item.rs | 6 |
4 files changed, 19 insertions, 20 deletions
diff --git a/src/builder.rs b/src/builder.rs index 68b664a3ba2..082b7be8c4e 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -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() } diff --git a/src/callee.rs b/src/callee.rs index fea5df9b9b0..496b8578bc3 100644 --- a/src/callee.rs +++ b/src/callee.rs @@ -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); //} diff --git a/src/context.rs b/src/context.rs index 04371048380..62e30679efa 100644 --- a/src/context.rs +++ b/src/context.rs @@ -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(), } } diff --git a/src/mono_item.rs b/src/mono_item.rs index 09ffd8dc798..3b7f9a0b6bc 100644 --- a/src/mono_item.rs +++ b/src/mono_item.rs @@ -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) }); } } |
