about summary refs log tree commit diff
path: root/tests/ui/loops
diff options
context:
space:
mode:
authorCaio <c410.f3r@gmail.com>2023-08-28 17:47:37 -0300
committerCaio <c410.f3r@gmail.com>2023-08-28 17:47:37 -0300
commit5a69151d7d86042efaefcc8f58486267b95f7a06 (patch)
treeaeb72407d3148884bc0cb807ac3af9a4c61f7946 /tests/ui/loops
parent93dd62024113acb782812189d01e8e239da150e7 (diff)
downloadrust-5a69151d7d86042efaefcc8f58486267b95f7a06.tar.gz
rust-5a69151d7d86042efaefcc8f58486267b95f7a06.zip
Move tests
Diffstat (limited to 'tests/ui/loops')
-rw-r--r--tests/ui/loops/issue-69225-SCEVAddExpr-wrap-flag.rs33
-rw-r--r--tests/ui/loops/issue-69225-layout-repeated-checked-add.rs31
2 files changed, 64 insertions, 0 deletions
diff --git a/tests/ui/loops/issue-69225-SCEVAddExpr-wrap-flag.rs b/tests/ui/loops/issue-69225-SCEVAddExpr-wrap-flag.rs
new file mode 100644
index 00000000000..6e030f1cc48
--- /dev/null
+++ b/tests/ui/loops/issue-69225-SCEVAddExpr-wrap-flag.rs
@@ -0,0 +1,33 @@
+// run-fail
+// compile-flags: -C opt-level=3
+// error-pattern: index out of bounds: the len is 0 but the index is 16777216
+// ignore-wasm no panic or subprocess support
+// ignore-emscripten no panic or subprocess support
+
+fn do_test(x: usize) {
+    let mut arr = vec![vec![0u8; 3]];
+
+    let mut z = vec![0];
+    for arr_ref in arr.iter_mut() {
+        for y in 0..x {
+            for _ in 0..1 {
+                z.reserve_exact(x);
+                let iterator = std::iter::repeat(0).take(x);
+                let mut cnt = 0;
+                iterator.for_each(|_| {
+                    z[0] = 0;
+                    cnt += 1;
+                });
+                let a = y * x;
+                let b = (y + 1) * x - 1;
+                let slice = &mut arr_ref[a..b];
+                slice[1 << 24] += 1;
+            }
+        }
+    }
+}
+
+fn main() {
+    do_test(1);
+    do_test(2);
+}
diff --git a/tests/ui/loops/issue-69225-layout-repeated-checked-add.rs b/tests/ui/loops/issue-69225-layout-repeated-checked-add.rs
new file mode 100644
index 00000000000..7f43e4d1a51
--- /dev/null
+++ b/tests/ui/loops/issue-69225-layout-repeated-checked-add.rs
@@ -0,0 +1,31 @@
+// Ensure we appropriately error instead of overflowing a calculation when creating a new Alloc
+// Layout
+
+// run-fail
+// compile-flags: -C opt-level=3
+// error-pattern: index out of bounds: the len is 0 but the index is 16777216
+// ignore-wasm no panic or subprocess support
+// ignore-emscripten no panic or subprocess support
+
+fn do_test(x: usize) {
+    let arr = vec![vec![0u8; 3]];
+
+    let mut z = Vec::new();
+    for arr_ref in arr {
+        for y in 0..x {
+            for _ in 0..1 {
+                z.extend(std::iter::repeat(0).take(x));
+                let a = y * x;
+                let b = (y + 1) * x - 1;
+                let slice = &arr_ref[a..b];
+                eprintln!("{} {} {} {}", a, b, arr_ref.len(), slice.len());
+                eprintln!("{:?}", slice[1 << 24]);
+            }
+        }
+    }
+}
+
+fn main() {
+    do_test(1);
+    do_test(2);
+}