Skip to content

Commit 91f428d

Browse files
authored
Rollup merge of rust-lang#112684 - saethlin:ignore-windows-alignment, r=wesleywiser
Disable alignment checks on i686-pc-windows-msvc r? `@wesleywiser` Because you were in the Zulip discussion of this: https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202023-06-15 cc rust-lang#112480
2 parents 2b73936 + 55d680b commit 91f428d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

compiler/rustc_mir_transform/src/check_alignment.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ pub struct CheckAlignment;
1515

1616
impl<'tcx> MirPass<'tcx> for CheckAlignment {
1717
fn is_enabled(&self, sess: &Session) -> bool {
18+
// FIXME(#112480) MSVC and rustc disagree on minimum stack alignment on x86 Windows
19+
if sess.target.llvm_target == "i686-pc-windows-msvc" {
20+
return false;
21+
}
1822
sess.opts.debug_assertions
1923
}
2024

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// run-pass
2+
// only-i686-pc-windows-msvc
3+
// compile-flags: -Copt-level=0 -Cdebug-assertions=yes
4+
5+
// MSVC isn't sure if on 32-bit Windows its u64 type is 8-byte-aligned or 4-byte-aligned.
6+
// So this test ensures that on i686-pc-windows-msvc, we do not insert a runtime check
7+
// that will fail on dereferencing of a pointer to u64 which is not 8-byte-aligned but is
8+
// 4-byte-aligned.
9+
10+
#![feature(strict_provenance)]
11+
12+
fn main() {
13+
let mut x = [0u64; 2];
14+
let ptr: *mut u8 = x.as_mut_ptr().cast::<u8>();
15+
unsafe {
16+
let misaligned = ptr.add(4).cast::<u64>();
17+
assert!(misaligned.addr() % 8 != 0);
18+
assert!(misaligned.addr() % 4 == 0);
19+
*misaligned = 42;
20+
}
21+
}

0 commit comments

Comments
 (0)