diff --git a/compiler/rustc_target/src/callconv/mips64.rs b/compiler/rustc_target/src/callconv/mips64.rs index e444e605d3b..72c02f6dc04 100644 --- a/compiler/rustc_target/src/callconv/mips64.rs +++ b/compiler/rustc_target/src/callconv/mips64.rs @@ -118,6 +118,19 @@ where if !arg.layout.is_aggregate() { extend_integer_width_mips(arg, 64); + + // We always pad with an integer, even if the primitive is a float. This + // conflicts with our reading of the specification, which would require + // padding floats with floats and integers with integers. + // However, this implementation is consistent with GCC, which means we + // are compatible with the de-facto ABI on the platform. + if let BackendRepr::Scalar(scalar) = arg.layout.backend_repr { + let kind = match scalar.primitive() { + Primitive::Int(_, _) | Primitive::Pointer(_) => RegKind::Integer, + Primitive::Float(_) => RegKind::Float, + }; + arg.cast_to_and_pad_i32(CastTarget::from(Reg { kind, size }), pad_i32); + } } else if arg.layout.pass_indirectly_in_non_rustic_abis(cx) { arg.make_indirect(); } else if let Some(component) = arg.layout.complex_number(cx) diff --git a/tests/codegen-llvm/mips64-abi/register-alignment.rs b/tests/codegen-llvm/mips64-abi/register-alignment.rs new file mode 100644 index 00000000000..e7db7e2c05d --- /dev/null +++ b/tests/codegen-llvm/mips64-abi/register-alignment.rs @@ -0,0 +1,33 @@ +//@ add-minicore +//@ compile-flags: -Copt-level=3 +// +//@ revisions: mips64 mips64el +//@[mips64] compile-flags: --target mips64-unknown-linux-gnuabi64 +//@[mips64el] compile-flags: --target mips64el-unknown-linux-gnuabi64 +// +//@ needs-llvm-components: mips + +// Test that 16-byte scalars are correctly aligned in registers. + +#![feature(f128, lang_items, no_core)] +#![crate_type = "lib"] +#![no_core] + +extern crate minicore; +use minicore::*; + +// CHECK: @i128_gets_aligned(i8 %0, i32 %1, i128 %2) +#[no_mangle] +extern "C" fn i128_gets_aligned(arg0: u8, arg1: i128) {} + +// CHECK: @i128_is_aligned(i8 %0, i16 %1, i128 %2) +#[no_mangle] +extern "C" fn i128_is_aligned(arg0: u8, arg1: i16, arg2: i128) {} + +// CHECK: @f128_gets_aligned(i8 %0, i32 %1, fp128 %2) +#[no_mangle] +extern "C" fn f128_gets_aligned(arg0: u8, arg1: f128) {} + +// CHECK: @f128_is_aligned(i8 %0, float %1, fp128 %2) +#[no_mangle] +extern "C" fn f128_is_aligned(arg0: u8, arg1: f32, arg2: f128) {}