Skip to content

Commit

Permalink
Rollup merge of rust-lang#63208 - tmandry:issue-62658, r=cramertj
Browse files Browse the repository at this point in the history
Round generator sizes to a multiple of their alignment

Fixes rust-lang#62658.

r? @cramertj
cc @eddyb
  • Loading branch information
Centril committed Aug 2, 2019
2 parents ed7b044 + 14be088 commit 109b21f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
Ok(variant)
}).collect::<Result<IndexVec<VariantIdx, _>, _>>()?;

size = size.align_to(align.abi);

let abi = if prefix.abi.is_uninhabited() ||
variants.iter().all(|v| v.abi.is_uninhabited()) {
Abi::Uninhabited
Expand Down
29 changes: 29 additions & 0 deletions src/test/ui/async-await/issue-62658.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This test created a generator whose size was not rounded to a multiple of its
// alignment. This caused an assertion error in codegen.

// build-pass
// edition:2018

#![feature(async_await)]

async fn noop() {}

async fn foo() {
// This suspend should be the largest variant.
{
let x = [0u8; 17];
noop().await;
println!("{:?}", x);
}

// Add one variant that's aligned to 8 bytes.
{
let x = 0u64;
noop().await;
println!("{:?}", x);
}
}

fn main() {
let _ = foo();
}

0 comments on commit 109b21f

Please sign in to comment.