Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round generator sizes to a multiple of their alignment #63208

Merged
merged 1 commit into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of println you could use either drop is define a fn dummy<T>(_: T) {} and use that

}

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

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