Skip to content

Commit

Permalink
Add regression tests for issue 80309
Browse files Browse the repository at this point in the history
  • Loading branch information
WaffleLapkin committed Feb 4, 2022
1 parent 427eba2 commit 8e99d92
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 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,16 @@
// run-pass
// 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));
}
13 changes: 13 additions & 0 deletions src/test/ui/ptr_ops/issue-80309.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// run-pass
// 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 8e99d92

Please sign in to comment.