From 631cd5845e8de329d0e227aaa707d7ea228b8f8f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:29 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/mir/addrof_alignment.rs | 15 +++++++++++++++ tests/ui/mir/checks_without_panic_impl.rs | 17 +++++++++++++++++ tests/ui/mir/issue-109004-drop-large-array.rs | 16 ++++++++++++++++ tests/ui/mir/mir_alignment_check.rs | 12 ++++++++++++ tests/ui/mir/mir_boxing.rs | 10 ---------- tests/ui/mir/unsize-trait.rs | 15 +++++++++++++++ tests/ui/mir/validate/transmute_cast_sized.rs | 17 +++++++++++++++++ 7 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 tests/ui/mir/addrof_alignment.rs create mode 100644 tests/ui/mir/checks_without_panic_impl.rs create mode 100644 tests/ui/mir/issue-109004-drop-large-array.rs create mode 100644 tests/ui/mir/mir_alignment_check.rs delete mode 100644 tests/ui/mir/mir_boxing.rs create mode 100644 tests/ui/mir/unsize-trait.rs create mode 100644 tests/ui/mir/validate/transmute_cast_sized.rs (limited to 'tests/ui/mir') 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::().add(1).cast::(); + 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::(); + unsafe { + *(ptr.add(1).cast::()) = 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 { - 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(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]); + }; +} -- cgit v1.2.3