mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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:
commit
520bd359a3
17
src/test/ui/ptr_ops/issue-80309-safe.rs
Normal file
17
src/test/ui/ptr_ops/issue-80309-safe.rs
Normal 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));
|
||||
}
|
14
src/test/ui/ptr_ops/issue-80309.rs
Normal file
14
src/test/ui/ptr_ops/issue-80309.rs
Normal 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) });
|
||||
}
|
Loading…
Reference in New Issue
Block a user