Skip to content

Commit

Permalink
x86-32 float return for 'Rust' ABI: treat all float types consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 18, 2024
1 parent d9c4b8d commit 7b06c64
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::iter;

use rustc_abi::Float::*;
use rustc_abi::Primitive::{Float, Pointer};
use rustc_abi::{Abi, AddressSpace, PointerKind, Scalar, Size};
use rustc_hir as hir;
Expand Down Expand Up @@ -702,30 +701,19 @@ fn fn_abi_adjust_for_abi<'tcx>(
// change their ABIs.
&& abi != SpecAbi::RustIntrinsic
{
match arg.layout.abi {
// Handle similar to the way arguments with an `Abi::Aggregate` abi are handled
// below, by returning arguments up to the size of a pointer (32 bits on x86)
// cast to an appropriately sized integer.
Abi::Scalar(s) if s.primitive() == Float(F32) => {
// Same size as a pointer, return in a register.
arg.cast_to(Reg::i32());
return;
}
Abi::Scalar(s) if s.primitive() == Float(F64) => {
// Larger than a pointer, return indirectly.
arg.make_indirect();
return;
}
Abi::ScalarPair(s1, s2)
if matches!(s1.primitive(), Float(F32 | F64))
|| matches!(s2.primitive(), Float(F32 | F64)) =>
{
let has_float = matches!(arg.layout.abi, Abi::Scalar(s) if matches!(s.primitive(), Float(_)))
|| matches!(arg.layout.abi, Abi::ScalarPair(s1, s2)
if matches!(s1.primitive(), Float(_)) || matches!(s2.primitive(), Float(_)));
if has_float {
if arg.layout.size <= Pointer(AddressSpace::DATA).size(cx) {
// Same size or smaller than pointer, return in a register.
arg.cast_to(Reg { kind: RegKind::Integer, size: arg.layout.size });
} else {
// Larger than a pointer, return indirectly.
arg.make_indirect();
return;
}
_ => {}
};
return;
}
}

match arg.layout.abi {
Expand Down

0 comments on commit 7b06c64

Please sign in to comment.