Skip to content

Commit

Permalink
Rollup merge of rust-lang#112684 - saethlin:ignore-windows-alignment,…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
matthiaskrgr committed Jun 16, 2023
2 parents 2b73936 + 55d680b commit 91f428d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_mir_transform/src/check_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub struct CheckAlignment;

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

Expand Down
21 changes: 21 additions & 0 deletions tests/ui/mir/mir_alignment_check_i686-pc-windows-msvc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-pass
// only-i686-pc-windows-msvc
// compile-flags: -Copt-level=0 -Cdebug-assertions=yes

// MSVC isn't sure if on 32-bit Windows its u64 type is 8-byte-aligned or 4-byte-aligned.
// So this test ensures that on i686-pc-windows-msvc, we do not insert a runtime check
// that will fail on dereferencing of a pointer to u64 which is not 8-byte-aligned but is
// 4-byte-aligned.

#![feature(strict_provenance)]

fn main() {
let mut x = [0u64; 2];
let ptr: *mut u8 = x.as_mut_ptr().cast::<u8>();
unsafe {
let misaligned = ptr.add(4).cast::<u64>();
assert!(misaligned.addr() % 8 != 0);
assert!(misaligned.addr() % 4 == 0);
*misaligned = 42;
}
}

0 comments on commit 91f428d

Please sign in to comment.