summaryrefslogtreecommitdiffstats
path: root/tests/ui/ptr_ops
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/ptr_ops
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/ptr_ops')
-rw-r--r--tests/ui/ptr_ops/issue-80309-safe.rs16
-rw-r--r--tests/ui/ptr_ops/issue-80309.rs13
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/ui/ptr_ops/issue-80309-safe.rs b/tests/ui/ptr_ops/issue-80309-safe.rs
new file mode 100644
index 000000000..8a4ff1669
--- /dev/null
+++ b/tests/ui/ptr_ops/issue-80309-safe.rs
@@ -0,0 +1,16 @@
+// run-pass
+// compile-flags: -O
+
+// Regression test for issue #80309
+
+pub fn zero(x: usize) -> usize {
+ std::ptr::null::<i8>().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/tests/ui/ptr_ops/issue-80309.rs b/tests/ui/ptr_ops/issue-80309.rs
new file mode 100644
index 000000000..c13ce3c9c
--- /dev/null
+++ b/tests/ui/ptr_ops/issue-80309.rs
@@ -0,0 +1,13 @@
+// run-pass
+// 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) });
+}