Use PassMode::Pair by default for Abi::ScalarPair for all abi's and in return position

Abi::ScalarPair is only ever used for types that don't have a stable
layout anyway so this doesn't break any FFI. It does however reduce the
amount of special casing on the abi outside of the code responsible for
abi specific adjustments to the pass mode.
This commit is contained in:
bjorn3 2020-12-27 19:59:37 +01:00
parent 2bde7d21cc
commit da0309c711
2 changed files with 21 additions and 18 deletions

View File

@ -2794,22 +2794,19 @@ where
}
}
// FIXME(eddyb) other ABIs don't have logic for scalar pairs.
if !is_return && rust_abi {
if let Abi::ScalarPair(ref a, ref b) = arg.layout.abi {
let mut a_attrs = ArgAttributes::new();
let mut b_attrs = ArgAttributes::new();
adjust_for_rust_scalar(&mut a_attrs, a, arg.layout, Size::ZERO, false);
adjust_for_rust_scalar(
&mut b_attrs,
b,
arg.layout,
a.value.size(cx).align_to(b.value.align(cx).abi),
false,
);
arg.mode = PassMode::Pair(a_attrs, b_attrs);
return arg;
}
if let Abi::ScalarPair(ref a, ref b) = arg.layout.abi {
let mut a_attrs = ArgAttributes::new();
let mut b_attrs = ArgAttributes::new();
adjust_for_rust_scalar(&mut a_attrs, a, arg.layout, Size::ZERO, is_return);
adjust_for_rust_scalar(
&mut b_attrs,
b,
arg.layout,
a.value.size(cx).align_to(b.value.align(cx).abi),
is_return,
);
arg.mode = PassMode::Pair(a_attrs, b_attrs);
return arg;
}
if let Abi::Scalar(ref scalar) = arg.layout.abi {

View File

@ -439,7 +439,10 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
}
pub fn make_indirect(&mut self) {
assert_eq!(self.mode, PassMode::Direct(ArgAttributes::new()));
match self.mode {
PassMode::Direct(_) | PassMode::Pair(_, _) => {}
_ => panic!("Tried to make {:?} indirect", self.mode),
}
// Start with fresh attributes for the pointer.
let mut attrs = ArgAttributes::new();
@ -486,7 +489,10 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
}
pub fn cast_to<T: Into<CastTarget>>(&mut self, target: T) {
assert_eq!(self.mode, PassMode::Direct(ArgAttributes::new()));
match self.mode {
PassMode::Direct(_) | PassMode::Pair(_, _) => {}
_ => panic!("Tried to cast {:?} to {:?}", self.mode, target.into()),
}
self.mode = PassMode::Cast(target.into());
}