diff options
| author | bors <bors@rust-lang.org> | 2025-07-20 13:52:48 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-07-20 13:52:48 +0000 |
| commit | 0864097cd31ee30f5081ba588a5c9820c2c6fc71 (patch) | |
| tree | e489f2917609ef4da2679ed89a08a91a4c1c5a9a /tests/codegen | |
| parent | ca9eecda36795789511e6e19500cb13b5a053fec (diff) | |
| parent | ae3708e4b20036b1bccc7e0ecb344e0ef9ce442b (diff) | |
| download | rust-0864097cd31ee30f5081ba588a5c9820c2c6fc71.tar.gz rust-0864097cd31ee30f5081ba588a5c9820c2c6fc71.zip | |
Auto merge of #144219 - GuillaumeGomez:rollup-ha29sql, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - rust-lang/rust#143282 (Add `uX::strict_sub_signed`) - rust-lang/rust#143423 (address clippy formatting nits) - rust-lang/rust#143720 (Allow `Rvalue::Repeat` to return true in `rvalue_creates_operand` too) - rust-lang/rust#144011 (bootstrap: Don't trigger an unnecessary LLVM build from check builds) - rust-lang/rust#144112 (bootstrap: Ignore `rust.debuginfo-level-tests` for codegen tests) - rust-lang/rust#144125 (Add new `ignore-backends` and `needs-backends` tests annotations) - rust-lang/rust#144143 (Fix `-Ctarget-feature`s getting ignored after `crt-static`) - rust-lang/rust#144150 (tests: assembly: cstring-merging: Disable GlobalMerge pass) - rust-lang/rust#144190 (Give a message with a span on MIR validation error) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/repeat-operand-zero-len.rs | 28 | ||||
| -rw-r--r-- | tests/codegen/repeat-operand-zst-elem.rs | 28 |
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/codegen/repeat-operand-zero-len.rs b/tests/codegen/repeat-operand-zero-len.rs new file mode 100644 index 00000000000..b4cec42a07c --- /dev/null +++ b/tests/codegen/repeat-operand-zero-len.rs @@ -0,0 +1,28 @@ +//@ 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{{.+}}(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) +} diff --git a/tests/codegen/repeat-operand-zst-elem.rs b/tests/codegen/repeat-operand-zst-elem.rs new file mode 100644 index 00000000000..c3637759afa --- /dev/null +++ b/tests/codegen/repeat-operand-zst-elem.rs @@ -0,0 +1,28 @@ +//@ 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 +#[inline(never)] +pub fn do_repeat<T: Copy, const N: usize>(x: T) -> Wrapper<T, N> { + Wrapper([x; N]) +} + +// CHECK-LABEL: @trigger_repeat_zst_elem +#[no_mangle] +pub fn trigger_repeat_zst_elem() -> Wrapper<(), 8> { + // CHECK: call void {{.+}}do_repeat{{.+}}() + do_repeat(()) +} |
