@@ -467,7 +467,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
467
467
468
468
try_block. end_with_jump ( None , then) ;
469
469
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
+ }
471
479
472
480
self . block . end_with_jump ( None , then) ;
473
481
@@ -1202,12 +1210,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
1202
1210
fn cleanup_landing_pad ( & mut self , _ty : Type < ' gcc > , pers_fn : RValue < ' gcc > ) -> RValue < ' gcc > {
1203
1211
self . set_personality_fn ( pers_fn) ;
1204
1212
1213
+ self . cleanup_blocks . borrow_mut ( ) . insert ( self . block ) ;
1214
+
1205
1215
// 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:
1207
1217
// libunwind finds a catch, so returns _URC_HANDLER_FOUND instead of _URC_CONTINUE_UNWIND.
1208
1218
// 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
1210
1220
// the catch block for it is a cleanup block.
1221
+ // => NO, a cleanup is only called during unwinding.
1211
1222
//
1212
1223
// TODO: look at TRY_CATCH_IS_CLEANUP, CLEANUP_POINT_EXPR, WITH_CLEANUP_EXPR, CLEANUP_EH_ONLY.
1213
1224
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> {
1223
1234
self . block . add_assignment ( None , value. access_field ( None , field1) , ptr) ;
1224
1235
self . block . add_assignment ( None , value. access_field ( None , field2) , zero) ; // TODO: set the proper value here (the type of exception?).
1225
1236
1237
+ /*
1226
1238
// Resume.
1227
1239
let param = self.context.new_parameter(None, ptr.get_type(), "exn");
1228
1240
// TODO: should we call __builtin_unwind_resume instead?
1229
1241
// FIXME: should probably not called resume because it could be executed (I believe) in
1230
1242
// normal (no exception) cases
1231
1243
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]));*/
1233
1245
1234
1246
value. to_rvalue ( )
1235
1247
}
0 commit comments