Skip to content

Commit

Permalink
Rollup merge of rust-lang#93649 - WaffleLapkin:regression_test_80309,…
Browse files Browse the repository at this point in the history
… 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?
  • Loading branch information
matthiaskrgr authored Feb 5, 2022
2 parents 39e2070 + a3b1bc1 commit 205f6e8
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 205f6e8

Please sign in to comment.