Skip to content

Commit f4a2193

Browse files
committed
x86-32 float return for 'Rust' ABI: treat all float types consistently
1 parent d9c4b8d commit f4a2193

File tree

1 file changed

+11
-22
lines changed
  • compiler/rustc_ty_utils/src

1 file changed

+11
-22
lines changed

compiler/rustc_ty_utils/src/abi.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use std::iter;
22

3-
use rustc_abi::Float::*;
43
use rustc_abi::Primitive::{Float, Pointer};
54
use rustc_abi::{Abi, AddressSpace, PointerKind, Scalar, Size};
65
use rustc_hir as hir;
76
use rustc_hir::lang_items::LangItem;
87
use rustc_middle::bug;
8+
use rustc_middle::mir::interpret::PointerArithmetic;
99
use rustc_middle::query::Providers;
1010
use rustc_middle::ty::layout::{
1111
FnAbiError, HasParamEnv, HasTyCtxt, LayoutCx, LayoutOf, TyAndLayout, fn_can_unwind,
@@ -702,30 +702,19 @@ fn fn_abi_adjust_for_abi<'tcx>(
702702
// change their ABIs.
703703
&& abi != SpecAbi::RustIntrinsic
704704
{
705-
match arg.layout.abi {
706-
// Handle similar to the way arguments with an `Abi::Aggregate` abi are handled
707-
// below, by returning arguments up to the size of a pointer (32 bits on x86)
708-
// cast to an appropriately sized integer.
709-
Abi::Scalar(s) if s.primitive() == Float(F32) => {
710-
// Same size as a pointer, return in a register.
711-
arg.cast_to(Reg::i32());
712-
return;
713-
}
714-
Abi::Scalar(s) if s.primitive() == Float(F64) => {
715-
// Larger than a pointer, return indirectly.
716-
arg.make_indirect();
717-
return;
718-
}
719-
Abi::ScalarPair(s1, s2)
720-
if matches!(s1.primitive(), Float(F32 | F64))
721-
|| matches!(s2.primitive(), Float(F32 | F64)) =>
722-
{
705+
let has_float = matches!(arg.layout.abi, Abi::Scalar(s) if matches!(s.primitive(), Float(_)))
706+
|| matches!(arg.layout.abi, Abi::ScalarPair(s1, s2)
707+
if matches!(s1.primitive(), Float(_)) || matches!(s2.primitive(), Float(_)));
708+
if has_float {
709+
if arg.layout.size <= tcx.pointer_size() {
710+
// Same size or smaller than pointer, return in a register.
711+
arg.cast_to(Reg { kind: RegKind::Integer, size: arg.layout.size });
712+
} else {
723713
// Larger than a pointer, return indirectly.
724714
arg.make_indirect();
725-
return;
726715
}
727-
_ => {}
728-
};
716+
return;
717+
}
729718
}
730719

731720
match arg.layout.abi {

0 commit comments

Comments
 (0)