Skip to content

Commit 68965b6

Browse files
authored
Rollup merge of #114296 - RalfJung:interpret-repeat-align, r=oli-obk
interpret: fix alignment handling for Repeat expressions
2 parents 3cc0c2a + 9b2faaf commit 68965b6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![feature(custom_mir, core_intrinsics)]
2+
use std::intrinsics::mir::*;
3+
4+
#[repr(packed)]
5+
struct S { field: [u32; 2] }
6+
7+
#[custom_mir(dialect = "runtime", phase = "optimized")]
8+
fn test() { mir! {
9+
let s: S;
10+
{
11+
// Store a repeat expression directly into a field of a packed struct.
12+
s.field = [0; 2];
13+
Return()
14+
}
15+
} }
16+
17+
fn main() {
18+
// Run this a bunch of time to make sure it doesn't pass by chance.
19+
for _ in 0..20 {
20+
test();
21+
}
22+
}

tests/pass/issues/issue-miri-1925.rs renamed to tests/pass/align_repeat_into_well_aligned_array.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::mem::size_of;
44

55
fn main() {
66
let mut a = Params::new();
7+
// The array itself here happens to be quite well-aligned, but not all its elements have that
8+
// large alignment and we better make sure that is still accepted by Miri.
79
a.key_block = [0; BLOCKBYTES];
810
}
911

0 commit comments

Comments
 (0)