@@ -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 }
0 commit comments