Skip to content

Commit

Permalink
Use PassMode::Pair by default for Abi::ScalarPair for all abi's and i…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
bjorn3 committed Jan 23, 2021
1 parent 2bde7d2 commit da0309c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
29 changes: 13 additions & 16 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_target/src/abi/call/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}

Expand Down

0 comments on commit da0309c

Please sign in to comment.