From 14be0886778aec5ed597db19b1778503b90c51ab Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 1 Aug 2019 18:24:12 -0700 Subject: [PATCH] Round generator sizes to multiple of their alignment Fixes #62658. --- src/librustc/ty/layout.rs | 2 ++ src/test/ui/async-await/issue-62658.rs | 29 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/ui/async-await/issue-62658.rs diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 3b4b814c92a..e0e70f41abe 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1540,6 +1540,8 @@ fn generator_layout( Ok(variant) }).collect::, _>>()?; + size = size.align_to(align.abi); + let abi = if prefix.abi.is_uninhabited() || variants.iter().all(|v| v.abi.is_uninhabited()) { Abi::Uninhabited diff --git a/src/test/ui/async-await/issue-62658.rs b/src/test/ui/async-await/issue-62658.rs new file mode 100644 index 00000000000..90fbb47bffd --- /dev/null +++ b/src/test/ui/async-await/issue-62658.rs @@ -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(); +}