Skip to content

Commit 205f6e8

Browse files
authored
Rollup merge of rust-lang#93649 - WaffleLapkin:regression_test_80309, r=oli-obk
Add regression tests for issue 80309 Closes rust-lang#80309 😝 I'm not sure where to put the tests, is `ui/issues` the right place for this kind of tests?
2 parents 39e2070 + a3b1bc1 commit 205f6e8

File tree

2 files changed

+31
-0
lines changed

2 files changed

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

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

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

0 commit comments

Comments
 (0)