Skip to content

Commit 14be088

Browse files
committed
Round generator sizes to multiple of their alignment
Fixes rust-lang#62658.
1 parent c43753f commit 14be088

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/librustc/ty/layout.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
15401540
Ok(variant)
15411541
}).collect::<Result<IndexVec<VariantIdx, _>, _>>()?;
15421542

1543+
size = size.align_to(align.abi);
1544+
15431545
let abi = if prefix.abi.is_uninhabited() ||
15441546
variants.iter().all(|v| v.abi.is_uninhabited()) {
15451547
Abi::Uninhabited
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This test created a generator whose size was not rounded to a multiple of its
2+
// alignment. This caused an assertion error in codegen.
3+
4+
// build-pass
5+
// edition:2018
6+
7+
#![feature(async_await)]
8+
9+
async fn noop() {}
10+
11+
async fn foo() {
12+
// This suspend should be the largest variant.
13+
{
14+
let x = [0u8; 17];
15+
noop().await;
16+
println!("{:?}", x);
17+
}
18+
19+
// Add one variant that's aligned to 8 bytes.
20+
{
21+
let x = 0u64;
22+
noop().await;
23+
println!("{:?}", x);
24+
}
25+
}
26+
27+
fn main() {
28+
let _ = foo();
29+
}

0 commit comments

Comments
 (0)