Skip to content

Commit eaaa03f

Browse files
committed
default Aggregate ABI to Indirect, and make sure it's never used for unsized
1 parent 405e420 commit eaaa03f

File tree

16 files changed

+124
-23
lines changed

16 files changed

+124
-23
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ where
4040
Ty: TyAbiInterface<'a, C> + Copy,
4141
C: HasDataLayout,
4242
{
43+
if !ret.layout.is_sized() {
44+
// Not touching this...
45+
return;
46+
}
4347
if !ret.layout.is_aggregate() {
4448
if kind == AbiKind::DarwinPCS {
4549
// On Darwin, when returning an i8/i16, it must be sign-extended to 32 bits,
@@ -67,6 +71,10 @@ where
6771
Ty: TyAbiInterface<'a, C> + Copy,
6872
C: HasDataLayout,
6973
{
74+
if !arg.layout.is_sized() {
75+
// Not touching this...
76+
return;
77+
}
7078
if !arg.layout.is_aggregate() {
7179
if kind == AbiKind::DarwinPCS {
7280
// On Darwin, when passing an i8/i16, it must be sign-extended to 32 bits,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ where
3030
Ty: TyAbiInterface<'a, C> + Copy,
3131
C: HasDataLayout,
3232
{
33+
if !ret.layout.is_sized() {
34+
// Not touching this...
35+
return;
36+
}
3337
if !ret.layout.is_aggregate() {
3438
ret.extend_integer_width_to(32);
3539
return;
@@ -56,6 +60,10 @@ where
5660
Ty: TyAbiInterface<'a, C> + Copy,
5761
C: HasDataLayout,
5862
{
63+
if !arg.layout.is_sized() {
64+
// Not touching this...
65+
return;
66+
}
5967
if !arg.layout.is_aggregate() {
6068
arg.extend_integer_width_to(32);
6169
return;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u6
152152
where
153153
Ty: TyAbiInterface<'a, C> + Copy,
154154
{
155+
if !arg.layout.is_sized() {
156+
// Not touching this...
157+
return false; // I guess? return value of this function is not documented
158+
}
155159
if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) {
156160
match conv {
157161
FloatConv::Float(f) => {
@@ -214,6 +218,10 @@ fn classify_arg<'a, Ty, C>(
214218
) where
215219
Ty: TyAbiInterface<'a, C> + Copy,
216220
{
221+
if !arg.layout.is_sized() {
222+
// Not touching this...
223+
return;
224+
}
217225
if !is_vararg {
218226
match should_use_fp_conv(cx, &arg.layout, xlen, flen) {
219227
Some(FloatConv::Float(f)) if *avail_fprs >= 1 => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ fn classify_arg<Ty, C>(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size)
1717
where
1818
C: HasDataLayout,
1919
{
20+
if !arg.layout.is_sized() {
21+
// Not touching this...
22+
return;
23+
}
2024
let dl = cx.data_layout();
2125
let size = arg.layout.size;
2226
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align).abi;

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
422422
}))
423423
}
424424

425-
Abi::ScalarPair(..) | Abi::Aggregate { .. } => {
425+
Abi::ScalarPair(..) | Abi::Aggregate { sized: true } => {
426426
// Helper for computing `homogeneous_aggregate`, allowing a custom
427427
// starting offset (used below for handling variants).
428428
let from_fields_at =
@@ -520,6 +520,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
520520
Ok(result)
521521
}
522522
}
523+
Abi::Aggregate { sized: false } => Err(Heterogeneous),
523524
}
524525
}
525526
}
@@ -555,8 +556,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
555556
scalar_attrs(&layout, b, a.size(cx).align_to(b.align(cx).abi)),
556557
),
557558
Abi::Vector { .. } => PassMode::Direct(ArgAttributes::new()),
558-
// The `Aggregate` ABI should always be adjusted later.
559-
Abi::Aggregate { .. } => PassMode::Direct(ArgAttributes::new()),
559+
Abi::Aggregate { .. } => Self::indirect_pass_mode(&layout),
560560
};
561561
ArgAbi { layout, mode }
562562
}
@@ -580,10 +580,20 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
580580
PassMode::Indirect { attrs, meta_attrs, on_stack: false }
581581
}
582582

583+
/// Pass this argument directly instead. Should NOT be used!
584+
/// Only exists because of past ABI mistakes that will take time to fix
585+
/// (see <https://github.com/rust-lang/rust/issues/115666>).
586+
pub fn make_direct_deprecated(&mut self) {
587+
self.mode = PassMode::Direct(ArgAttributes::new());
588+
}
589+
583590
pub fn make_indirect(&mut self) {
584591
match self.mode {
585592
PassMode::Direct(_) | PassMode::Pair(_, _) => {}
586-
PassMode::Indirect { attrs: _, meta_attrs: None, on_stack: false } => return,
593+
PassMode::Indirect { attrs: _, meta_attrs: _, on_stack: false } => {
594+
// already indirect
595+
return;
596+
}
587597
_ => panic!("Tried to make {:?} indirect", self.mode),
588598
}
589599

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@ use crate::abi::{HasDataLayout, TyAbiInterface};
44
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
55
if ret.layout.is_aggregate() && ret.layout.size.bits() > 64 {
66
ret.make_indirect();
7+
} else {
8+
// FIXME: this is wrong! Need to decide which ABI we really want here.
9+
ret.make_direct_deprecated();
710
}
811
}
912

1013
fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
1114
if arg.layout.is_aggregate() && arg.layout.size.bits() > 64 {
1215
arg.make_indirect();
16+
} else {
17+
// FIXME: this is wrong! Need to decide which ABI we really want here.
18+
arg.make_direct_deprecated();
1319
}
1420
}
1521

@@ -30,6 +36,9 @@ where
3036
_ => unreachable!("Align is given as power of 2 no larger than 16 bytes"),
3137
};
3238
arg.cast_to(Uniform { unit, total: Size::from_bytes(2 * align_bytes) });
39+
} else {
40+
// FIXME: find a better way to do this. See https://github.com/rust-lang/rust/issues/117271.
41+
arg.make_direct_deprecated();
3342
}
3443
}
3544

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ where
4646
Ty: TyAbiInterface<'a, C> + Copy,
4747
C: HasDataLayout,
4848
{
49+
if !ret.layout.is_sized() {
50+
// Not touching this...
51+
return;
52+
}
4953
if !ret.layout.is_aggregate() {
5054
ret.extend_integer_width_to(64);
5155
return;
@@ -89,6 +93,10 @@ where
8993
Ty: TyAbiInterface<'a, C> + Copy,
9094
C: HasDataLayout,
9195
{
96+
if !arg.layout.is_sized() {
97+
// Not touching this...
98+
return;
99+
}
92100
if !arg.layout.is_aggregate() {
93101
arg.extend_integer_width_to(64);
94102
return;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ fn classify_ret<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, xlen: u64, flen: u6
158158
where
159159
Ty: TyAbiInterface<'a, C> + Copy,
160160
{
161+
if !arg.layout.is_sized() {
162+
// Not touching this...
163+
return false; // I guess? return value of this function is not documented
164+
}
161165
if let Some(conv) = should_use_fp_conv(cx, &arg.layout, xlen, flen) {
162166
match conv {
163167
FloatConv::Float(f) => {
@@ -220,6 +224,10 @@ fn classify_arg<'a, Ty, C>(
220224
) where
221225
Ty: TyAbiInterface<'a, C> + Copy,
222226
{
227+
if !arg.layout.is_sized() {
228+
// Not touching this...
229+
return;
230+
}
223231
if !is_vararg {
224232
match should_use_fp_conv(cx, &arg.layout, xlen, flen) {
225233
Some(FloatConv::Float(f)) if *avail_fprs >= 1 => {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ where
1717
Ty: TyAbiInterface<'a, C> + Copy,
1818
C: HasDataLayout,
1919
{
20+
if !arg.layout.is_sized() {
21+
// Not touching this...
22+
return;
23+
}
2024
if !arg.layout.is_aggregate() && arg.layout.size.bits() <= 64 {
2125
arg.extend_integer_width_to(64);
2226
return;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ fn classify_arg<Ty, C>(cx: &C, arg: &mut ArgAbi<'_, Ty>, offset: &mut Size)
1717
where
1818
C: HasDataLayout,
1919
{
20+
if !arg.layout.is_sized() {
21+
// Not touching this...
22+
return;
23+
}
2024
let dl = cx.data_layout();
2125
let size = arg.layout.size;
2226
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align).abi;

0 commit comments

Comments
 (0)