-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #112684 - saethlin:ignore-windows-alignment, r=wesley…
…wiser 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 #112480
- Loading branch information
Showing
2 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |