]> git.lizzy.rs Git - rust.git/commitdiff
forgot to add alignment test loop in one test
authorRalf Jung <post@ralfj.de>
Tue, 18 Aug 2020 08:11:54 +0000 (10:11 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 18 Aug 2020 08:19:29 +0000 (10:19 +0200)
rust-version
tests/compile-fail/unaligned_pointers/alignment.rs
tests/compile-fail/unaligned_pointers/atomic_unaligned.rs
tests/compile-fail/unaligned_pointers/dyn_alignment.rs
tests/compile-fail/unaligned_pointers/intptrcast_alignment_check.rs
tests/compile-fail/unaligned_pointers/reference_to_packed.rs
tests/compile-fail/unaligned_pointers/unaligned_ptr1.rs
tests/compile-fail/unaligned_pointers/unaligned_ptr2.rs
tests/compile-fail/unaligned_pointers/unaligned_ptr3.rs
tests/compile-fail/unaligned_pointers/unaligned_ptr_zst.rs

index e322ff61d1bda31bb18451d6d289ea581dccad76..6d85c7fb38887d538419e30c703b433359dac838 100644 (file)
@@ -1 +1 @@
-8cdc94e84040ce797fd33d0a7cfda4ec4f2f2421
+515c9fa505e18a65d7f61bc3e9eb833b79a68618
index e4d7621b8b125d278e4a835916b24b74b70242ea..ff31fc6c293e95fc1553e561b3d9b95d786ed717 100644 (file)
@@ -1,6 +1,8 @@
 // error-pattern: but alignment 4 is required
 
 fn main() {
+    // No retry needed, this fails reliably.
+
     let mut x = [0u8; 20];
     let x_ptr: *mut u8 = x.as_mut_ptr();
     // At least one of these is definitely unaligned.
index 77eff5087dac5c2f293a40bb8c15c796f71ee1a5..7e0704ac6fc06315f7cabb5bc494ba494a64b34e 100644 (file)
@@ -8,6 +8,6 @@ fn main() {
     let zptr = &z as *const _ as *const u64;
     unsafe {
         ::std::intrinsics::atomic_load(zptr);
-        //~^ ERROR accessing memory with alignment 4, but alignment 8 is required
+        //~^ERROR accessing memory with alignment 4, but alignment 8 is required
     }
 }
index a40db99a72a6c6e78c7172ef680ddfa97b6b59d9..91d9ec475b1fefca737d72f41752131490f305cb 100644 (file)
@@ -6,14 +6,16 @@
 struct MuchAlign;
 
 fn main() {
-    let buf = [0u32; 256];
-    // `buf` is sufficiently aligned for `layout.align` on a `dyn Debug`, but not
-    // for the actual alignment required by `MuchAlign`.
-    // We craft a wide reference `&dyn Debug` with the vtable for `MuchAlign`. That should be UB,
-    // as the reference is not aligned to its dynamic alignment requirements.
-    let mut ptr = &MuchAlign as &dyn std::fmt::Debug;
-    // Overwrite the data part of `ptr` so it points to `buf`.
-    unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); }
-    // Re-borrow that. This should be UB.
-    let _ptr = &*ptr; //~ ERROR alignment 256 is required
+    for _ in 0..10 { // Try many times as this might work by chance.
+        let buf = [0u32; 256];
+        // `buf` is sufficiently aligned for `layout.align` on a `dyn Debug`, but not
+        // for the actual alignment required by `MuchAlign`.
+        // We craft a wide reference `&dyn Debug` with the vtable for `MuchAlign`. That should be UB,
+        // as the reference is not aligned to its dynamic alignment requirements.
+        let mut ptr = &MuchAlign as &dyn std::fmt::Debug;
+        // Overwrite the data part of `ptr` so it points to `buf`.
+        unsafe { (&mut ptr as *mut _ as *mut *const u8).write(&buf as *const _ as *const u8); }
+        // Re-borrow that. This should be UB.
+        let _ptr = &*ptr; //~ERROR alignment 256 is required
+    }
 }
index 3865d45786374929fbf3f62fb05b7b9cbf672e5d..9872a493c02a9b6c68c0f1a19fe63e9de576514f 100644 (file)
@@ -9,8 +9,9 @@
 fn main() {
     let x = &mut [0u8; 3];
     let base_addr = x as *mut _ as usize;
+    // Manually make sure the pointer is properly aligned.
     let base_addr_aligned = if base_addr % 2 == 0 { base_addr } else { base_addr+1 };
     let u16_ptr = base_addr_aligned as *mut u16;
-    unsafe { *u16_ptr = 2; } //~ ERROR memory with alignment 1, but alignment 2 is required
+    unsafe { *u16_ptr = 2; } //~ERROR memory with alignment 1, but alignment 2 is required
     println!("{:?}", x);
 }
index 998394c6c70cce11eeac1db27969b0ca3439b413..6fa95211853524915cf66cb27f1fe59d8d116c27 100644 (file)
@@ -16,6 +16,6 @@ fn main() {
             y: 99,
         };
         let p = unsafe { &foo.x };
-        let i = *p; //~ ERROR alignment 4 is required
+        let i = *p; //~ERROR alignment 4 is required
     }
 }
index 43e6fd67d2460c0c350f6532f27450be0722f66b..1d72e5170b7c2d99f770f88f206dfc7af2fbaff9 100644 (file)
@@ -6,6 +6,6 @@ fn main() {
         let x = [2u16, 3, 4]; // Make it big enough so we don't get an out-of-bounds error.
         let x = &x[0] as *const _ as *const u32;
         // This must fail because alignment is violated: the allocation's base is not sufficiently aligned.
-        let _x = unsafe { *x }; //~ ERROR memory with alignment 2, but alignment 4 is required
+        let _x = unsafe { *x }; //~ERROR memory with alignment 2, but alignment 4 is required
     }
 }
index f4ed8d47b53f1a70edbe3b85ee9c5e75710d6388..49612e2b8a0964087d7a6f3e1233218fd362fdce 100644 (file)
@@ -2,11 +2,11 @@
 // compile-flags: -Zmiri-disable-validation -Zmiri-disable-stacked-borrows
 
 fn main() {
-    for _ in 0..10 { // Try many times as this might work by chance.
-        let x = [2u32, 3]; // Make it big enough so we don't get an out-of-bounds error.
-        let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32;
-        // This must fail because alignment is violated: the offset is not sufficiently aligned.
-        // Also make the offset not a power of 2, that used to ICE.
-        let _x = unsafe { *x }; //~ ERROR memory with alignment 1, but alignment 4 is required
-    }
+    // No retry needed, this fails reliably.
+
+    let x = [2u32, 3]; // Make it big enough so we don't get an out-of-bounds error.
+    let x = (x.as_ptr() as *const u8).wrapping_offset(3) as *const u32;
+    // This must fail because alignment is violated: the offset is not sufficiently aligned.
+    // Also make the offset not a power of 2, that used to ICE.
+    let _x = unsafe { *x }; //~ERROR memory with alignment 1, but alignment 4 is required
 }
index 61c2a3cde8948c73ae186446a6306dd5b6933a3b..ecab83b05a09fbcc8a88744dc28d4ff38c01010f 100644 (file)
@@ -7,7 +7,6 @@ fn main() {
         let x = &x[0] as *const _ as *const *const u8; // cast to ptr-to-ptr, so that we load a ptr
         // This must fail because alignment is violated. Test specifically for loading pointers,
         // which have special code in miri's memory.
-        let _x = unsafe { *x };
-        //~^ ERROR but alignment
+        let _x = unsafe { *x }; //~ERROR but alignment
     }
 }
index beba47359b551d4119b093aa7edf7c6f503043c9..2b6ff3f71c60f85e3e4300b02d53d165cac96af8 100644 (file)
@@ -2,9 +2,10 @@
 // compile-flags: -Zmiri-disable-validation
 
 fn main() {
-    let x = &2u8;
-    let x = x as *const _ as *const [u32; 0];
-    // This must fail because alignment is violated. Test specifically for loading ZST.
-    let _x = unsafe { *x };
-    //~^ ERROR alignment 4 is required
+    for _ in 0..10 { // Try many times as this might work by chance.
+        let x = &2u8;
+        let x = x as *const _ as *const [u32; 0];
+        // This must fail because alignment is violated. Test specifically for loading ZST.
+        let _x = unsafe { *x }; //~ERROR alignment 4 is required
+    }
 }