diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-07-22 23:23:02 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-07-23 00:09:36 -0700 |
| commit | 6a5c7e04156125cb8c1ff78eae95e6ff076f51ed (patch) | |
| tree | ce77625e4246f41e9638e536e7cc87931529e1f1 /tests/codegen-llvm/enum/enum-transparent-extract.rs | |
| parent | a7a1618e6c835f1f00940ad72203d05808209a0d (diff) | |
| download | rust-6a5c7e04156125cb8c1ff78eae95e6ff076f51ed.tar.gz rust-6a5c7e04156125cb8c1ff78eae95e6ff076f51ed.zip | |
No longer need `alloca`s for consuming `Result<!, i32>` and similar
In optimized builds GVN gets rid of these already, but in `opt-level=0` we actually make `alloca`s for this, which particularly impacts `?`-style things that use actually-only-one-variant types like this.
Diffstat (limited to 'tests/codegen-llvm/enum/enum-transparent-extract.rs')
| -rw-r--r-- | tests/codegen-llvm/enum/enum-transparent-extract.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/codegen-llvm/enum/enum-transparent-extract.rs b/tests/codegen-llvm/enum/enum-transparent-extract.rs new file mode 100644 index 00000000000..c5efb8d472b --- /dev/null +++ b/tests/codegen-llvm/enum/enum-transparent-extract.rs @@ -0,0 +1,31 @@ +//@ compile-flags: -Copt-level=0 +//@ only-64bit + +#![crate_type = "lib"] + +use std::ops::ControlFlow; + +pub enum Never {} + +#[no_mangle] +pub fn make_unmake_result_never(x: i32) -> i32 { + // CHECK-LABEL: define i32 @make_unmake_result_never(i32 %x) + // CHECK: start: + // CHECK-NEXT: ret i32 %x + + let y: Result<i32, Never> = Ok(x); + let Ok(z) = y; + z +} + +#[no_mangle] +pub fn extract_control_flow_never(x: ControlFlow<&str, Never>) -> &str { + // CHECK-LABEL: define { ptr, i64 } @extract_control_flow_never(ptr align 1 %x.0, i64 %x.1) + // CHECK: start: + // CHECK-NEXT: %[[P0:.+]] = insertvalue { ptr, i64 } poison, ptr %x.0, 0 + // CHECK-NEXT: %[[P1:.+]] = insertvalue { ptr, i64 } %[[P0]], i64 %x.1, 1 + // CHECK-NEXT: ret { ptr, i64 } %[[P1]] + + let ControlFlow::Break(s) = x; + s +} |
