Skip to content

Commit 09e03d4

Browse files
Rollup merge of #156867 - scottmcm:WIP-no-alloca-for-catch-unwind, r=dianqk
Stop needing an alloca for `catch_unwind` Turns out these were all making `OperandValue::Immediate`s already -- the intrinsic always returns a primitive scalar -- so pretty easy to handle. cc rust-lang/rust#153250 rust-lang/compiler-team#970 While I was looking at it, I also "rustified" the intrinsic signature a bit: returning a `bool` and taking a generic pointee and `unsafe fn`s cleans up the call in `std` a bit without making the implementation in the backend any harder. r? dianqk
2 parents 2ad24e1 + a291dd0 commit 09e03d4

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/intrinsic/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
13641364
bx.call(fn_type, None, None, try_func, &[data], None, None);
13651365
// Return 0 unconditionally from the intrinsic call;
13661366
// we can never unwind.
1367-
OperandValue::Immediate(bx.const_i32(0)).store(bx, dest);
1367+
OperandValue::Immediate(bx.const_bool(false)).store(bx, dest);
13681368
} else {
13691369
if wants_msvc_seh(bx.sess()) {
13701370
unimplemented!();
@@ -1421,7 +1421,7 @@ fn codegen_gnu_try<'gcc, 'tcx>(
14211421
let current_block = bx.block;
14221422

14231423
bx.switch_to_block(then);
1424-
bx.ret(bx.const_i32(0));
1424+
bx.ret(bx.const_bool(false));
14251425

14261426
// Type indicator for the exception being thrown.
14271427
//
@@ -1435,7 +1435,7 @@ fn codegen_gnu_try<'gcc, 'tcx>(
14351435
let ptr = bx.cx.context.new_call(None, eh_pointer_builtin, &[zero]);
14361436
let catch_ty = bx.type_func(&[bx.type_i8p(), bx.type_i8p()], bx.type_void());
14371437
bx.call(catch_ty, None, None, catch_func, &[data, ptr], None, None);
1438-
bx.ret(bx.const_i32(1));
1438+
bx.ret(bx.const_bool(true));
14391439

14401440
// NOTE: the blocks must be filled before adding the try/catch, otherwise gcc will not
14411441
// generate a try/catch.
@@ -1468,7 +1468,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
14681468
// Define the type up front for the signature of the rust_try function.
14691469
let tcx = cx.tcx;
14701470
let i8p = Ty::new_mut_ptr(tcx, tcx.types.i8);
1471-
// `unsafe fn(*mut i8) -> ()`
1471+
// `unsafe fn(*mut Data) -> ()`
14721472
let try_fn_ty = Ty::new_fn_ptr(
14731473
tcx,
14741474
ty::Binder::dummy(tcx.mk_fn_sig_rust_abi(
@@ -1477,7 +1477,7 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
14771477
rustc_hir::Safety::Unsafe,
14781478
)),
14791479
);
1480-
// `unsafe fn(*mut i8, *mut i8) -> ()`
1480+
// `unsafe fn(*mut Data, *mut i8) -> ()`
14811481
let catch_fn_ty = Ty::new_fn_ptr(
14821482
tcx,
14831483
ty::Binder::dummy(tcx.mk_fn_sig_rust_abi(
@@ -1486,10 +1486,10 @@ fn get_rust_try_fn<'a, 'gcc, 'tcx>(
14861486
rustc_hir::Safety::Unsafe,
14871487
)),
14881488
);
1489-
// `unsafe fn(unsafe fn(*mut i8) -> (), *mut i8, unsafe fn(*mut i8, *mut i8) -> ()) -> i32`
1489+
// `unsafe fn(unsafe fn(*mut Data) -> (), *mut Data, unsafe fn(*mut Data, *mut i8) -> ()) -> bool`
14901490
let rust_fn_sig = ty::Binder::dummy(cx.tcx.mk_fn_sig_rust_abi(
14911491
[try_fn_ty, i8p, catch_fn_ty],
1492-
tcx.types.i32,
1492+
tcx.types.bool,
14931493
rustc_hir::Safety::Unsafe,
14941494
));
14951495
let rust_try = gen_fn(cx, "__rust_try", rust_fn_sig, codegen);

0 commit comments

Comments
 (0)