Auto merge of #1927 - RalfJung:array-align-tests, r=RalfJung

add tests for alignment on array initialization

This adds regression tests for https://github.com/rust-lang/miri/issues/1925, https://github.com/rust-lang/miri/issues/1919.
This commit is contained in:
bors 2021-11-28 15:28:57 +00:00
commit 9983e0fc63
3 changed files with 47 additions and 1 deletions

View File

@ -1 +1 @@
686e313a9aa14107c8631ffe48fa09110a7692db
58f9efd36de5669ab731ec7ebf565999ff17b159

View File

@ -45,6 +45,18 @@ async fn partial_init(x: u32) -> u32 {
let _x: (String, !) = (String::new(), return async { x + x }.await);
}
async fn read_exact(_from: &mut &[u8], _to: &mut [u8]) -> Option<()> {
Some(())
}
async fn hello_world() {
let data = [0u8; 1];
let mut reader = &data[..];
let mut marker = [0u8; 1];
read_exact(&mut reader, &mut marker).await.unwrap();
}
fn run_fut<T>(fut: impl Future<Output = T>) -> T {
use std::sync::Arc;
use std::task::{Context, Poll, Wake, Waker};
@ -74,4 +86,5 @@ fn main() {
assert_eq!(run_fut(build_aggregate(1, 2, 3, 4)), 10);
assert_eq!(run_fut(includes_never(false, 4)), 16);
assert_eq!(run_fut(partial_init(4)), 8);
run_fut(hello_world());
}

View File

@ -0,0 +1,33 @@
// compile-flags: -Zmiri-symbolic-alignment-check
use std::mem::size_of;
fn main() {
let mut a = Params::new();
a.key_block = [0; BLOCKBYTES];
}
#[repr(C)]
#[derive(Clone)]
#[allow(unused)]
pub struct Params {
hash_length: u8,
key_length: u8,
key_block: [u8; BLOCKBYTES],
max_leaf_length: u32,
}
pub const OUTBYTES: usize = 8 * size_of::<u64>();
pub const KEYBYTES: usize = 8 * size_of::<u64>();
pub const BLOCKBYTES: usize = 16 * size_of::<u64>();
impl Params {
pub fn new() -> Self {
Self {
hash_length: OUTBYTES as u8,
key_length: 0,
key_block: [0; BLOCKBYTES],
max_leaf_length: 0,
}
}
}