Skip to content

Commit

Permalink
Auto merge of #1927 - RalfJung:array-align-tests, r=RalfJung
Browse files Browse the repository at this point in the history
add tests for alignment on array initialization

This adds regression tests for #1925, #1919.
  • Loading branch information
bors committed Nov 28, 2021
2 parents e62924e + ee666d8 commit 9983e0f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
686e313a9aa14107c8631ffe48fa09110a7692db
58f9efd36de5669ab731ec7ebf565999ff17b159
13 changes: 13 additions & 0 deletions tests/run-pass/async-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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());
}
33 changes: 33 additions & 0 deletions tests/run-pass/issue-miri-1925.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}

0 comments on commit 9983e0f

Please sign in to comment.