Skip to content

Commit dabcfff

Browse files
committed
Disable alignment checks on i686-pc-windows-msvc
1 parent 8c74a5d commit dabcfff

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

compiler/rustc_mir_transform/src/check_alignment.rs

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub struct CheckAlignment;
1414

1515
impl<'tcx> MirPass<'tcx> for CheckAlignment {
1616
fn is_enabled(&self, sess: &Session) -> bool {
17+
if sess.target.llvm_target == "i686-pc-windows-msvc" {
18+
return false;
19+
}
1720
sess.opts.debug_assertions
1821
}
1922

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)