Skip to content

Commit 8e99d92

Browse files
committed
Add regression tests for issue 80309
1 parent 427eba2 commit 8e99d92

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// run-pass
2+
// compiler-flags: -O
3+
4+
// Regression test for issue #80309
5+
6+
pub fn zero(x: usize) -> usize {
7+
std::ptr::null::<i8>().wrapping_add(x) as usize - x
8+
}
9+
pub fn qux(x: &[i8]) -> i8 {
10+
x[zero(x.as_ptr() as usize)]
11+
}
12+
13+
fn main() {
14+
let z = vec![42, 43];
15+
println!("{}", qux(&z));
16+
}

src/test/ui/ptr_ops/issue-80309.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-pass
2+
// compiler-flags: -O
3+
4+
// Regression test for issue #80309
5+
6+
pub unsafe fn foo(x: *const i8) -> i8 {
7+
*x.wrapping_sub(x as _).wrapping_add(x as _)
8+
}
9+
10+
fn main() {
11+
let x = 42;
12+
println!("{}", unsafe { foo(&x) });
13+
}

0 commit comments

Comments
 (0)