From 8e99d92f4ecaf7c6d8deae4461d4781c4194bf24 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 4 Feb 2022 17:11:51 +0300 Subject: [PATCH 1/2] Add regression tests for issue 80309 --- src/test/ui/ptr_ops/issue-80309-safe.rs | 16 ++++++++++++++++ src/test/ui/ptr_ops/issue-80309.rs | 13 +++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/test/ui/ptr_ops/issue-80309-safe.rs create mode 100644 src/test/ui/ptr_ops/issue-80309.rs 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 0000000000000..16c2580303776 --- /dev/null +++ b/src/test/ui/ptr_ops/issue-80309-safe.rs @@ -0,0 +1,16 @@ +// run-pass +// compiler-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 0000000000000..191ae5f42d231 --- /dev/null +++ b/src/test/ui/ptr_ops/issue-80309.rs @@ -0,0 +1,13 @@ +// run-pass +// compiler-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) }); +} From a3b1bc13882197900f4a6858c465f67ffb75f1fe Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 4 Feb 2022 21:18:56 +0300 Subject: [PATCH 2/2] Specify min llvm version for issue 80309 regression tests --- src/test/ui/ptr_ops/issue-80309-safe.rs | 1 + src/test/ui/ptr_ops/issue-80309.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/test/ui/ptr_ops/issue-80309-safe.rs b/src/test/ui/ptr_ops/issue-80309-safe.rs index 16c2580303776..ca3778aab2da3 100644 --- a/src/test/ui/ptr_ops/issue-80309-safe.rs +++ b/src/test/ui/ptr_ops/issue-80309-safe.rs @@ -1,4 +1,5 @@ // run-pass +// min-llvm-version: 13.0 // compiler-flags: -O // Regression test for issue #80309 diff --git a/src/test/ui/ptr_ops/issue-80309.rs b/src/test/ui/ptr_ops/issue-80309.rs index 191ae5f42d231..bbec1012082c3 100644 --- a/src/test/ui/ptr_ops/issue-80309.rs +++ b/src/test/ui/ptr_ops/issue-80309.rs @@ -1,4 +1,5 @@ // run-pass +// min-llvm-version: 13.0 // compiler-flags: -O // Regression test for issue #80309