diff options
| author | bors <bors@rust-lang.org> | 2022-02-28 06:11:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-02-28 06:11:20 +0000 |
| commit | 427cf81206d3b6cf41c86c1b9ce113a33f1ce860 (patch) | |
| tree | a387fba5f3b3800f23355308503ba27016e575b2 /src/test/codegen | |
| parent | ec0ab61e8adb5dff04b5f39e6e4faecffd776441 (diff) | |
| parent | fec4335407c9a292c524e07996ccd4d26c563548 (diff) | |
Auto merge of #94158 - erikdesjardins:more-more-noundef, r=nikic
Apply noundef metadata to loads of types that do not permit raw init This matches the noundef attributes we apply on arguments/return types. Fixes (partially) #74378.
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/loads.rs | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/src/test/codegen/loads.rs b/src/test/codegen/loads.rs index 3c9ecec2cbf..977175a4a62 100644 --- a/src/test/codegen/loads.rs +++ b/src/test/codegen/loads.rs @@ -2,11 +2,87 @@ #![crate_type = "lib"] +use std::mem::MaybeUninit; +use std::num::NonZeroU16; + pub struct Bytes { - a: u8, - b: u8, - c: u8, - d: u8, + a: u8, + b: u8, + c: u8, + d: u8, +} + +#[derive(Copy, Clone)] +pub enum MyBool { + True, + False, +} + +// CHECK-LABEL: @load_ref +#[no_mangle] +pub fn load_ref<'a>(x: &&'a i32) -> &'a i32 { +// Alignment of a reference itself is target dependent, so just match any alignment: +// the main thing we care about here is !nonnull and !noundef. +// CHECK: load i32*, i32** %x, align {{[0-9]+}}, !nonnull !{{[0-9]+}}, !noundef !{{[0-9]+}} + *x +} + +// CHECK-LABEL: @load_box +#[no_mangle] +pub fn load_box<'a>(x: Box<Box<i32>>) -> Box<i32> { +// Alignment of a box itself is target dependent, so just match any alignment: +// the main thing we care about here is !nonnull and !noundef. +// CHECK: load i32*, i32** %x, align {{[0-9]+}}, !nonnull !{{[0-9]+}}, !noundef !{{[0-9]+}} + *x +} + +// CHECK-LABEL: @load_bool +#[no_mangle] +pub fn load_bool(x: &bool) -> bool { +// CHECK: load i8, i8* %x, align 1, !range ![[BOOL_RANGE:[0-9]+]], !noundef !{{[0-9]+}} + *x +} + +// CHECK-LABEL: @load_maybeuninit_bool +#[no_mangle] +pub fn load_maybeuninit_bool(x: &MaybeUninit<bool>) -> MaybeUninit<bool> { +// CHECK: load i8, i8* %x, align 1{{$}} + *x +} + +// CHECK-LABEL: @load_enum_bool +#[no_mangle] +pub fn load_enum_bool(x: &MyBool) -> MyBool { +// CHECK: load i8, i8* %x, align 1, !range ![[BOOL_RANGE]], !noundef !{{[0-9]+}} + *x +} + +// CHECK-LABEL: @load_maybeuninit_enum_bool +#[no_mangle] +pub fn load_maybeuninit_enum_bool(x: &MaybeUninit<MyBool>) -> MaybeUninit<MyBool> { +// CHECK: load i8, i8* %x, align 1{{$}} + *x +} + +// CHECK-LABEL: @load_int +#[no_mangle] +pub fn load_int(x: &u16) -> u16 { +// CHECK: load i16, i16* %x, align 2{{$}} + *x +} + +// CHECK-LABEL: @load_nonzero_int +#[no_mangle] +pub fn load_nonzero_int(x: &NonZeroU16) -> NonZeroU16 { +// CHECK: load i16, i16* %x, align 2, !range ![[NONZEROU16_RANGE:[0-9]+]], !noundef !{{[0-9]+}} + *x +} + +// CHECK-LABEL: @load_option_nonzero_int +#[no_mangle] +pub fn load_option_nonzero_int(x: &Option<NonZeroU16>) -> Option<NonZeroU16> { +// CHECK: load i16, i16* %x, align 2{{$}} + *x } // CHECK-LABEL: @borrow @@ -43,3 +119,6 @@ pub fn small_struct_alignment(x: Bytes) -> Bytes { // CHECK: ret i32 [[VAR]] x } + +// CHECK: ![[BOOL_RANGE]] = !{i8 0, i8 2} +// CHECK: ![[NONZEROU16_RANGE]] = !{i16 1, i16 0} |
