diff options
Diffstat (limited to 'tests/ui/ptr_ops/issue-80309-safe.rs')
-rw-r--r-- | tests/ui/ptr_ops/issue-80309-safe.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/ui/ptr_ops/issue-80309-safe.rs b/tests/ui/ptr_ops/issue-80309-safe.rs new file mode 100644 index 000000000..8a4ff1669 --- /dev/null +++ b/tests/ui/ptr_ops/issue-80309-safe.rs @@ -0,0 +1,16 @@ +// run-pass +// compile-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)); +} |