2024-05-20 12:53:07 -05:00
|
|
|
//@ compile-flags: -O
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
use std::ptr::NonNull;
|
|
|
|
|
|
|
|
// CHECK-LABEL: @slice_ptr_len_1
|
2024-06-09 08:25:12 -05:00
|
|
|
// CHECK-NEXT: {{.*}}:
|
2024-06-11 02:45:16 -05:00
|
|
|
// CHECK-NEXT: ret {{i(32|64)}} %ptr.1
|
2024-05-20 12:53:07 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn slice_ptr_len_1(ptr: *const [u8]) -> usize {
|
2024-06-09 08:25:12 -05:00
|
|
|
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()
|
|
|
|
}
|
2024-05-20 12:53:07 -05:00
|
|
|
}
|