about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-06-19 08:34:50 +0000
committerbors <bors@rust-lang.org>2020-06-19 08:34:50 +0000
commit63b441aafbf52d6ba789ecc478455800c1a48df9 (patch)
tree522aba5368c067b64995b45a91f3e4e5587bfe3a /src/test/codegen
parenta39c7787ba246353178e099373b9240be0d9e603 (diff)
parent028c908991125742c4acc38b7a3108a1d1133771 (diff)
downloadrust-63b441aafbf52d6ba789ecc478455800c1a48df9.tar.gz
rust-63b441aafbf52d6ba789ecc478455800c1a48df9.zip
Auto merge of #73498 - RalfJung:rollup-1mfjcju, r=RalfJung
Rollup of 13 pull requests

Successful merges:

 - #70740 (Enabling static-pie for musl)
 - #72331 (Report error when casting an C-like enum implementing Drop)
 - #72486 (Fix asinh of negative values)
 - #72497 (tag/niche terminology cleanup)
 - #72999 (Create self-contained directory and move there some of external binaries/libs)
 - #73130 (Remove const prop for indirects)
 - #73142 (Ensure std benchmarks get tested.)
 - #73305 (Disallow loading crates with non-ascii identifier name.)
 - #73346 (Add rust specific features to print target features)
 - #73362 (Test that bounds checks are elided when slice len is checked up-front)
 - #73459 (Reduce pointer casts in Box::into_boxed_slice)
 - #73464 (Document format correction)
 - #73479 (Minor tweaks to liballoc)

Failed merges:

r? @ghost
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/issue-69101-bounds-check.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/codegen/issue-69101-bounds-check.rs b/src/test/codegen/issue-69101-bounds-check.rs
new file mode 100644
index 00000000000..8ade583b571
--- /dev/null
+++ b/src/test/codegen/issue-69101-bounds-check.rs
@@ -0,0 +1,44 @@
+// no-system-llvm
+// compile-flags: -O
+// ignore-debug: the debug assertions get in the way
+#![crate_type = "lib"]
+
+// Make sure no bounds checks are emitted in the loop when upfront slicing
+// ensures that the slices are big enough.
+// In particular, bounds checks were not always optimized out if the upfront
+// check was for a greater len than the loop requires.
+// (i.e. `already_sliced_no_bounds_check` was not always optimized even when
+// `already_sliced_no_bounds_check_exact` was)
+// CHECK-LABEL: @already_sliced_no_bounds_check
+#[no_mangle]
+pub fn already_sliced_no_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
+    // CHECK: slice_index_len_fail
+    // CHECK-NOT: panic_bounds_check
+    let _ = (&a[..2048], &b[..2048], &mut c[..2048]);
+    for i in 0..1024 {
+        c[i] = a[i] ^ b[i];
+    }
+}
+
+// CHECK-LABEL: @already_sliced_no_bounds_check_exact
+#[no_mangle]
+pub fn already_sliced_no_bounds_check_exact(a: &[u8], b: &[u8], c: &mut [u8]) {
+    // CHECK: slice_index_len_fail
+    // CHECK-NOT: panic_bounds_check
+    let _ = (&a[..1024], &b[..1024], &mut c[..1024]);
+    for i in 0..1024 {
+        c[i] = a[i] ^ b[i];
+    }
+}
+
+// Make sure we're checking for the right thing: there can be a panic if the slice is too small.
+// CHECK-LABEL: @already_sliced_bounds_check
+#[no_mangle]
+pub fn already_sliced_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
+    // CHECK: slice_index_len_fail
+    // CHECK: panic_bounds_check
+    let _ = (&a[..1023], &b[..2048], &mut c[..2048]);
+    for i in 0..1024 {
+        c[i] = a[i] ^ b[i];
+    }
+}