Skip to content

Commit 7e933b4

Browse files
repr(align) <= 4 should still be byval
1 parent 2591c30 commit 7e933b4

File tree

13 files changed

+120
-107
lines changed

13 files changed

+120
-107
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub trait LayoutCalculator {
4040
largest_niche,
4141
align,
4242
size,
43-
has_repr_align: false,
43+
repr_align: None,
4444
}
4545
}
4646

@@ -123,7 +123,7 @@ pub trait LayoutCalculator {
123123
largest_niche: None,
124124
align: dl.i8_align,
125125
size: Size::ZERO,
126-
has_repr_align: false,
126+
repr_align: None,
127127
}
128128
}
129129

@@ -424,7 +424,7 @@ pub trait LayoutCalculator {
424424
largest_niche,
425425
size,
426426
align,
427-
has_repr_align: repr.align.is_some(),
427+
repr_align: repr.align,
428428
};
429429

430430
Some(TmpLayout { layout, variants: variant_layouts })
@@ -694,7 +694,7 @@ pub trait LayoutCalculator {
694694
abi,
695695
align,
696696
size,
697-
has_repr_align: repr.align.is_some(),
697+
repr_align: repr.align,
698698
};
699699

700700
let tagged_layout = TmpLayout { layout: tagged_layout, variants: layout_variants };
@@ -813,7 +813,7 @@ pub trait LayoutCalculator {
813813
largest_niche: None,
814814
align,
815815
size: size.align_to(align.abi),
816-
has_repr_align: repr.align.is_some(),
816+
repr_align: repr.align,
817817
})
818818
}
819819
}
@@ -1111,9 +1111,9 @@ fn univariant(
11111111
abi = Abi::Uninhabited;
11121112
}
11131113

1114-
let has_repr_align = repr.align.is_some()
1115-
|| repr.transparent()
1116-
&& layout_of_single_non_zst_field.map_or(false, |l| l.has_repr_align());
1114+
let repr_align = repr.align.or_else(|| {
1115+
if repr.transparent() { layout_of_single_non_zst_field?.repr_align() } else { None }
1116+
});
11171117

11181118
Some(LayoutS {
11191119
variants: Variants::Single { index: FIRST_VARIANT },
@@ -1122,7 +1122,7 @@ fn univariant(
11221122
largest_niche,
11231123
align,
11241124
size,
1125-
has_repr_align,
1125+
repr_align,
11261126
})
11271127
}
11281128

compiler/rustc_abi/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,10 +1532,10 @@ pub struct LayoutS {
15321532
pub align: AbiAndPrefAlign,
15331533
pub size: Size,
15341534

1535-
/// True if the alignment was explicitly requested with `repr(align)`.
1535+
/// The alignment explicitly requested with `repr(align)`.
15361536
/// Only used on i686-windows, where the argument passing ABI is different when alignment is
1537-
/// requested, even if the requested alignment is equal to or less than the natural alignment.
1538-
pub has_repr_align: bool,
1537+
/// requested, even if the requested alignment is equal to the natural alignment.
1538+
pub repr_align: Option<Align>,
15391539
}
15401540

15411541
impl LayoutS {
@@ -1550,7 +1550,7 @@ impl LayoutS {
15501550
largest_niche,
15511551
size,
15521552
align,
1553-
has_repr_align: false,
1553+
repr_align: None,
15541554
}
15551555
}
15561556
}
@@ -1560,15 +1560,15 @@ impl fmt::Debug for LayoutS {
15601560
// This is how `Layout` used to print before it become
15611561
// `Interned<LayoutS>`. We print it like this to avoid having to update
15621562
// expected output in a lot of tests.
1563-
let LayoutS { size, align, abi, fields, largest_niche, variants, has_repr_align } = self;
1563+
let LayoutS { size, align, abi, fields, largest_niche, variants, repr_align } = self;
15641564
f.debug_struct("Layout")
15651565
.field("size", size)
15661566
.field("align", align)
15671567
.field("abi", abi)
15681568
.field("fields", fields)
15691569
.field("largest_niche", largest_niche)
15701570
.field("variants", variants)
1571-
.field("has_repr_align", has_repr_align)
1571+
.field("repr_align", repr_align)
15721572
.finish()
15731573
}
15741574
}
@@ -1609,8 +1609,8 @@ impl<'a> Layout<'a> {
16091609
self.0.0.size
16101610
}
16111611

1612-
pub fn has_repr_align(self) -> bool {
1613-
self.0.0.has_repr_align
1612+
pub fn repr_align(self) -> Option<Align> {
1613+
self.0.0.repr_align
16141614
}
16151615

16161616
/// Whether the layout is from a type that implements [`std::marker::PointerLike`].

compiler/rustc_codegen_cranelift/src/abi/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(super) fn add_local_place_comments<'tcx>(
8383
let rustc_target::abi::LayoutS {
8484
size,
8585
align,
86-
has_repr_align: _,
86+
repr_align: _,
8787
abi: _,
8888
variants: _,
8989
fields: _,

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ where
755755
largest_niche: None,
756756
align: tcx.data_layout.i8_align,
757757
size: Size::ZERO,
758-
has_repr_align: false,
758+
repr_align: None,
759759
})
760760
}
761761

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,19 @@ where
6363

6464
if t.is_like_msvc
6565
&& arg.layout.is_adt()
66-
&& arg.layout.has_repr_align
67-
&& arg.layout.align.abi > align_4
66+
&& let Some(repr_align) = arg.layout.repr_align
67+
&& repr_align > align_4
6868
{
6969
// MSVC has special rules for overaligned arguments: https://reviews.llvm.org/D72114.
7070
// Summarized here:
7171
// - Arguments with _requested_ alignment > 4 are passed indirectly.
7272
// - For backwards compatibility, arguments with natural alignment > 4 are still passed
7373
// on stack (via `byval`). For example, this includes `double`, `int64_t`,
7474
// and structs containing them, provided they lack an explicit alignment attribute.
75+
assert!(arg.layout.align.abi >= repr_align,
76+
"abi alignment {:?} less than requested alignment {repr_align:?}",
77+
arg.layout.align.abi,
78+
);
7579
arg.make_indirect();
7680
} else if arg.layout.is_aggregate() {
7781
// We need to compute the alignment of the `byval` argument. The rules can be found in

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn layout_of_uncached<'tcx>(
258258
largest_niche,
259259
align: element.align,
260260
size,
261-
has_repr_align: false,
261+
repr_align: None,
262262
})
263263
}
264264
ty::Slice(element) => {
@@ -270,7 +270,7 @@ fn layout_of_uncached<'tcx>(
270270
largest_niche: None,
271271
align: element.align,
272272
size: Size::ZERO,
273-
has_repr_align: false,
273+
repr_align: None,
274274
})
275275
}
276276
ty::Str => tcx.mk_layout(LayoutS {
@@ -280,7 +280,7 @@ fn layout_of_uncached<'tcx>(
280280
largest_niche: None,
281281
align: dl.i8_align,
282282
size: Size::ZERO,
283-
has_repr_align: false,
283+
repr_align: None,
284284
}),
285285

286286
// Odd unit types.
@@ -434,7 +434,7 @@ fn layout_of_uncached<'tcx>(
434434
largest_niche: e_ly.largest_niche,
435435
size,
436436
align,
437-
has_repr_align: false,
437+
repr_align: None,
438438
})
439439
}
440440

@@ -883,7 +883,7 @@ fn generator_layout<'tcx>(
883883
largest_niche: prefix.largest_niche,
884884
size,
885885
align,
886-
has_repr_align: false,
886+
repr_align: None,
887887
});
888888
debug!("generator layout ({:?}): {:#?}", ty, layout);
889889
Ok(layout)

tests/codegen/align-byval.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,16 @@ pub struct ForceAlign8 {
7171
c: i64
7272
}
7373

74-
// On i686-windows, this is passed by reference because alignment is requested,
75-
// even though the requested alignment is less than the natural alignment.
74+
// On i686-windows, this is passed on stack, because requested alignment is <=4.
7675
#[repr(C)]
77-
#[repr(align(1))]
76+
#[repr(align(4))]
7877
pub struct LowerFA8 {
7978
a: i64,
8079
b: i64,
8180
c: i64
8281
}
8382

84-
// On i686-windows, this is passed on stack again, because the wrapper struct does not have
83+
// On i686-windows, this is passed on stack, because the wrapper struct does not have
8584
// requested/forced alignment.
8685
#[repr(C)]
8786
pub struct WrappedFA8 {
@@ -287,9 +286,7 @@ extern "C" {
287286

288287
// i686-linux: declare void @lower_fa8({{.*}}byval(%LowerFA8) align 4{{.*}})
289288

290-
// i686-windows: declare void @lower_fa8(
291-
// i686-windows-NOT: byval
292-
// i686-windows-SAME: align 8{{.*}})
289+
// i686-windows: declare void @lower_fa8({{.*}}byval(%LowerFA8) align 4{{.*}})
293290
fn lower_fa8(x: LowerFA8);
294291

295292
// m68k: declare void @wrapped_fa8({{.*}}byval(%WrappedFA8) align 8{{.*}})

tests/ui/layout/debug.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ error: layout_of(E) = Layout {
5353
variants: Single {
5454
index: 0,
5555
},
56-
has_repr_align: false,
56+
repr_align: None,
5757
},
5858
Layout {
5959
size: Size(12 bytes),
@@ -78,11 +78,11 @@ error: layout_of(E) = Layout {
7878
variants: Single {
7979
index: 1,
8080
},
81-
has_repr_align: false,
81+
repr_align: None,
8282
},
8383
],
8484
},
85-
has_repr_align: false,
85+
repr_align: None,
8686
}
8787
--> $DIR/debug.rs:7:1
8888
|
@@ -127,7 +127,7 @@ error: layout_of(S) = Layout {
127127
variants: Single {
128128
index: 0,
129129
},
130-
has_repr_align: false,
130+
repr_align: None,
131131
}
132132
--> $DIR/debug.rs:10:1
133133
|
@@ -150,7 +150,7 @@ error: layout_of(U) = Layout {
150150
variants: Single {
151151
index: 0,
152152
},
153-
has_repr_align: false,
153+
repr_align: None,
154154
}
155155
--> $DIR/debug.rs:13:1
156156
|
@@ -242,7 +242,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
242242
variants: Single {
243243
index: 0,
244244
},
245-
has_repr_align: false,
245+
repr_align: None,
246246
},
247247
Layout {
248248
size: Size(8 bytes),
@@ -278,11 +278,11 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
278278
variants: Single {
279279
index: 1,
280280
},
281-
has_repr_align: false,
281+
repr_align: None,
282282
},
283283
],
284284
},
285-
has_repr_align: false,
285+
repr_align: None,
286286
}
287287
--> $DIR/debug.rs:16:1
288288
|
@@ -309,7 +309,7 @@ error: layout_of(i32) = Layout {
309309
variants: Single {
310310
index: 0,
311311
},
312-
has_repr_align: false,
312+
repr_align: None,
313313
}
314314
--> $DIR/debug.rs:19:1
315315
|
@@ -332,7 +332,7 @@ error: layout_of(V) = Layout {
332332
variants: Single {
333333
index: 0,
334334
},
335-
has_repr_align: false,
335+
repr_align: None,
336336
}
337337
--> $DIR/debug.rs:22:1
338338
|
@@ -355,7 +355,7 @@ error: layout_of(W) = Layout {
355355
variants: Single {
356356
index: 0,
357357
},
358-
has_repr_align: false,
358+
repr_align: None,
359359
}
360360
--> $DIR/debug.rs:28:1
361361
|
@@ -378,7 +378,7 @@ error: layout_of(Y) = Layout {
378378
variants: Single {
379379
index: 0,
380380
},
381-
has_repr_align: false,
381+
repr_align: None,
382382
}
383383
--> $DIR/debug.rs:34:1
384384
|
@@ -401,7 +401,7 @@ error: layout_of(P1) = Layout {
401401
variants: Single {
402402
index: 0,
403403
},
404-
has_repr_align: false,
404+
repr_align: None,
405405
}
406406
--> $DIR/debug.rs:41:1
407407
|
@@ -424,7 +424,7 @@ error: layout_of(P2) = Layout {
424424
variants: Single {
425425
index: 0,
426426
},
427-
has_repr_align: false,
427+
repr_align: None,
428428
}
429429
--> $DIR/debug.rs:45:1
430430
|
@@ -447,7 +447,7 @@ error: layout_of(P3) = Layout {
447447
variants: Single {
448448
index: 0,
449449
},
450-
has_repr_align: false,
450+
repr_align: None,
451451
}
452452
--> $DIR/debug.rs:53:1
453453
|
@@ -470,7 +470,7 @@ error: layout_of(P4) = Layout {
470470
variants: Single {
471471
index: 0,
472472
},
473-
has_repr_align: false,
473+
repr_align: None,
474474
}
475475
--> $DIR/debug.rs:57:1
476476
|
@@ -498,7 +498,7 @@ error: layout_of(P5) = Layout {
498498
variants: Single {
499499
index: 0,
500500
},
501-
has_repr_align: false,
501+
repr_align: None,
502502
}
503503
--> $DIR/debug.rs:61:1
504504
|
@@ -526,7 +526,7 @@ error: layout_of(std::mem::MaybeUninit<u8>) = Layout {
526526
variants: Single {
527527
index: 0,
528528
},
529-
has_repr_align: false,
529+
repr_align: None,
530530
}
531531
--> $DIR/debug.rs:64:1
532532
|

0 commit comments

Comments
 (0)