Skip to content

Commit 9024a66

Browse files
committed
Use a C-safe return type for __rust_[ui]128_* overflowing intrinsics
Combined with [1], this will change the overflowing multiplication operations to return an `extern "C"`-safe type. Link: rust-lang/compiler-builtins#735 [1]
1 parent 76cb21a commit 9024a66

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/codegen_i128.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,22 @@ pub(crate) fn maybe_codegen_mul_checked<'tcx>(
7676
}
7777

7878
let is_signed = type_sign(lhs.layout().ty);
79-
80-
let out_ty = Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]);
81-
let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty));
79+
let oflow_out_place = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32));
8280
let param_types = vec![
83-
AbiParam::special(fx.pointer_type, ArgumentPurpose::StructReturn),
8481
AbiParam::new(types::I128),
8582
AbiParam::new(types::I128),
83+
AbiParam::special(fx.pointer_type, ArgumentPurpose::Normal),
8684
];
87-
let args = [out_place.to_ptr().get_addr(fx), lhs.load_scalar(fx), rhs.load_scalar(fx)];
88-
fx.lib_call(
85+
let args = [lhs.load_scalar(fx), rhs.load_scalar(fx), oflow_out_place.to_ptr().get_addr(fx)];
86+
let ret = fx.lib_call(
8987
if is_signed { "__rust_i128_mulo" } else { "__rust_u128_mulo" },
9088
param_types,
91-
vec![],
89+
vec![AbiParam::new(types::I128)],
9290
&args,
9391
);
94-
Some(out_place.to_cvalue(fx))
92+
let mul = ret[0];
93+
let oflow = oflow_out_place.to_cvalue(fx).load_scalar(fx);
94+
let oflow = clif_intcast(fx, oflow, types::I8, false);
95+
let layout = fx.layout_of(Ty::new_tup(fx.tcx, &[lhs.layout().ty, fx.tcx.types.bool]));
96+
Some(CValue::by_val_pair(mul, oflow, layout))
9597
}

src/compiler_builtins.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ builtin_functions! {
4343
fn __divti3(n: i128, d: i128) -> i128;
4444
fn __umodti3(n: u128, d: u128) -> u128;
4545
fn __modti3(n: i128, d: i128) -> i128;
46-
fn __rust_u128_mulo(a: u128, b: u128) -> (u128, bool);
46+
fn __rust_u128_mulo(a: u128, b: u128, oflow: &mut i32) -> u128;
4747

4848
// floats
4949
fn __floattisf(i: i128) -> f32;

0 commit comments

Comments
 (0)