summaryrefslogtreecommitdiffstats
path: root/src/test/ui/ptr_ops
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/ptr_ops
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/ptr_ops')
-rw-r--r--src/test/ui/ptr_ops/issue-80309-safe.rs17
-rw-r--r--src/test/ui/ptr_ops/issue-80309.rs14
2 files changed, 31 insertions, 0 deletions
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::<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/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) });
+}