From f9c06abc211f76004f3f558753d5d992ab32d223 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sun, 6 Mar 2016 14:29:31 +0200 Subject: [PATCH] trans: Simplify "try" intrinsic. --- src/librustc_trans/trans/intrinsic.rs | 42 ++++----------------------- 1 file changed, 5 insertions(+), 37 deletions(-) diff --git a/src/librustc_trans/trans/intrinsic.rs b/src/librustc_trans/trans/intrinsic.rs index df8bdb05fcd..37eb2aa4c58 100644 --- a/src/librustc_trans/trans/intrinsic.rs +++ b/src/librustc_trans/trans/intrinsic.rs @@ -350,43 +350,6 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, } } - // For `try` we need some custom control flow - if &name[..] == "try" { - if let callee::ArgExprs(ref exprs) = args { - let (func, data, local_ptr) = if exprs.len() != 3 { - ccx.sess().bug("expected three exprs as arguments for \ - `try` intrinsic"); - } else { - (&exprs[0], &exprs[1], &exprs[2]) - }; - - // translate arguments - let func = unpack_datum!(bcx, expr::trans(bcx, func)); - let func = unpack_datum!(bcx, func.to_rvalue_datum(bcx, "func")); - let data = unpack_datum!(bcx, expr::trans(bcx, data)); - let data = unpack_datum!(bcx, data.to_rvalue_datum(bcx, "data")); - let local_ptr = unpack_datum!(bcx, expr::trans(bcx, local_ptr)); - let local_ptr = local_ptr.to_rvalue_datum(bcx, "local_ptr"); - let local_ptr = unpack_datum!(bcx, local_ptr); - - let dest = match dest { - expr::SaveIn(d) => d, - expr::Ignore => alloc_ty(bcx, tcx.mk_mut_ptr(tcx.types.i8), - "try_result"), - }; - - // do the invoke - bcx = try_intrinsic(bcx, func.val, data.val, local_ptr.val, dest, - call_debug_location); - - fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope); - return Result::new(bcx, dest); - } else { - ccx.sess().bug("expected two exprs as arguments for \ - `try` intrinsic"); - } - } - // save the actual AST arguments for later (some places need to do // const-evaluation on them) let expr_arguments = match args { @@ -446,6 +409,11 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>, (Some(llfn), _) => { Call(bcx, llfn, &llargs, call_debug_location) } + (_, "try") => { + bcx = try_intrinsic(bcx, llargs[0], llargs[1], llargs[2], llresult, + call_debug_location); + C_nil(ccx) + } (_, "breakpoint") => { let llfn = ccx.get_intrinsic(&("llvm.debugtrap")); Call(bcx, llfn, &[], call_debug_location)