add codegen test for #120440
This commit is contained in:
parent
13423befc4
commit
36e1414b10
1 changed files with 19 additions and 0 deletions
19
tests/codegen/slice-pointer-nonnull-unwrap.rs
Normal file
19
tests/codegen/slice-pointer-nonnull-unwrap.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
//@ compile-flags: -O
|
||||
//@ min-llvm-version: 18
|
||||
#![crate_type = "lib"]
|
||||
|
||||
use std::ptr::NonNull;
|
||||
|
||||
// CHECK-LABEL: @slice_ptr_len_1
|
||||
// CHECK: {{.*}}:
|
||||
// CHECK-NEXT: ret i64 %ptr.1
|
||||
#[no_mangle]
|
||||
pub fn slice_ptr_len_1(ptr: *const [u8]) -> usize {
|
||||
let ptr = ptr.cast_mut();
|
||||
if let Some(ptr) = NonNull::new(ptr) {
|
||||
ptr.len()
|
||||
} else {
|
||||
// We know ptr is null, so we know ptr.wrapping_byte_add(1) is not null.
|
||||
NonNull::new(ptr.wrapping_byte_add(1)).unwrap().len()
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue