Skip to content

Commit 9983e0f

Browse files
committed
Auto merge of #1927 - RalfJung:array-align-tests, r=RalfJung
add tests for alignment on array initialization This adds regression tests for #1925, #1919.
2 parents e62924e + ee666d8 commit 9983e0f

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
686e313a9aa14107c8631ffe48fa09110a7692db
1+
58f9efd36de5669ab731ec7ebf565999ff17b159

tests/run-pass/async-fn.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ async fn partial_init(x: u32) -> u32 {
4545
let _x: (String, !) = (String::new(), return async { x + x }.await);
4646
}
4747

48+
async fn read_exact(_from: &mut &[u8], _to: &mut [u8]) -> Option<()> {
49+
Some(())
50+
}
51+
52+
async fn hello_world() {
53+
let data = [0u8; 1];
54+
let mut reader = &data[..];
55+
56+
let mut marker = [0u8; 1];
57+
read_exact(&mut reader, &mut marker).await.unwrap();
58+
}
59+
4860
fn run_fut<T>(fut: impl Future<Output = T>) -> T {
4961
use std::sync::Arc;
5062
use std::task::{Context, Poll, Wake, Waker};
@@ -74,4 +86,5 @@ fn main() {
7486
assert_eq!(run_fut(build_aggregate(1, 2, 3, 4)), 10);
7587
assert_eq!(run_fut(includes_never(false, 4)), 16);
7688
assert_eq!(run_fut(partial_init(4)), 8);
89+
run_fut(hello_world());
7790
}

tests/run-pass/issue-miri-1925.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// compile-flags: -Zmiri-symbolic-alignment-check
2+
3+
use std::mem::size_of;
4+
5+
fn main() {
6+
let mut a = Params::new();
7+
a.key_block = [0; BLOCKBYTES];
8+
}
9+
10+
#[repr(C)]
11+
#[derive(Clone)]
12+
#[allow(unused)]
13+
pub struct Params {
14+
hash_length: u8,
15+
key_length: u8,
16+
key_block: [u8; BLOCKBYTES],
17+
max_leaf_length: u32,
18+
}
19+
20+
pub const OUTBYTES: usize = 8 * size_of::<u64>();
21+
pub const KEYBYTES: usize = 8 * size_of::<u64>();
22+
pub const BLOCKBYTES: usize = 16 * size_of::<u64>();
23+
24+
impl Params {
25+
pub fn new() -> Self {
26+
Self {
27+
hash_length: OUTBYTES as u8,
28+
key_length: 0,
29+
key_block: [0; BLOCKBYTES],
30+
max_leaf_length: 0,
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)