blob: 252735883aa5e26ca47563e00b74a80b3a5ff7b4 [file] [edit]
//@ compile-flags: -Copt-level=3 -Cpanic=abort
#![crate_type = "lib"]
use std::ffi::CStr;
// A `CStr` always contains at least its trailing nul byte.
// CHECK-LABEL: @cstr_with_nul_is_nonempty
#[no_mangle]
pub fn cstr_with_nul_is_nonempty(s: &CStr) -> bool {
// CHECK: ret i1 true
!s.to_bytes_with_nul().is_empty()
}
// CHECK-LABEL: @cstr_first_with_nul
#[no_mangle]
pub fn cstr_first_with_nul(s: &CStr) -> u8 {
// CHECK-NOT: panic_bounds_check
// CHECK: ret i8
s.to_bytes_with_nul()[0]
}