about summary refs log tree commit diff
path: root/tests/ui/unsized-locals
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2023-05-08 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2023-05-08 23:40:51 +0200
commit83a5a69a4c7bd60901bf7f7d96378ddea7ecb06c (patch)
treeb004f829fc6b066af593af1901d5b797dbd020b1 /tests/ui/unsized-locals
parentce042889f7f0d687368a9704eff64cf9542bac6d (diff)
downloadrust-83a5a69a4c7bd60901bf7f7d96378ddea7ecb06c.tar.gz
rust-83a5a69a4c7bd60901bf7f7d96378ddea7ecb06c.zip
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/ui/unsized-locals')
-rw-r--r--tests/ui/unsized-locals/align.rs30
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);
+}