diff options
| author | bors <bors@rust-lang.org> | 2022-02-13 00:14:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-02-13 00:14:52 +0000 |
| commit | 5c30d6568383916ce97cdf20ceb61a8b9e5bb5a8 (patch) | |
| tree | f46d936ef6bc64bd6f032bca84e9711a0e572d7b /src/test/codegen/function-arguments.rs | |
| parent | 3cfa4def7c87d571bd46d92fed608edf8fad236e (diff) | |
| parent | 401307759aaf6f1e49c8a2c840a76ae41ec1f865 (diff) | |
| download | rust-5c30d6568383916ce97cdf20ceb61a8b9e5bb5a8.tar.gz rust-5c30d6568383916ce97cdf20ceb61a8b9e5bb5a8.zip | |
Auto merge of #93670 - erikdesjardins:noundef, r=nikic
Apply noundef attribute to &T, &mut T, Box<T>, bool This doesn't handle `char` because it's a bit awkward to distinguish it from `u32` at this point in codegen. Note that this _does not_ change whether or not it is UB for `&`, `&mut`, or `Box` to point to undef. It only applies to the pointer itself, not the pointed-to memory. Fixes (partially) #74378. r? `@nikic` cc `@RalfJung`
Diffstat (limited to 'src/test/codegen/function-arguments.rs')
| -rw-r--r-- | src/test/codegen/function-arguments.rs | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/src/test/codegen/function-arguments.rs b/src/test/codegen/function-arguments.rs index 3e10e227e55..17b54d86cb0 100644 --- a/src/test/codegen/function-arguments.rs +++ b/src/test/codegen/function-arguments.rs @@ -3,6 +3,8 @@ #![crate_type = "lib"] #![feature(rustc_attrs)] +use std::mem::MaybeUninit; + pub struct S { _field: [i32; 8], } @@ -11,68 +13,79 @@ pub struct UnsafeInner { _field: std::cell::UnsafeCell<i16>, } -// CHECK: zeroext i1 @boolean(i1 zeroext %x) +// CHECK: noundef zeroext i1 @boolean(i1 noundef zeroext %x) #[no_mangle] pub fn boolean(x: bool) -> bool { x } -// CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1) +// CHECK: i8 @maybeuninit_boolean(i8 %x) +#[no_mangle] +pub fn maybeuninit_boolean(x: MaybeUninit<bool>) -> MaybeUninit<bool> { + x +} + +// CHECK: @readonly_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn readonly_borrow(_: &i32) { } -// CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1) +// CHECK: @static_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1) // static borrow may be captured #[no_mangle] pub fn static_borrow(_: &'static i32) { } -// CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1) +// CHECK: @named_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1) // borrow with named lifetime may be captured #[no_mangle] pub fn named_borrow<'r>(_: &'r i32) { } -// CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %_1) +// CHECK: @unsafe_borrow(i16* noundef align 2 dereferenceable(2) %_1) // unsafe interior means this isn't actually readonly and there may be aliases ... #[no_mangle] pub fn unsafe_borrow(_: &UnsafeInner) { } -// CHECK: @mutable_unsafe_borrow(i16* noalias align 2 dereferenceable(2) %_1) +// CHECK: @mutable_unsafe_borrow(i16* noalias noundef align 2 dereferenceable(2) %_1) // ... unless this is a mutable borrow, those never alias #[no_mangle] pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) { } -// CHECK: @mutable_borrow(i32* noalias align 4 dereferenceable(4) %_1) +// CHECK: @mutable_borrow(i32* noalias noundef align 4 dereferenceable(4) %_1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn mutable_borrow(_: &mut i32) { } -// CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %_1) +// CHECK: @indirect_struct(%S* noalias nocapture noundef dereferenceable(32) %_1) #[no_mangle] pub fn indirect_struct(_: S) { } -// CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %_1) +// CHECK: @borrowed_struct(%S* noalias noundef readonly align 4 dereferenceable(32) %_1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn borrowed_struct(_: &S) { } +// CHECK: @raw_struct(%S* %_1) +#[no_mangle] +pub fn raw_struct(_: *const S) { +} + // `Box` can get deallocated during execution of the function, so it should // not get `dereferenceable`. -// CHECK: noalias nonnull align 4 i32* @_box(i32* noalias nonnull align 4 %x) +// CHECK: noalias noundef nonnull align 4 i32* @_box(i32* noalias noundef nonnull align 4 %x) #[no_mangle] pub fn _box(x: Box<i32>) -> Box<i32> { x } -// CHECK: @struct_return(%S* noalias nocapture sret(%S) dereferenceable(32){{( %0)?}}) +// CHECK: @struct_return(%S* noalias nocapture noundef sret(%S) dereferenceable(32){{( %0)?}}) #[no_mangle] pub fn struct_return() -> S { S { @@ -86,48 +99,58 @@ pub fn struct_return() -> S { pub fn helper(_: usize) { } -// CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1) +// CHECK: @slice([0 x i8]* noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn slice(_: &[u8]) { } -// CHECK: @mutable_slice([0 x i8]* noalias nonnull align 1 %_1.0, [[USIZE]] %_1.1) +// CHECK: @mutable_slice([0 x i8]* noalias noundef nonnull align 1 %_1.0, [[USIZE]] %_1.1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn mutable_slice(_: &mut [u8]) { } -// CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %_1.0, [[USIZE]] %_1.1) +// CHECK: @unsafe_slice([0 x i16]* noundef nonnull align 2 %_1.0, [[USIZE]] %_1.1) // unsafe interior means this isn't actually readonly and there may be aliases ... #[no_mangle] pub fn unsafe_slice(_: &[UnsafeInner]) { } -// CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1) +// CHECK: @raw_slice([0 x i8]* %_1.0, [[USIZE]] %_1.1) +#[no_mangle] +pub fn raw_slice(_: *const [u8]) { +} + +// CHECK: @str([0 x i8]* noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn str(_: &[u8]) { } -// CHECK: @trait_borrow({}* nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %_1.1) +// CHECK: @trait_borrow({}* noundef nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1) // FIXME #25759 This should also have `nocapture` #[no_mangle] pub fn trait_borrow(_: &Drop) { } -// CHECK: @trait_box({}* noalias nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}}) +// CHECK: @trait_raw({}* %_1.0, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1) +#[no_mangle] +pub fn trait_raw(_: *const Drop) { +} + +// CHECK: @trait_box({}* noalias noundef nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}}) #[no_mangle] pub fn trait_box(_: Box<Drop>) { } -// CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1) +// CHECK: { i8*, i8* } @trait_option(i8* noalias noundef align 1 %x.0, i8* %x.1) #[no_mangle] pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> { x } -// CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1) +// CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias noundef nonnull readonly align 2 %x.0, [[USIZE]] %x.1) #[no_mangle] pub fn return_slice(x: &[u16]) -> &[u16] { x @@ -139,7 +162,7 @@ pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> { x } -// CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1) +// CHECK: { i8, i8 } @enum_id_2(i1 noundef zeroext %x.0, i8 %x.1) #[no_mangle] pub fn enum_id_2(x: Option<u8>) -> Option<u8> { x |
