Skip to content
/ rustc Public
forked from rust-lang/rust

Commit

Permalink
add codegen test for rust-lang#120440
Browse files Browse the repository at this point in the history
  • Loading branch information
tesuji committed May 20, 2024
1 parent 6982935 commit ab8b456
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/codegen/slice-pointer-nonnull-unwrap.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}

0 comments on commit ab8b456

Please sign in to comment.