Rollup merge of #93649 - WaffleLapkin:regression_test_80309, r=oli-obk

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?
This commit is contained in:
Matthias Krüger 2022-02-06 04:13:33 +01:00 committed by GitHub
commit 520bd359a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -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));
}

View File

@ -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) });
}