diff options
author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2023-05-08 00:00:00 +0000 |
---|---|---|
committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2023-05-08 23:40:51 +0200 |
commit | 83a5a69a4c7bd60901bf7f7d96378ddea7ecb06c (patch) | |
tree | b004f829fc6b066af593af1901d5b797dbd020b1 /tests | |
parent | ce042889f7f0d687368a9704eff64cf9542bac6d (diff) | |
download | rust-83a5a69a4c7bd60901bf7f7d96378ddea7ecb06c.tar.gz |
Align unsized locals
Allocate an extra space for unsized locals and manually align the
storage, since alloca doesn't support dynamic alignment.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ui/unsized-locals/align.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/unsized-locals/align.rs b/tests/ui/unsized-locals/align.rs new file mode 100644 index 00000000000..01be8f3bb9c --- /dev/null +++ b/tests/ui/unsized-locals/align.rs @@ -0,0 +1,30 @@ +// Test that unsized locals uphold alignment requirements. +// Regression test for #71416. +// run-pass +#![feature(unsized_locals)] +#![allow(incomplete_features)] +use std::any::Any; + +#[repr(align(256))] +#[allow(dead_code)] +struct A { + v: u8 +} + +impl A { + fn f(&self) -> *const A { + assert_eq!(self as *const A as usize % 256, 0); + self + } +} + +fn mk() -> Box<dyn Any> { + Box::new(A { v: 4 }) +} + +fn main() { + let x = *mk(); + let dwncst = x.downcast_ref::<A>().unwrap(); + let addr = dwncst.f(); + assert_eq!(addr as usize % 256, 0); +} |