about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-03-31 08:50:35 +0000
committerbors <bors@rust-lang.org>2023-03-31 08:50:35 +0000
commit22a7a19f9333bc1fcba97ce444a3515cb5fb33e6 (patch)
tree8ac7da60c0ee60d36ef565024a75f848c98a19b6 /tests
parentec7bb8da11f3e5cc73be397b78d2aea4157df300 (diff)
parent750707801b42c0da6beeccd587925130ba2bad99 (diff)
downloadrust-22a7a19f9333bc1fcba97ce444a3515cb5fb33e6.tar.gz
rust-22a7a19f9333bc1fcba97ce444a3515cb5fb33e6.zip
Auto merge of #98112 - saethlin:mir-alignment-checks, r=oli-obk
Insert alignment checks for pointer dereferences when debug assertions are enabled

Closes https://github.com/rust-lang/rust/issues/54915

- [x] Jake tells me this sounds like a place to use `MirPatch`, but I can't figure out how to insert a new basic block with a new terminator in the middle of an existing basic block, using `MirPatch`. (if nobody else backs up this point I'm checking this as "not actually a good idea" because the code looks pretty clean to me after rearranging it a bit)
- [x] Using `CastKind::PointerExposeAddress` is definitely wrong, we don't want to expose. Calling a function to get the pointer address seems quite excessive. ~I'll see if I can add a new `CastKind`.~ `CastKind::Transmute` to the rescue!
- [x] Implement a more helpful panic message like slice bounds checking.

r? `@oli-obk`
Diffstat (limited to 'tests')
-rw-r--r--tests/assembly/static-relocation-model.rs1
-rw-r--r--tests/codegen/issues/issue-37945.rs1
-rw-r--r--tests/codegen/virtual-function-elimination.rs1
-rw-r--r--tests/mir-opt/inline/inline_into_box_place.main.Inline.diff8
-rw-r--r--tests/mir-opt/inline/inline_into_box_place.rs1
-rw-r--r--tests/run-make/fmt-write-bloat/Makefile4
-rw-r--r--tests/ui/mir/mir_alignment_check.rs12
-rw-r--r--tests/ui/process/signal-exit-status.rs6
8 files changed, 26 insertions, 8 deletions
diff --git a/tests/assembly/static-relocation-model.rs b/tests/assembly/static-relocation-model.rs
index faa2e395209..41aa9a46103 100644
--- a/tests/assembly/static-relocation-model.rs
+++ b/tests/assembly/static-relocation-model.rs
@@ -6,6 +6,7 @@
 // [A64] needs-llvm-components: aarch64
 // [ppc64le] compile-flags: --target powerpc64le-unknown-linux-gnu -Crelocation-model=static
 // [ppc64le] needs-llvm-components: powerpc
+// ignore-debug: alignment checks insert panics that we don't have a lang item for
 
 #![feature(no_core, lang_items)]
 #![no_core]
diff --git a/tests/codegen/issues/issue-37945.rs b/tests/codegen/issues/issue-37945.rs
index fe54375bbf6..19e7e8b1f6e 100644
--- a/tests/codegen/issues/issue-37945.rs
+++ b/tests/codegen/issues/issue-37945.rs
@@ -4,6 +4,7 @@
 // ignore-emscripten
 // ignore-gnux32
 // ignore 32-bit platforms (LLVM has a bug with them)
+// ignore-debug
 
 // Check that LLVM understands that `Iter` pointer is not null. Issue #37945.
 
diff --git a/tests/codegen/virtual-function-elimination.rs b/tests/codegen/virtual-function-elimination.rs
index 4cf7e12fee2..30e5cd0584d 100644
--- a/tests/codegen/virtual-function-elimination.rs
+++ b/tests/codegen/virtual-function-elimination.rs
@@ -1,5 +1,6 @@
 // compile-flags: -Zvirtual-function-elimination -Clto -O -Csymbol-mangling-version=v0
 // ignore-32bit
+// ignore-debug
 
 // CHECK: @vtable.0 = {{.*}}, !type ![[TYPE0:[0-9]+]], !vcall_visibility ![[VCALL_VIS0:[0-9]+]]
 // CHECK: @vtable.1 = {{.*}}, !type ![[TYPE1:[0-9]+]], !vcall_visibility ![[VCALL_VIS0:[0-9]+]]
diff --git a/tests/mir-opt/inline/inline_into_box_place.main.Inline.diff b/tests/mir-opt/inline/inline_into_box_place.main.Inline.diff
index bc1c913c00e..a4f0ad465e2 100644
--- a/tests/mir-opt/inline/inline_into_box_place.main.Inline.diff
+++ b/tests/mir-opt/inline/inline_into_box_place.main.Inline.diff
@@ -8,10 +8,10 @@
       scope 1 {
           debug _x => _1;                  // in scope 1 at $DIR/inline_into_box_place.rs:+1:9: +1:11
       }
-+     scope 2 (inlined Vec::<u32>::new) {  // at $DIR/inline_into_box_place.rs:7:38: 7:48
++     scope 2 (inlined Vec::<u32>::new) {  // at $DIR/inline_into_box_place.rs:8:38: 8:48
 +         let mut _3: alloc::raw_vec::RawVec<u32>; // in scope 2 at $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
 +     }
-+     scope 3 (inlined Box::<Vec<u32>>::new) { // at $DIR/inline_into_box_place.rs:7:29: 7:49
++     scope 3 (inlined Box::<Vec<u32>>::new) { // at $DIR/inline_into_box_place.rs:8:29: 8:49
 +         debug x => _2;                   // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
 +         let mut _4: usize;               // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
 +         let mut _5: usize;               // in scope 3 at $SRC_DIR/alloc/src/boxed.rs:LL:COL
@@ -28,7 +28,7 @@
 +         StorageLive(_3);                 // scope 2 at $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
 +         _3 = const _;                    // scope 2 at $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
                                            // mir::Constant
--                                          // + span: $DIR/inline_into_box_place.rs:7:38: 7:46
+-                                          // + span: $DIR/inline_into_box_place.rs:8:38: 8:46
 -                                          // + user_ty: UserType(2)
 -                                          // + literal: Const { ty: fn() -> Vec<u32> {Vec::<u32>::new}, val: Value(<ZST>) }
 +                                          // + span: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
@@ -47,7 +47,7 @@
       bb1: {
 -         _1 = Box::<Vec<u32>>::new(move _2) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/inline_into_box_place.rs:+1:29: +1:49
 -                                          // mir::Constant
--                                          // + span: $DIR/inline_into_box_place.rs:7:29: 7:37
+-                                          // + span: $DIR/inline_into_box_place.rs:8:29: 8:37
 -                                          // + user_ty: UserType(1)
 -                                          // + literal: Const { ty: fn(Vec<u32>) -> Box<Vec<u32>> {Box::<Vec<u32>>::new}, val: Value(<ZST>) }
 +         StorageDead(_1);                 // scope 0 at $DIR/inline_into_box_place.rs:+2:1: +2:2
diff --git a/tests/mir-opt/inline/inline_into_box_place.rs b/tests/mir-opt/inline/inline_into_box_place.rs
index b8b73f0c44c..02823e4e1b7 100644
--- a/tests/mir-opt/inline/inline_into_box_place.rs
+++ b/tests/mir-opt/inline/inline_into_box_place.rs
@@ -1,5 +1,6 @@
 // ignore-endian-big
 // ignore-wasm32-bare compiled with panic=abort by default
+// ignore-debug MIR alignment checks in std alter the diff, breaking the test
 // compile-flags: -Z mir-opt-level=4
 
 // EMIT_MIR inline_into_box_place.main.Inline.diff
diff --git a/tests/run-make/fmt-write-bloat/Makefile b/tests/run-make/fmt-write-bloat/Makefile
index 07e6e025e08..53615775486 100644
--- a/tests/run-make/fmt-write-bloat/Makefile
+++ b/tests/run-make/fmt-write-bloat/Makefile
@@ -11,11 +11,11 @@ else
 
 NM = nm
 
-PANIC_SYMS = panic_bounds_check pad_integral Display Debug
+PANIC_SYMS = panic_bounds_check Debug
 
 # Allow for debug_assert!() in debug builds of std.
 ifdef NO_DEBUG_ASSERTIONS
-PANIC_SYMS += panicking panic_fmt
+PANIC_SYMS += panicking panic_fmt pad_integral Display Debug
 endif
 
 all: main.rs
diff --git a/tests/ui/mir/mir_alignment_check.rs b/tests/ui/mir/mir_alignment_check.rs
new file mode 100644
index 00000000000..68a5384b30d
--- /dev/null
+++ b/tests/ui/mir/mir_alignment_check.rs
@@ -0,0 +1,12 @@
+// run-fail
+// ignore-wasm32-bare: No panic messages
+// compile-flags: -C debug-assertions
+// error-pattern: misaligned pointer dereference: address must be a multiple of 0x4 but is
+
+fn main() {
+    let mut x = [0u32; 2];
+    let ptr: *mut u8 = x.as_mut_ptr().cast::<u8>();
+    unsafe {
+        *(ptr.add(1).cast::<u32>()) = 42;
+    }
+}
diff --git a/tests/ui/process/signal-exit-status.rs b/tests/ui/process/signal-exit-status.rs
index 9519ed7b4c7..0f05f916cb9 100644
--- a/tests/ui/process/signal-exit-status.rs
+++ b/tests/ui/process/signal-exit-status.rs
@@ -4,14 +4,16 @@
 // ignore-windows
 // ignore-fuchsia code returned as ZX_TASK_RETCODE_EXCEPTION_KILL, FIXME (#58590)
 
+#![feature(core_intrinsics)]
+
 use std::env;
 use std::process::Command;
 
 pub fn main() {
     let args: Vec<String> = env::args().collect();
     if args.len() >= 2 && args[1] == "signal" {
-        // Raise a segfault.
-        unsafe { *(1 as *mut isize) = 0; }
+        // Raise an aborting signal without UB
+        core::intrinsics::abort();
     } else {
         let status = Command::new(&args[0]).arg("signal").status().unwrap();
         assert!(status.code().is_none());