Skip to content

Commit 8d3f80b

Browse files
committed
Auto merge of #130450 - workingjubilee:these-names-are-indirect, r=bjorn3
Reduce confusion about `make_indirect_byval` by renaming it As part of doing so, remove the incorrect handling of the wasm target's `make_indirect_byval` (i.e. using it at all).
2 parents 28e8f01 + 30be609 commit 8d3f80b

File tree

9 files changed

+118
-37
lines changed

9 files changed

+118
-37
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn classify_arg<Ty>(arg: &mut ArgAbi<'_, Ty>) {
1414
return;
1515
}
1616
if arg.layout.is_aggregate() {
17-
arg.make_indirect_byval(None);
17+
arg.pass_by_stack_offset(None);
1818
} else {
1919
arg.extend_integer_width_to(32);
2020
}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub enum PassMode {
6464
/// (which ensures that padding is preserved and that we do not rely on LLVM's struct layout),
6565
/// and will use the alignment specified in `attrs.pointee_align` (if `Some`) or the type's
6666
/// alignment (if `None`). This means that the alignment will not always
67-
/// match the Rust type's alignment; see documentation of `make_indirect_byval` for more info.
67+
/// match the Rust type's alignment; see documentation of `pass_by_stack_offset` for more info.
6868
///
6969
/// `on_stack` cannot be true for unsized arguments, i.e., when `meta_attrs` is `Some`.
7070
Indirect { attrs: ArgAttributes, meta_attrs: Option<ArgAttributes>, on_stack: bool },
@@ -681,7 +681,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
681681
/// either in the caller (if the type's alignment is lower than the byval alignment)
682682
/// or in the callee (if the type's alignment is higher than the byval alignment),
683683
/// to ensure that Rust code never sees an underaligned pointer.
684-
pub fn make_indirect_byval(&mut self, byval_align: Option<Align>) {
684+
pub fn pass_by_stack_offset(&mut self, byval_align: Option<Align>) {
685685
assert!(!self.layout.is_unsized(), "used byval ABI for unsized layout");
686686
self.make_indirect();
687687
match self.mode {
@@ -879,8 +879,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
879879
{
880880
if abi == spec::abi::Abi::X86Interrupt {
881881
if let Some(arg) = self.args.first_mut() {
882-
// FIXME(pcwalton): This probably should use the x86 `byval` ABI...
883-
arg.make_indirect_byval(None);
882+
arg.pass_by_stack_offset(None);
884883
}
885884
return Ok(());
886885
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ where
4040
}
4141
arg.extend_integer_width_to(32);
4242
if arg.layout.is_aggregate() && !unwrap_trivial_aggregate(cx, arg) {
43-
arg.make_indirect_byval(None);
43+
arg.make_indirect();
4444
}
4545
}
4646

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ where
122122
align_4
123123
};
124124

125-
arg.make_indirect_byval(Some(byval_align));
125+
arg.pass_by_stack_offset(Some(byval_align));
126126
} else {
127127
arg.extend_integer_width_to(32);
128128
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ where
219219
if is_arg {
220220
// The x86_64 ABI doesn't have any special requirements for `byval` alignment,
221221
// the type's alignment is always used.
222-
arg.make_indirect_byval(None);
222+
arg.pass_by_stack_offset(None);
223223
} else {
224224
// `sret` parameter thus one less integer register available
225225
arg.make_indirect();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where
6868
*arg_gprs_left -= needed_arg_gprs;
6969

7070
if must_use_stack {
71-
arg.make_indirect_byval(None);
71+
arg.pass_by_stack_offset(None);
7272
} else if is_xtensa_aggregate(arg) {
7373
// Aggregates which are <= max_size will be passed in
7474
// registers if possible, so coerce to integers.

tests/codegen/align-byval.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
//@[m68k] compile-flags: --target m68k-unknown-linux-gnu
55
//@[m68k] needs-llvm-components: m68k
6-
//@[wasm] compile-flags: --target wasm32-unknown-emscripten
7-
//@[wasm] needs-llvm-components: webassembly
86
//@[x86_64-linux] compile-flags: --target x86_64-unknown-linux-gnu
97
//@[x86_64-linux] needs-llvm-components: x86
108
//@[x86_64-windows] compile-flags: --target x86_64-pc-windows-msvc
@@ -15,7 +13,7 @@
1513
//@[i686-windows] needs-llvm-components: x86
1614

1715
// Tests that `byval` alignment is properly specified (#80127).
18-
// The only targets that use `byval` are m68k, wasm, x86-64, and x86.
16+
// The only targets that use `byval` are m68k, x86-64, and x86.
1917
// Note also that Windows mandates a by-ref ABI here, so it does not use byval.
2018

2119
#![feature(no_core, lang_items)]
@@ -112,9 +110,6 @@ pub unsafe fn call_na1(x: NaturalAlign1) {
112110
// m68k: [[ALLOCA:%[a-z0-9+]]] = alloca [2 x i8], align 1
113111
// m68k: call void @natural_align_1({{.*}}byval([2 x i8]) align 1{{.*}} [[ALLOCA]])
114112

115-
// wasm: [[ALLOCA:%[a-z0-9+]]] = alloca [2 x i8], align 1
116-
// wasm: call void @natural_align_1({{.*}}byval([2 x i8]) align 1{{.*}} [[ALLOCA]])
117-
118113
// x86_64-linux: call void @natural_align_1(i16
119114

120115
// x86_64-windows: call void @natural_align_1(i16
@@ -133,7 +128,6 @@ pub unsafe fn call_na2(x: NaturalAlign2) {
133128
// CHECK: start:
134129

135130
// m68k-NEXT: call void @natural_align_2
136-
// wasm-NEXT: call void @natural_align_2
137131
// x86_64-linux-NEXT: call void @natural_align_2
138132
// x86_64-windows-NEXT: call void @natural_align_2
139133

@@ -204,8 +198,6 @@ pub unsafe fn call_fa16(x: ForceAlign16) {
204198
extern "C" {
205199
// m68k: declare void @natural_align_1({{.*}}byval([2 x i8]) align 1{{.*}})
206200

207-
// wasm: declare void @natural_align_1({{.*}}byval([2 x i8]) align 1{{.*}})
208-
209201
// x86_64-linux: declare void @natural_align_1(i16)
210202

211203
// x86_64-windows: declare void @natural_align_1(i16)
@@ -217,8 +209,6 @@ extern "C" {
217209

218210
// m68k: declare void @natural_align_2({{.*}}byval([34 x i8]) align 2{{.*}})
219211

220-
// wasm: declare void @natural_align_2({{.*}}byval([34 x i8]) align 2{{.*}})
221-
222212
// x86_64-linux: declare void @natural_align_2({{.*}}byval([34 x i8]) align 2{{.*}})
223213

224214
// x86_64-windows: declare void @natural_align_2(
@@ -232,8 +222,6 @@ extern "C" {
232222

233223
// m68k: declare void @force_align_4({{.*}}byval([20 x i8]) align 4{{.*}})
234224

235-
// wasm: declare void @force_align_4({{.*}}byval([20 x i8]) align 4{{.*}})
236-
237225
// x86_64-linux: declare void @force_align_4({{.*}}byval([20 x i8]) align 4{{.*}})
238226

239227
// x86_64-windows: declare void @force_align_4(
@@ -247,8 +235,6 @@ extern "C" {
247235

248236
// m68k: declare void @natural_align_8({{.*}}byval([24 x i8]) align 4{{.*}})
249237

250-
// wasm: declare void @natural_align_8({{.*}}byval([24 x i8]) align 8{{.*}})
251-
252238
// x86_64-linux: declare void @natural_align_8({{.*}}byval([24 x i8]) align 8{{.*}})
253239

254240
// x86_64-windows: declare void @natural_align_8(
@@ -262,8 +248,6 @@ extern "C" {
262248

263249
// m68k: declare void @force_align_8({{.*}}byval([24 x i8]) align 8{{.*}})
264250

265-
// wasm: declare void @force_align_8({{.*}}byval([24 x i8]) align 8{{.*}})
266-
267251
// x86_64-linux: declare void @force_align_8({{.*}}byval([24 x i8]) align 8{{.*}})
268252

269253
// x86_64-windows: declare void @force_align_8(
@@ -279,8 +263,6 @@ extern "C" {
279263

280264
// m68k: declare void @lower_fa8({{.*}}byval([24 x i8]) align 4{{.*}})
281265

282-
// wasm: declare void @lower_fa8({{.*}}byval([24 x i8]) align 8{{.*}})
283-
284266
// x86_64-linux: declare void @lower_fa8({{.*}}byval([24 x i8]) align 8{{.*}})
285267

286268
// x86_64-windows: declare void @lower_fa8(
@@ -294,8 +276,6 @@ extern "C" {
294276

295277
// m68k: declare void @wrapped_fa8({{.*}}byval([24 x i8]) align 8{{.*}})
296278

297-
// wasm: declare void @wrapped_fa8({{.*}}byval([24 x i8]) align 8{{.*}})
298-
299279
// x86_64-linux: declare void @wrapped_fa8({{.*}}byval([24 x i8]) align 8{{.*}})
300280

301281
// x86_64-windows: declare void @wrapped_fa8(
@@ -311,8 +291,6 @@ extern "C" {
311291

312292
// m68k: declare void @transparent_fa8({{.*}}byval([24 x i8]) align 8{{.*}})
313293

314-
// wasm: declare void @transparent_fa8({{.*}}byval([24 x i8]) align 8{{.*}})
315-
316294
// x86_64-linux: declare void @transparent_fa8({{.*}}byval([24 x i8]) align 8{{.*}})
317295

318296
// x86_64-windows: declare void @transparent_fa8(
@@ -328,8 +306,6 @@ extern "C" {
328306

329307
// m68k: declare void @force_align_16({{.*}}byval([80 x i8]) align 16{{.*}})
330308

331-
// wasm: declare void @force_align_16({{.*}}byval([80 x i8]) align 16{{.*}})
332-
333309
// x86_64-linux: declare void @force_align_16({{.*}}byval([80 x i8]) align 16{{.*}})
334310

335311
// x86_64-windows: declare void @force_align_16(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
//@ revisions: wasm32
2+
//@ compile-flags: -O -C no-prepopulate-passes
3+
4+
//@[wasm32] compile-flags: --target wasm32-wasi
5+
//@[wasm32] needs-llvm-components: webassembly
6+
7+
// See ./transparent.rs
8+
// Some platforms pass large aggregates using immediate arrays in LLVMIR
9+
// Other platforms pass large aggregates using struct pointer in LLVMIR
10+
// This covers the "struct pointer" case, except without "byval".
11+
12+
#![feature(no_core, lang_items, transparent_unions)]
13+
#![crate_type = "lib"]
14+
#![no_std]
15+
#![no_core]
16+
17+
#[lang = "sized"]
18+
trait Sized {}
19+
#[lang = "freeze"]
20+
trait Freeze {}
21+
#[lang = "copy"]
22+
trait Copy {}
23+
24+
impl Copy for [u32; 16] {}
25+
impl Copy for BigS {}
26+
impl Copy for BigU {}
27+
28+
#[repr(C)]
29+
pub struct BigS([u32; 16]);
30+
31+
#[repr(transparent)]
32+
pub struct TsBigS(BigS);
33+
34+
#[repr(transparent)]
35+
pub union TuBigS {
36+
field: BigS,
37+
}
38+
39+
#[repr(transparent)]
40+
pub enum TeBigS {
41+
Variant(BigS),
42+
}
43+
44+
// CHECK: define{{.*}}void @test_BigS(ptr [[BIGS_RET_ATTRS1:.*]] sret([64 x i8]) [[BIGS_RET_ATTRS2:.*]], ptr [[BIGS_ARG_ATTRS1:.*]] [[BIGS_ARG_ATTRS2:.*]])
45+
#[no_mangle]
46+
pub extern "C" fn test_BigS(_: BigS) -> BigS {
47+
loop {}
48+
}
49+
50+
// CHECK: define{{.*}}void @test_TsBigS(ptr [[BIGS_RET_ATTRS1]] sret([64 x i8]) [[BIGS_RET_ATTRS2]], ptr [[BIGS_ARG_ATTRS1]] [[BIGS_ARG_ATTRS2:.*]])
51+
#[no_mangle]
52+
pub extern "C" fn test_TsBigS(_: TsBigS) -> TsBigS {
53+
loop {}
54+
}
55+
56+
// CHECK: define{{.*}}void @test_TuBigS(ptr [[BIGS_RET_ATTRS1]] sret([64 x i8]) [[BIGS_RET_ATTRS2]], ptr [[BIGS_ARG_ATTRS1]] [[BIGS_ARG_ATTRS2:.*]])
57+
#[no_mangle]
58+
pub extern "C" fn test_TuBigS(_: TuBigS) -> TuBigS {
59+
loop {}
60+
}
61+
62+
// CHECK: define{{.*}}void @test_TeBigS(ptr [[BIGS_RET_ATTRS1]] sret([64 x i8]) [[BIGS_RET_ATTRS2]], ptr [[BIGS_ARG_ATTRS1]] [[BIGS_ARG_ATTRS2]])
63+
#[no_mangle]
64+
pub extern "C" fn test_TeBigS(_: TeBigS) -> TeBigS {
65+
loop {}
66+
}
67+
68+
#[repr(C)]
69+
pub union BigU {
70+
foo: [u32; 16],
71+
}
72+
73+
#[repr(transparent)]
74+
pub struct TsBigU(BigU);
75+
76+
#[repr(transparent)]
77+
pub union TuBigU {
78+
field: BigU,
79+
}
80+
81+
#[repr(transparent)]
82+
pub enum TeBigU {
83+
Variant(BigU),
84+
}
85+
86+
// CHECK: define{{.*}}void @test_BigU(ptr [[BIGU_RET_ATTRS1:.*]] sret([64 x i8]) [[BIGU_RET_ATTRS2:.*]], ptr [[BIGU_ARG_ATTRS1:.*]] [[BIGU_ARG_ATTRS2:.*]])
87+
#[no_mangle]
88+
pub extern "C" fn test_BigU(_: BigU) -> BigU {
89+
loop {}
90+
}
91+
92+
// CHECK: define{{.*}}void @test_TsBigU(ptr [[BIGU_RET_ATTRS1:.*]] sret([64 x i8]) [[BIGU_RET_ATTRS2:.*]], ptr [[BIGU_ARG_ATTRS1]] [[BIGU_ARG_ATTRS2]])
93+
#[no_mangle]
94+
pub extern "C" fn test_TsBigU(_: TsBigU) -> TsBigU {
95+
loop {}
96+
}
97+
98+
// CHECK: define{{.*}}void @test_TuBigU(ptr [[BIGU_RET_ATTRS1]] sret([64 x i8]) [[BIGU_RET_ATTRS2:.*]], ptr [[BIGU_ARG_ATTRS1]] [[BIGU_ARG_ATTRS2]])
99+
#[no_mangle]
100+
pub extern "C" fn test_TuBigU(_: TuBigU) -> TuBigU {
101+
loop {}
102+
}
103+
104+
// CHECK: define{{.*}}void @test_TeBigU(ptr [[BIGU_RET_ATTRS1]] sret([64 x i8]) [[BIGU_RET_ATTRS2:.*]], ptr [[BIGU_ARG_ATTRS1]] [[BIGU_ARG_ATTRS2]])
105+
#[no_mangle]
106+
pub extern "C" fn test_TeBigU(_: TeBigU) -> TeBigU {
107+
loop {}
108+
}

tests/codegen/repr/transparent-struct-ptr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ revisions: i686-linux i686-freebsd x64-linux x64-apple wasm32
1+
//@ revisions: i686-linux i686-freebsd x64-linux x64-apple
22
//@ compile-flags: -O -C no-prepopulate-passes
33

44
//@[i686-linux] compile-flags: --target i686-unknown-linux-gnu
@@ -9,8 +9,6 @@
99
//@[x64-linux] needs-llvm-components: x86
1010
//@[x64-apple] compile-flags: --target x86_64-apple-darwin
1111
//@[x64-apple] needs-llvm-components: x86
12-
//@[wasm32] compile-flags: --target wasm32-wasi
13-
//@[wasm32] needs-llvm-components: webassembly
1412

1513
// See ./transparent.rs
1614
// Some platforms pass large aggregates using immediate arrays in LLVMIR

0 commit comments

Comments
 (0)