about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAntoni Boucher <bouanto@zoho.com>2023-01-06 10:42:38 -0500
committerAntoni Boucher <bouanto@zoho.com>2023-01-06 10:42:38 -0500
commita4b74e3adf214d985c541eb7d005bb77e59338f5 (patch)
treeee1bea3aa38948c1398ddac6df15aea8386a9c9b
parent71d7e561bdc2e58cef7fedcec1970dafc852bb61 (diff)
downloadrust-a4b74e3adf214d985c541eb7d005bb77e59338f5.tar.gz
rust-a4b74e3adf214d985c541eb7d005bb77e59338f5.zip
Fix unwinding
-rw-r--r--src/builder.rs23
-rw-r--r--src/intrinsic/mod.rs12
2 files changed, 6 insertions, 29 deletions
diff --git a/src/builder.rs b/src/builder.rs
index fd674ed0b87..af77fa418c8 100644
--- a/src/builder.rs
+++ b/src/builder.rs
@@ -472,7 +472,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
         }
         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);
         }
@@ -1220,15 +1219,6 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
 
         self.cleanup_blocks.borrow_mut().insert(self.block);
 
-        // FIXME: we're probably not creating a real cleanup pad here.
-        // 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: 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");
         let zero = self.cx.context.new_rvalue_zero(self.int_type);
         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> {
         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]));*/
-
         value.to_rvalue()
     }
 
     fn resume(&mut self, exn: RValue<'gcc>) {
+        // TODO: check if this is normal that we need to dereference the value.
+        let exn = exn.dereference(None).to_rvalue();
         let param = self.context.new_parameter(None, exn.get_type(), "exn");
-        // TODO: should we call __builtin_unwind_resume instead?
+        // TODO(antoyo): should we call __builtin_unwind_resume instead? This might actually be the same.
         let unwind_resume = self.context.new_function(None, FunctionType::Extern, self.type_void(), &[param], "_Unwind_Resume", false);
         self.llbb().add_eval(None, self.context.new_call(None, unwind_resume, &[exn]));
         self.unreachable();
diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs
index 511256e45a3..ce7874a3de4 100644
--- a/src/intrinsic/mod.rs
+++ b/src/intrinsic/mod.rs
@@ -1179,16 +1179,10 @@ fn codegen_gnu_try<'gcc>(bx: &mut Builder<'_, 'gcc, '_>, try_func: RValue<'gcc>,
 
         // Type indicator for the exception being thrown.
         //
-        // The first value in this tuple is a pointer to the exception object
-        // being thrown.  The second value is a "selector" indicating which of
-        // the landing pad clauses the exception's type had been matched to.
-        // rust_try ignores the selector.
+        // The value is a pointer to the exception object
+        // being thrown.
         bx.switch_to_block(catch);
-        /*let lpad_ty = bx.type_struct(&[bx.type_i8p(), bx.type_i32()], false);
-        let vals = bx.landing_pad(lpad_ty, bx.eh_personality(), 1);
-        let tydesc = bx.const_null(bx.type_i8p());
-        bx.add_clause(vals, tydesc);
-        let ptr = bx.extract_value(vals, 0);*/
+        bx.set_personality_fn(bx.eh_personality());
 
         let eh_pointer_builtin = bx.cx.context.get_target_builtin_function("__builtin_eh_pointer");
         let zero = bx.cx.context.new_rvalue_zero(bx.int_type);