about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2025-07-09 23:59:00 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2025-07-19 20:50:02 -0700
commit0586c63e070981af7df53e2f778d3e50293d8103 (patch)
treebd736dbc3d0e455d16f3df79d752c547faf4355b /tests
parentf63685ddf3d3c92a61158cd55d44bde17c2b024f (diff)
downloadrust-0586c63e070981af7df53e2f778d3e50293d8103.tar.gz
rust-0586c63e070981af7df53e2f778d3e50293d8103.zip
Allow `Rvalue::Repeat` to return true in `rvalue_creates_operand` too
The conversation in 143502 made be realize how easy this is to handle, since the only possibilty is ZSTs -- everything else ends up with the destination being `LocalKind::Memory` and thus doesn't call `codegen_rvalue_operand` at all.

This gets us perilously close to a world where `rvalue_creates_operand` only ever returns true.  I'll try out such a world next :)

Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/repeat-operand.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/codegen/repeat-operand.rs b/tests/codegen/repeat-operand.rs
new file mode 100644
index 00000000000..6464b35ddca
--- /dev/null
+++ b/tests/codegen/repeat-operand.rs
@@ -0,0 +1,39 @@
+//@ compile-flags: -Copt-level=1 -Cno-prepopulate-passes
+
+// This test is here to hit the `Rvalue::Repeat` case in `codegen_rvalue_operand`.
+// It only applies when the resulting array is a ZST, so the test is written in
+// such a way as to keep MIR optimizations from seeing that fact and removing
+// the local and statement altogether. (At the time of writing, no other codegen
+// test hit that code path, nor did a stage 2 build of the compiler.)
+
+#![crate_type = "lib"]
+
+#[repr(transparent)]
+pub struct Wrapper<T, const N: usize>([T; N]);
+
+// CHECK-LABEL: define {{.+}}do_repeat{{.+}}()
+// CHECK-NEXT: start:
+// CHECK-NOT: alloca
+// CHECK-NEXT: ret void
+// CHECK-LABEL: define {{.+}}do_repeat{{.+}}(i32 noundef %x)
+// CHECK-NEXT: start:
+// CHECK-NOT: alloca
+// CHECK-NEXT: ret void
+#[inline(never)]
+pub fn do_repeat<T: Copy, const N: usize>(x: T) -> Wrapper<T, N> {
+    Wrapper([x; N])
+}
+
+// CHECK-LABEL: @trigger_repeat_zero_len
+#[no_mangle]
+pub fn trigger_repeat_zero_len() -> Wrapper<u32, 0> {
+    // CHECK: call void {{.+}}do_repeat{{.+}}(i32 noundef 4)
+    do_repeat(4)
+}
+
+// CHECK-LABEL: @trigger_repeat_zst
+#[no_mangle]
+pub fn trigger_repeat_zst() -> Wrapper<(), 8> {
+    // CHECK: call void {{.+}}do_repeat{{.+}}()
+    do_repeat(())
+}