2023-03-15 00:24:28 -05:00
|
|
|
//@ compile-flags: -O -Z merge-functions=disabled
|
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
|
|
|
|
|
|
|
// Ensure that various forms of reading pointers correctly annotate the `load`s
|
|
|
|
// with `!noundef` and `!range` metadata to enable extra optimization.
|
|
|
|
|
|
|
|
use std::mem::MaybeUninit;
|
|
|
|
|
2023-05-23 08:26:31 -05:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}noundef i8 @copy_byte(
|
2023-03-15 00:24:28 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn copy_byte(p: *const u8) -> u8 {
|
|
|
|
// CHECK-NOT: load
|
|
|
|
// CHECK: load i8, ptr %p, align 1
|
|
|
|
// CHECK-SAME: !noundef !
|
|
|
|
// CHECK-NOT: load
|
|
|
|
*p
|
|
|
|
}
|
|
|
|
|
2023-05-23 08:26:31 -05:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}noundef i8 @read_byte(
|
2023-03-15 00:24:28 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn read_byte(p: *const u8) -> u8 {
|
|
|
|
// CHECK-NOT: load
|
|
|
|
// CHECK: load i8, ptr %p, align 1
|
|
|
|
// CHECK-SAME: !noundef !
|
|
|
|
// CHECK-NOT: load
|
|
|
|
p.read()
|
|
|
|
}
|
|
|
|
|
2023-05-23 08:26:31 -05:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}i8 @read_byte_maybe_uninit(
|
2023-03-15 00:24:28 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn read_byte_maybe_uninit(p: *const MaybeUninit<u8>) -> MaybeUninit<u8> {
|
|
|
|
// CHECK-NOT: load
|
|
|
|
// CHECK: load i8, ptr %p, align 1
|
|
|
|
// CHECK-NOT: noundef
|
|
|
|
// CHECK-NOT: load
|
|
|
|
p.read()
|
|
|
|
}
|
|
|
|
|
2023-05-23 08:26:31 -05:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}noundef i8 @read_byte_assume_init(
|
2023-03-15 00:24:28 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn read_byte_assume_init(p: &MaybeUninit<u8>) -> u8 {
|
|
|
|
// CHECK-NOT: load
|
|
|
|
// CHECK: load i8, ptr %p, align 1
|
|
|
|
// CHECK-SAME: !noundef !
|
|
|
|
// CHECK-NOT: load
|
|
|
|
p.assume_init_read()
|
|
|
|
}
|
|
|
|
|
2023-05-23 08:26:31 -05:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}noundef i32 @copy_char(
|
2023-03-15 00:24:28 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn copy_char(p: *const char) -> char {
|
|
|
|
// CHECK-NOT: load
|
|
|
|
// CHECK: load i32, ptr %p
|
|
|
|
// CHECK-SAME: !range ![[RANGE:[0-9]+]]
|
|
|
|
// CHECK-SAME: !noundef !
|
|
|
|
// CHECK-NOT: load
|
|
|
|
*p
|
|
|
|
}
|
|
|
|
|
2023-05-23 08:26:31 -05:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}noundef i32 @read_char(
|
2023-03-15 00:24:28 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn read_char(p: *const char) -> char {
|
|
|
|
// CHECK-NOT: load
|
|
|
|
// CHECK: load i32, ptr %p
|
|
|
|
// CHECK-SAME: !range ![[RANGE]]
|
|
|
|
// CHECK-SAME: !noundef !
|
|
|
|
// CHECK-NOT: load
|
|
|
|
p.read()
|
|
|
|
}
|
|
|
|
|
2023-05-23 08:26:31 -05:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}i32 @read_char_maybe_uninit(
|
2023-03-15 00:24:28 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn read_char_maybe_uninit(p: *const MaybeUninit<char>) -> MaybeUninit<char> {
|
|
|
|
// CHECK-NOT: load
|
|
|
|
// CHECK: load i32, ptr %p
|
|
|
|
// CHECK-NOT: range
|
|
|
|
// CHECK-NOT: noundef
|
|
|
|
// CHECK-NOT: load
|
|
|
|
p.read()
|
|
|
|
}
|
|
|
|
|
2023-05-23 08:26:31 -05:00
|
|
|
// CHECK-LABEL: define {{(dso_local )?}}noundef i32 @read_char_assume_init(
|
2023-03-15 00:24:28 -05:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe fn read_char_assume_init(p: &MaybeUninit<char>) -> char {
|
|
|
|
// CHECK-NOT: load
|
|
|
|
// CHECK: load i32, ptr %p
|
|
|
|
// CHECK-SAME: !range ![[RANGE]]
|
|
|
|
// CHECK-SAME: !noundef !
|
|
|
|
// CHECK-NOT: load
|
|
|
|
p.assume_init_read()
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK: ![[RANGE]] = !{i32 0, i32 1114112}
|