From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/ptr_ops/issue-80309-safe.rs | 17 +++++++++++++++++ src/test/ui/ptr_ops/issue-80309.rs | 14 ++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/ui/ptr_ops/issue-80309-safe.rs create mode 100644 src/test/ui/ptr_ops/issue-80309.rs (limited to 'src/test/ui/ptr_ops') diff --git a/src/test/ui/ptr_ops/issue-80309-safe.rs b/src/test/ui/ptr_ops/issue-80309-safe.rs new file mode 100644 index 000000000..f7513b6b8 --- /dev/null +++ b/src/test/ui/ptr_ops/issue-80309-safe.rs @@ -0,0 +1,17 @@ +// run-pass +// min-llvm-version: 13.0 +// compile-flags: -O + +// Regression test for issue #80309 + +pub fn zero(x: usize) -> usize { + std::ptr::null::().wrapping_add(x) as usize - x +} +pub fn qux(x: &[i8]) -> i8 { + x[zero(x.as_ptr() as usize)] +} + +fn main() { + let z = vec![42, 43]; + println!("{}", qux(&z)); +} diff --git a/src/test/ui/ptr_ops/issue-80309.rs b/src/test/ui/ptr_ops/issue-80309.rs new file mode 100644 index 000000000..5c0f4b76c --- /dev/null +++ b/src/test/ui/ptr_ops/issue-80309.rs @@ -0,0 +1,14 @@ +// run-pass +// min-llvm-version: 13.0 +// compile-flags: -O + +// Regression test for issue #80309 + +pub unsafe fn foo(x: *const i8) -> i8 { + *x.wrapping_sub(x as _).wrapping_add(x as _) +} + +fn main() { + let x = 42; + println!("{}", unsafe { foo(&x) }); +} -- cgit v1.2.3