about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-09-16 00:56:12 +0000
committerbors <bors@rust-lang.org>2020-09-16 00:56:12 +0000
commitf4e4485a052857e5dd32ea29ceb7b1a8223e83cc (patch)
tree187b836dc0d60f2fe5cecd273a99ca0ba306a073 /src/test/codegen
parent9f04c9065764e56c91cbe567f78d2b207f546ba7 (diff)
parent2e1f0121e8bf138789fd41ae13ede9450cf373f3 (diff)
downloadrust-f4e4485a052857e5dd32ea29ceb7b1a8223e83cc.tar.gz
rust-f4e4485a052857e5dd32ea29ceb7b1a8223e83cc.zip
Auto merge of #76771 - Dylan-DPC:rollup-qj4j3ma, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #73955 (deny(unsafe_op_in_unsafe_fn) in libstd/process.rs)
 - #75146 (Detect overflow in proc_macro_server subspan)
 - #75304 (Note when a a move/borrow error is caused by a deref coercion)
 - #75749 (Consolidate some duplicate code in the sys modules.)
 - #75882 (Use translated variable for test string)
 - #75886 (Test that bounds checks are elided for [..index] after .position())
 - #76048 (Initial support for riscv32gc_unknown_linux_gnu)
 - #76198 (Make some Ordering methods const)
 - #76689 (Upgrade to pulldown-cmark 0.8.0)
 - #76763 (Update cargo)

Failed merges:

r? `@ghost`
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/issue-73396-bounds-check-after-position.rs78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/test/codegen/issue-73396-bounds-check-after-position.rs b/src/test/codegen/issue-73396-bounds-check-after-position.rs
new file mode 100644
index 00000000000..e5f3ae45c07
--- /dev/null
+++ b/src/test/codegen/issue-73396-bounds-check-after-position.rs
@@ -0,0 +1,78 @@
+// min-llvm-version: 11.0.0
+// compile-flags: -O
+// ignore-debug: the debug assertions get in the way
+#![crate_type = "lib"]
+
+// Make sure no bounds checks are emitted when slicing or indexing
+// with an index from `position()` or `rposition()`.
+
+// CHECK-LABEL: @position_slice_to_no_bounds_check
+#[no_mangle]
+pub fn position_slice_to_no_bounds_check(s: &[u8]) -> &[u8] {
+    // CHECK-NOT: panic
+    // CHECK-NOT: slice_index_len_fail
+    if let Some(idx) = s.iter().position(|b| *b == b'\\') {
+        &s[..idx]
+    } else {
+        s
+    }
+}
+
+// CHECK-LABEL: @position_slice_from_no_bounds_check
+#[no_mangle]
+pub fn position_slice_from_no_bounds_check(s: &[u8]) -> &[u8] {
+    // CHECK-NOT: panic
+    // CHECK-NOT: slice_index_len_fail
+    if let Some(idx) = s.iter().position(|b| *b == b'\\') {
+        &s[idx..]
+    } else {
+        s
+    }
+}
+
+// CHECK-LABEL: @position_index_no_bounds_check
+#[no_mangle]
+pub fn position_index_no_bounds_check(s: &[u8]) -> u8 {
+    // CHECK-NOT: panic
+    // CHECK-NOT: slice_index_len_fail
+    if let Some(idx) = s.iter().position(|b| *b == b'\\') {
+        s[idx]
+    } else {
+        42
+    }
+}
+// CHECK-LABEL: @rposition_slice_to_no_bounds_check
+#[no_mangle]
+pub fn rposition_slice_to_no_bounds_check(s: &[u8]) -> &[u8] {
+    // CHECK-NOT: panic
+    // CHECK-NOT: slice_index_len_fail
+    if let Some(idx) = s.iter().rposition(|b| *b == b'\\') {
+        &s[..idx]
+    } else {
+        s
+    }
+}
+
+// CHECK-LABEL: @rposition_slice_from_no_bounds_check
+#[no_mangle]
+pub fn rposition_slice_from_no_bounds_check(s: &[u8]) -> &[u8] {
+    // CHECK-NOT: panic
+    // CHECK-NOT: slice_index_len_fail
+    if let Some(idx) = s.iter().rposition(|b| *b == b'\\') {
+        &s[idx..]
+    } else {
+        s
+    }
+}
+
+// CHECK-LABEL: @rposition_index_no_bounds_check
+#[no_mangle]
+pub fn rposition_index_no_bounds_check(s: &[u8]) -> u8 {
+    // CHECK-NOT: panic
+    // CHECK-NOT: slice_index_len_fail
+    if let Some(idx) = s.iter().rposition(|b| *b == b'\\') {
+        s[idx]
+    } else {
+        42
+    }
+}