Skip to content

Commit da0309c

Browse files
committed
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.
1 parent 2bde7d2 commit da0309c

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

compiler/rustc_middle/src/ty/layout.rs

+13-16
Original file line numberDiff line numberDiff line change
@@ -2794,22 +2794,19 @@ where
27942794
}
27952795
}
27962796

2797-
// FIXME(eddyb) other ABIs don't have logic for scalar pairs.
2798-
if !is_return && rust_abi {
2799-
if let Abi::ScalarPair(ref a, ref b) = arg.layout.abi {
2800-
let mut a_attrs = ArgAttributes::new();
2801-
let mut b_attrs = ArgAttributes::new();
2802-
adjust_for_rust_scalar(&mut a_attrs, a, arg.layout, Size::ZERO, false);
2803-
adjust_for_rust_scalar(
2804-
&mut b_attrs,
2805-
b,
2806-
arg.layout,
2807-
a.value.size(cx).align_to(b.value.align(cx).abi),
2808-
false,
2809-
);
2810-
arg.mode = PassMode::Pair(a_attrs, b_attrs);
2811-
return arg;
2812-
}
2797+
if let Abi::ScalarPair(ref a, ref b) = arg.layout.abi {
2798+
let mut a_attrs = ArgAttributes::new();
2799+
let mut b_attrs = ArgAttributes::new();
2800+
adjust_for_rust_scalar(&mut a_attrs, a, arg.layout, Size::ZERO, is_return);
2801+
adjust_for_rust_scalar(
2802+
&mut b_attrs,
2803+
b,
2804+
arg.layout,
2805+
a.value.size(cx).align_to(b.value.align(cx).abi),
2806+
is_return,
2807+
);
2808+
arg.mode = PassMode::Pair(a_attrs, b_attrs);
2809+
return arg;
28132810
}
28142811

28152812
if let Abi::Scalar(ref scalar) = arg.layout.abi {

compiler/rustc_target/src/abi/call/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,10 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
439439
}
440440

441441
pub fn make_indirect(&mut self) {
442-
assert_eq!(self.mode, PassMode::Direct(ArgAttributes::new()));
442+
match self.mode {
443+
PassMode::Direct(_) | PassMode::Pair(_, _) => {}
444+
_ => panic!("Tried to make {:?} indirect", self.mode),
445+
}
443446

444447
// Start with fresh attributes for the pointer.
445448
let mut attrs = ArgAttributes::new();
@@ -486,7 +489,10 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
486489
}
487490

488491
pub fn cast_to<T: Into<CastTarget>>(&mut self, target: T) {
489-
assert_eq!(self.mode, PassMode::Direct(ArgAttributes::new()));
492+
match self.mode {
493+
PassMode::Direct(_) | PassMode::Pair(_, _) => {}
494+
_ => panic!("Tried to cast {:?} to {:?}", self.mode, target.into()),
495+
}
490496
self.mode = PassMode::Cast(target.into());
491497
}
492498

0 commit comments

Comments
 (0)