Skip to content

Commit dcd3168

Browse files
committed
Use correct sign extension on __powi*f2 arguments
1 parent 3ab6af0 commit dcd3168

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/abi/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,3 +828,31 @@ pub(crate) fn codegen_drop<'tcx>(
828828
}
829829
}
830830
}
831+
832+
pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam {
833+
let param = AbiParam::new(ty);
834+
if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size.bits() {
835+
match (&*tcx.sess.target.arch, &*tcx.sess.target.vendor) {
836+
("x86_64", _) | ("aarch64", "apple") => match (ty, is_signed) {
837+
(types::I8 | types::I16, true) => param.sext(),
838+
(types::I8 | types::I16, false) => param.uext(),
839+
_ => param,
840+
},
841+
("aarch64", _) => param,
842+
("riscv64", _) => match (ty, is_signed) {
843+
(types::I32, _) | (_, true) => param.sext(),
844+
_ => param.uext(),
845+
},
846+
("s390x", _) => {
847+
if is_signed {
848+
param.sext()
849+
} else {
850+
param.uext()
851+
}
852+
}
853+
_ => unimplemented!("{:?}", tcx.sess.target.arch),
854+
}
855+
} else {
856+
param
857+
}
858+
}

src/intrinsics/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ fn codegen_float_intrinsic_call<'tcx>(
416416
// These intrinsics aren't supported natively by Cranelift.
417417
// Lower them to a libcall.
418418
sym::powif32 | sym::powif64 => {
419-
let input_tys: Vec<_> = vec![AbiParam::new(clif_ty), AbiParam::new(types::I32)];
419+
let input_tys: Vec<_> =
420+
vec![AbiParam::new(clif_ty), lib_call_arg_param(fx.tcx, types::I32, true)];
420421
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0];
421422
CValue::by_val(ret_val, fx.layout_of(ty))
422423
}

0 commit comments

Comments
 (0)