diff options
| author | bors <bors@rust-lang.org> | 2022-02-27 21:41:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-02-27 21:41:06 +0000 |
| commit | 9fbff89354ba7a4ec2d1191a3f405cbe408370f6 (patch) | |
| tree | be5786736399ab8be46745ceb4239a9155b5ac79 /src/test/codegen/function-arguments.rs | |
| parent | 6a705566166debf5eff88c57140df607fa409aaa (diff) | |
| parent | 45ee3fc700950da07e0682c6bf56b9c123fbf995 (diff) | |
| download | rust-9fbff89354ba7a4ec2d1191a3f405cbe408370f6.tar.gz rust-9fbff89354ba7a4ec2d1191a3f405cbe408370f6.zip | |
Auto merge of #94157 - erikdesjardins:more-noundef, r=nikic
Apply noundef attribute to all scalar types which do not permit raw init Beyond `&`/`&mut`/`Box`, this covers `char`, enum discriminants, `NonZero*`, etc. All such types currently cause a Miri error if left uninitialized, and an `invalid_value` lint in cases like `mem::uninitialized::<char>()`. Note that this _does not_ change whether or not it is UB for `u64` (or other integer types with no invalid values) to be undef. Fixes (partially) #74378. r? `@ghost` (blocked on #94127) `@rustbot` label S-blocked
Diffstat (limited to 'src/test/codegen/function-arguments.rs')
| -rw-r--r-- | src/test/codegen/function-arguments.rs | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs index 17b54d86cb0..b1ccbdd934a 100644 --- a/src/test/codegen/function-arguments.rs +++ b/src/test/codegen/function-arguments.rs @@ -4,6 +4,7 @@ #![feature(rustc_attrs)] use std::mem::MaybeUninit; +use std::num::NonZeroU64; pub struct S { _field: [i32; 8], @@ -13,6 +14,11 @@ pub struct UnsafeInner { _field: std::cell::UnsafeCell<i16>, } +pub enum MyBool { + True, + False, +} + // CHECK: noundef zeroext i1 @boolean(i1 noundef zeroext %x) #[no_mangle] pub fn boolean(x: bool) -> bool { @@ -25,6 +31,48 @@ pub fn maybeuninit_boolean(x: MaybeUninit<bool>) -> MaybeUninit<bool> { x } +// CHECK: noundef zeroext i1 @enum_bool(i1 noundef zeroext %x) +#[no_mangle] +pub fn enum_bool(x: MyBool) -> MyBool { + x +} + +// CHECK: i8 @maybeuninit_enum_bool(i8 %x) +#[no_mangle] +pub fn maybeuninit_enum_bool(x: MaybeUninit<MyBool>) -> MaybeUninit<MyBool> { + x +} + +// CHECK: noundef i32 @char(i32 noundef %x) +#[no_mangle] +pub fn char(x: char) -> char { + x +} + +// CHECK: i32 @maybeuninit_char(i32 %x) +#[no_mangle] +pub fn maybeuninit_char(x: MaybeUninit<char>) -> MaybeUninit<char> { + x +} + +// CHECK: i64 @int(i64 %x) +#[no_mangle] +pub fn int(x: u64) -> u64 { + x +} + +// CHECK: noundef i64 @nonzero_int(i64 noundef %x) +#[no_mangle] +pub fn nonzero_int(x: NonZeroU64) -> NonZeroU64 { + x +} + +// CHECK: i64 @option_nonzero_int(i64 %x) +#[no_mangle] +pub fn option_nonzero_int(x: Option<NonZeroU64>) -> Option<NonZeroU64> { + x +} + // CHECK: @readonly_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1) // FIXME #25759 This should also have `nocapture` #[no_mangle] @@ -156,7 +204,7 @@ pub fn return_slice(x: &[u16]) -> &[u16] { x } -// CHECK: { i16, i16 } @enum_id_1(i16 %x.0, i16 %x.1) +// CHECK: { i16, i16 } @enum_id_1(i16 noundef %x.0, i16 %x.1) #[no_mangle] pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> { x |
