about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-12-29 23:16:13 +0000
committerbors <bors@rust-lang.org>2024-12-29 23:16:13 +0000
commit6cd33d889d0cd554e195d0eb9a38af88152b786f (patch)
tree6a6dd2bc5ea2f3d518fcc133cac873f6ef203ec3 /tests/codegen
parent14ee63a3c651bb7a243c8b07333749ab4b152e13 (diff)
parente178795dbae6bd0e11b24db250fb5dfb8b0211b0 (diff)
downloadrust-6cd33d889d0cd554e195d0eb9a38af88152b786f.tar.gz
rust-6cd33d889d0cd554e195d0eb9a38af88152b786f.zip
Auto merge of #134901 - matthiaskrgr:rollup-b0wwuht, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #134870 (Fix sentence fragment in `pin` module docs)
 - #134884 (Fix typos)
 - #134892 (Added codegen test for elidings bounds check when indexes are manually checked)
 - #134894 (Document how to run the split Docker pipelines)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/slice-indexing.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/codegen/slice-indexing.rs b/tests/codegen/slice-indexing.rs
index 3d284148db2..75112bb0c24 100644
--- a/tests/codegen/slice-indexing.rs
+++ b/tests/codegen/slice-indexing.rs
@@ -60,3 +60,40 @@ pub unsafe fn str_get_unchecked_mut_by_range(x: &mut str, r: Range<usize>) -> &m
     // CHECK: sub nuw i64
     x.get_unchecked_mut(r)
 }
+
+// CHECK-LABEL: @slice_repeated_indexing(
+#[no_mangle]
+pub fn slice_repeated_indexing(dst: &mut [u8], offset: usize) {
+    let mut i = offset;
+    // CHECK: panic_bounds_check
+    dst[i] = 1;
+    i += 1;
+    // CHECK: panic_bounds_check
+    dst[i] = 2;
+    i += 1;
+    // CHECK: panic_bounds_check
+    dst[i] = 3;
+    i += 1;
+    // CHECK: panic_bounds_check
+    dst[i] = 4;
+}
+
+// CHECK-LABEL: @slice_repeated_indexing_coalesced(
+#[no_mangle]
+pub fn slice_repeated_indexing_coalesced(dst: &mut [u8], offset: usize) {
+    let mut i = offset;
+    if i.checked_add(4).unwrap() <= dst.len() {
+        // CHECK-NOT: panic_bounds_check
+        dst[i] = 1;
+        i += 1;
+        // CHECK-NOT: panic_bounds_check
+        dst[i] = 2;
+        i += 1;
+        // CHECK-NOT: panic_bounds_check
+        dst[i] = 3;
+        i += 1;
+        // CHECK-NOT: panic_bounds_check
+        dst[i] = 4;
+    }
+    // CHECK: ret
+}