Skip to content

Commit

Permalink
Rollup merge of #93649 - WaffleLapkin:regression_test_80309, r=oli-obk
Browse files Browse the repository at this point in the history
Add regression tests for issue 80309

Closes #80309 馃槤

I'm not sure where to put the tests, is `ui/issues` the right place for this kind of tests?
  • Loading branch information
matthiaskrgr committed Feb 6, 2022
2 parents 59baf4d + a3b1bc1 commit 520bd35
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/ui/ptr_ops/issue-80309-safe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-pass
// min-llvm-version: 13.0
// compiler-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));
}
14 changes: 14 additions & 0 deletions src/test/ui/ptr_ops/issue-80309.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run-pass
// min-llvm-version: 13.0
// 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) });
}

0 comments on commit 520bd35

Please sign in to comment.