Align unsized locals
Allocate an extra space for unsized locals and manually align the storage, since alloca doesn't support dynamic alignment.
This commit is contained in:
parent
ce042889f7
commit
83a5a69a4c
2 changed files with 45 additions and 11 deletions
30
tests/ui/unsized-locals/align.rs
Normal file
30
tests/ui/unsized-locals/align.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue