summaryrefslogtreecommitdiffstats
path: root/tests/ui/mir
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/mir')
-rw-r--r--tests/ui/mir/addrof_alignment.rs15
-rw-r--r--tests/ui/mir/checks_without_panic_impl.rs17
-rw-r--r--tests/ui/mir/issue-109004-drop-large-array.rs16
-rw-r--r--tests/ui/mir/mir_alignment_check.rs12
-rw-r--r--tests/ui/mir/mir_boxing.rs10
-rw-r--r--tests/ui/mir/unsize-trait.rs15
-rw-r--r--tests/ui/mir/validate/transmute_cast_sized.rs17
7 files changed, 92 insertions, 10 deletions
diff --git a/tests/ui/mir/addrof_alignment.rs b/tests/ui/mir/addrof_alignment.rs
new file mode 100644
index 000000000..892638bfb
--- /dev/null
+++ b/tests/ui/mir/addrof_alignment.rs
@@ -0,0 +1,15 @@
+// run-pass
+// ignore-wasm32-bare: No panic messages
+// compile-flags: -C debug-assertions
+
+struct Misalignment {
+ a: u32,
+}
+
+fn main() {
+ let items: [Misalignment; 2] = [Misalignment { a: 0 }, Misalignment { a: 1 }];
+ unsafe {
+ let ptr: *const Misalignment = items.as_ptr().cast::<u8>().add(1).cast::<Misalignment>();
+ let _ptr = core::ptr::addr_of!((*ptr).a);
+ }
+}
diff --git a/tests/ui/mir/checks_without_panic_impl.rs b/tests/ui/mir/checks_without_panic_impl.rs
new file mode 100644
index 000000000..04f410b77
--- /dev/null
+++ b/tests/ui/mir/checks_without_panic_impl.rs
@@ -0,0 +1,17 @@
+// Ensures that the alignment check we insert for raw pointer dereferences
+// does not prevent crates without a panic_impl from compiling.
+// See rust-lang/rust#109996
+
+// build-pass
+// compile-flags: -Cdebug-assertions=yes
+
+#![crate_type = "lib"]
+
+#![feature(lang_items)]
+#![feature(no_core)]
+#![no_core]
+
+#[lang = "sized"]
+trait Foo {}
+
+pub unsafe fn foo(x: *const i32) -> &'static i32 { unsafe { &*x } }
diff --git a/tests/ui/mir/issue-109004-drop-large-array.rs b/tests/ui/mir/issue-109004-drop-large-array.rs
new file mode 100644
index 000000000..5e3361cef
--- /dev/null
+++ b/tests/ui/mir/issue-109004-drop-large-array.rs
@@ -0,0 +1,16 @@
+// check-pass
+
+const SZ: usize = 64_000_000;
+type BigDrop = [String; SZ];
+
+fn f(_dropme: BigDrop) {}
+
+fn f2(_moveme: BigDrop) -> String {
+ let [a, ..] = _moveme;
+ a
+}
+
+fn main() {
+ f(std::array::from_fn(|_| String::new()));
+ f2(std::array::from_fn(|_| String::new()));
+}
diff --git a/tests/ui/mir/mir_alignment_check.rs b/tests/ui/mir/mir_alignment_check.rs
new file mode 100644
index 000000000..68a5384b3
--- /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/mir/mir_boxing.rs b/tests/ui/mir/mir_boxing.rs
deleted file mode 100644
index 83e1cfb64..000000000
--- a/tests/ui/mir/mir_boxing.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-// run-pass
-#![feature(box_syntax)]
-
-fn test() -> Box<i32> {
- box 42
-}
-
-fn main() {
- assert_eq!(*test(), 42);
-}
diff --git a/tests/ui/mir/unsize-trait.rs b/tests/ui/mir/unsize-trait.rs
new file mode 100644
index 000000000..45b5308c0
--- /dev/null
+++ b/tests/ui/mir/unsize-trait.rs
@@ -0,0 +1,15 @@
+// Check that the interpreter does not ICE when trying to unsize `B` to `[u8]`.
+// This is a `build` test to ensure that const-prop-lint runs.
+// build-pass
+
+#![feature(unsize)]
+
+fn foo<B>(buffer: &mut [B; 2])
+ where B: std::marker::Unsize<[u8]>,
+{
+ let buffer: &[u8] = &buffer[0];
+}
+
+fn main() {
+ foo(&mut [[0], [5]]);
+}
diff --git a/tests/ui/mir/validate/transmute_cast_sized.rs b/tests/ui/mir/validate/transmute_cast_sized.rs
new file mode 100644
index 000000000..eaaf7eb3e
--- /dev/null
+++ b/tests/ui/mir/validate/transmute_cast_sized.rs
@@ -0,0 +1,17 @@
+// build-pass
+// compile-flags: -Zvalidate-mir
+// edition: 2021
+
+#![crate_type = "lib"]
+
+// Use `PhantomData` to get target-independent size
+async fn get(_r: std::marker::PhantomData<&i32>) {
+ loop {}
+}
+
+pub fn check() {
+ let mut v = get(loop {});
+ let _ = || unsafe {
+ v = std::mem::transmute([0_u8; 1]);
+ };
+}