From b169ee7c1a0a72576df06d7b01699703f6ed65a8 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 31 Jul 2023 17:29:30 +0200 Subject: fix alignment handling for Repeat expressions --- .../tests/pass/align_repeat_into_packed_field.rs | 22 ++++++++++++++ .../pass/align_repeat_into_well_aligned_array.rs | 35 ++++++++++++++++++++++ .../miri/tests/pass/issues/issue-miri-1925.rs | 33 -------------------- 3 files changed, 57 insertions(+), 33 deletions(-) create mode 100644 src/tools/miri/tests/pass/align_repeat_into_packed_field.rs create mode 100644 src/tools/miri/tests/pass/align_repeat_into_well_aligned_array.rs delete mode 100644 src/tools/miri/tests/pass/issues/issue-miri-1925.rs (limited to 'src/tools') diff --git a/src/tools/miri/tests/pass/align_repeat_into_packed_field.rs b/src/tools/miri/tests/pass/align_repeat_into_packed_field.rs new file mode 100644 index 00000000000..3affb204205 --- /dev/null +++ b/src/tools/miri/tests/pass/align_repeat_into_packed_field.rs @@ -0,0 +1,22 @@ +#![feature(custom_mir, core_intrinsics)] +use std::intrinsics::mir::*; + +#[repr(packed)] +struct S { field: [u32; 2] } + +#[custom_mir(dialect = "runtime", phase = "optimized")] +fn test() { mir! { + let s: S; + { + // Store a repeat expression directly into a field of a packed struct. + s.field = [0; 2]; + Return() + } +} } + +fn main() { + // Run this a bunch of time to make sure it doesn't pass by chance. + for _ in 0..20 { + test(); + } +} diff --git a/src/tools/miri/tests/pass/align_repeat_into_well_aligned_array.rs b/src/tools/miri/tests/pass/align_repeat_into_well_aligned_array.rs new file mode 100644 index 00000000000..735251039f7 --- /dev/null +++ b/src/tools/miri/tests/pass/align_repeat_into_well_aligned_array.rs @@ -0,0 +1,35 @@ +//@compile-flags: -Zmiri-symbolic-alignment-check + +use std::mem::size_of; + +fn main() { + let mut a = Params::new(); + // The array itself here happens to be quite well-aligned, but not all its elements have that + // large alignment and we better make sure that is still accepted by Miri. + 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::(); +pub const KEYBYTES: usize = 8 * size_of::(); +pub const BLOCKBYTES: usize = 16 * size_of::(); + +impl Params { + pub fn new() -> Self { + Self { + hash_length: OUTBYTES as u8, + key_length: 0, + key_block: [0; BLOCKBYTES], + max_leaf_length: 0, + } + } +} diff --git a/src/tools/miri/tests/pass/issues/issue-miri-1925.rs b/src/tools/miri/tests/pass/issues/issue-miri-1925.rs deleted file mode 100644 index 86556813491..00000000000 --- a/src/tools/miri/tests/pass/issues/issue-miri-1925.rs +++ /dev/null @@ -1,33 +0,0 @@ -//@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::(); -pub const KEYBYTES: usize = 8 * size_of::(); -pub const BLOCKBYTES: usize = 16 * size_of::(); - -impl Params { - pub fn new() -> Self { - Self { - hash_length: OUTBYTES as u8, - key_length: 0, - key_block: [0; BLOCKBYTES], - max_leaf_length: 0, - } - } -} -- cgit 1.4.1-3-g733a5