diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-07-04 16:01:16 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-07-20 11:33:49 -0700 |
| commit | 34732e8560a3fea72bab9f2c9840897faa4f55b5 (patch) | |
| tree | 0c965eb3f105dba15e765274bade0805cbb67ff3 /tests/codegen/slice-iter-nonnull.rs | |
| parent | 06a53ddc0bd3a50f9bcf2f7c373011dc7869f59f (diff) | |
| download | rust-34732e8560a3fea72bab9f2c9840897faa4f55b5.tar.gz rust-34732e8560a3fea72bab9f2c9840897faa4f55b5.zip | |
Get `!nonnull` metadata consistently in slice iterators, without needing `assume`s
Diffstat (limited to 'tests/codegen/slice-iter-nonnull.rs')
| -rw-r--r-- | tests/codegen/slice-iter-nonnull.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/codegen/slice-iter-nonnull.rs b/tests/codegen/slice-iter-nonnull.rs index 997bdaf5636..f7d164bc856 100644 --- a/tests/codegen/slice-iter-nonnull.rs +++ b/tests/codegen/slice-iter-nonnull.rs @@ -2,11 +2,16 @@ // compile-flags: -O // ignore-debug (these add extra checks that make it hard to verify) #![crate_type = "lib"] +#![feature(exact_size_is_empty)] // The slice iterator used to `assume` that the `start` pointer was non-null. // That ought to be unneeded, though, since the type is `NonNull`, so this test // confirms that the appropriate metadata is included to denote that. +// It also used to `assume` the `end` pointer was non-null, but that's no longer +// needed as the code changed to read it as a `NonNull`, and thus gets the +// appropriate `!nonnull` annotations naturally. + // CHECK-LABEL: @slice_iter_next( #[no_mangle] pub fn slice_iter_next<'a>(it: &mut std::slice::Iter<'a, u32>) -> Option<&'a u32> { @@ -75,3 +80,37 @@ pub fn slice_iter_mut_new(slice: &mut [u32]) -> std::slice::IterMut<'_, u32> { // CHECK: } slice.iter_mut() } + +// CHECK-LABEL: @slice_iter_is_empty +#[no_mangle] +pub fn slice_iter_is_empty(it: &std::slice::Iter<'_, u32>) -> bool { + // CHECK: %[[ENDP:.+]] = getelementptr{{.+}}ptr %it,{{.+}} 1 + // CHECK: %[[END:.+]] = load ptr, ptr %[[ENDP]] + // CHECK-SAME: !nonnull + // CHECK-SAME: !noundef + // CHECK: %[[START:.+]] = load ptr, ptr %it, + // CHECK-SAME: !nonnull + // CHECK-SAME: !noundef + + // CHECK: %[[RET:.+]] = icmp eq ptr %[[START]], %[[END]] + // CHECK: ret i1 %[[RET]] + it.is_empty() +} + +// CHECK-LABEL: @slice_iter_len +#[no_mangle] +pub fn slice_iter_len(it: &std::slice::Iter<'_, u32>) -> usize { + // CHECK: %[[START:.+]] = load ptr, ptr %it, + // CHECK-SAME: !nonnull + // CHECK-SAME: !noundef + // CHECK: %[[ENDP:.+]] = getelementptr{{.+}}ptr %it,{{.+}} 1 + // CHECK: %[[END:.+]] = load ptr, ptr %[[ENDP]] + // CHECK-SAME: !nonnull + // CHECK-SAME: !noundef + + // CHECK: ptrtoint + // CHECK: ptrtoint + // CHECK: sub nuw + // CHECK: lshr exact + it.len() +} |
