about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2024-08-19 19:04:43 -0400
committerBen Kimock <kimockb@gmail.com>2024-09-21 01:06:59 -0400
commit0ea5dc506f50cf8e2732c715878ecf09ea0db480 (patch)
treefbd70826c455558345b87f836adff155fae93cc9 /tests
parent5ba6db1b648d93fbbab4ae0466e40db682fa45fc (diff)
downloadrust-0ea5dc506f50cf8e2732c715878ecf09ea0db480.tar.gz
rust-0ea5dc506f50cf8e2732c715878ecf09ea0db480.zip
Don't alloca for unused locals
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/constant-branch.rs4
-rw-r--r--tests/codegen/no-alloca-inside-if-false.rs23
2 files changed, 24 insertions, 3 deletions
diff --git a/tests/codegen/constant-branch.rs b/tests/codegen/constant-branch.rs
index a2710cc4b25..8f8438b0b1a 100644
--- a/tests/codegen/constant-branch.rs
+++ b/tests/codegen/constant-branch.rs
@@ -41,10 +41,8 @@ pub fn if_constant_match() {
         _ => 4,
     };
 
-    // CHECK: br label %[[MINUS1:.+]]
+    // CHECK: br label %{{.+}}
     _ = match -1 {
-        // CHECK: [[MINUS1]]:
-        // CHECK: store i32 1
         -1 => 1,
         _ => 0,
     }
diff --git a/tests/codegen/no-alloca-inside-if-false.rs b/tests/codegen/no-alloca-inside-if-false.rs
new file mode 100644
index 00000000000..1bfbf71da4d
--- /dev/null
+++ b/tests/codegen/no-alloca-inside-if-false.rs
@@ -0,0 +1,23 @@
+//@ compile-flags: -Cno-prepopulate-passes -Copt-level=0
+
+#![crate_type = "lib"]
+
+#[inline(never)]
+fn test<const SIZE: usize>() {
+    // CHECK-LABEL: no_alloca_inside_if_false::test
+    // CHECK: start:
+    // CHECK-NEXT: %0 = alloca
+    // CHECK-NEXT: %vec = alloca
+    // CHECK-NOT: %arr = alloca
+    if const { SIZE < 4096 } {
+        let arr = [0u8; SIZE];
+        std::hint::black_box(&arr);
+    } else {
+        let vec = vec![0u8; SIZE];
+        std::hint::black_box(&vec);
+    }
+}
+
+pub fn main() {
+    test::<8192>();
+}