Skip to content

Commit a38873d

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

File tree

1 file changed

+13
-21
lines changed
  • compiler/rustc_ty_utils/src

1 file changed

+13
-21
lines changed

compiler/rustc_ty_utils/src/abi.rs

+13-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
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;
@@ -702,30 +701,23 @@ fn fn_abi_adjust_for_abi<'tcx>(
702701
// change their ABIs.
703702
&& abi != SpecAbi::RustIntrinsic
704703
{
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;
704+
let has_float = match arg.layout.abi {
705+
Abi::Scalar(s) => matches!(s.primitive(), Float(_)),
706+
Abi::ScalarPair(s1, s2) => {
707+
matches!(s1.primitive(), Float(_)) || matches!(s2.primitive(), Float(_))
713708
}
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-
{
709+
_ => false,
710+
};
711+
if has_float {
712+
if arg.layout.size <= Pointer(AddressSpace::DATA).size(cx) {
713+
// Same size or smaller than pointer, return in a register.
714+
arg.cast_to(Reg { kind: RegKind::Integer, size: arg.layout.size });
715+
} else {
723716
// Larger than a pointer, return indirectly.
724717
arg.make_indirect();
725-
return;
726718
}
727-
_ => {}
728-
};
719+
return;
720+
}
729721
}
730722

731723
match arg.layout.abi {

0 commit comments

Comments
 (0)