Skip to content

Commit 5145c97

Browse files
committed
Add LLVM15-specific codegen test for try/?s that now optimize away
These still generated a bunch of code back in Rust 1.63 (<https://rust.godbolt.org/z/z31P8h6rz>), but with LLVM 15 merged they no longer do 🎉
1 parent 76c427d commit 5145c97

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// min-llvm-version: 15.0
2+
// compile-flags: -O -Z merge-functions=disabled --edition=2021
3+
// only-x86_64
4+
5+
#![crate_type = "lib"]
6+
#![feature(try_blocks)]
7+
8+
// These are now NOPs in LLVM 15, presumably thanks to nikic's change mentioned in
9+
// <https://github.com/rust-lang/rust/issues/85133#issuecomment-1072168354>.
10+
// Unfortunately, as of 2022-08-17 they're not yet nops for `u64`s nor `Option`.
11+
12+
use std::ops::ControlFlow::{self, Continue, Break};
13+
14+
// CHECK-LABEL: @result_nop_match_32
15+
#[no_mangle]
16+
pub fn result_nop_match_32(x: Result<i32, u32>) -> Result<i32, u32> {
17+
// CHECK: start
18+
// CHECK-NEXT: ret i64 %0
19+
match x {
20+
Ok(x) => Ok(x),
21+
Err(x) => Err(x),
22+
}
23+
}
24+
25+
// CHECK-LABEL: @result_nop_traits_32
26+
#[no_mangle]
27+
pub fn result_nop_traits_32(x: Result<i32, u32>) -> Result<i32, u32> {
28+
// CHECK: start
29+
// CHECK-NEXT: ret i64 %0
30+
try {
31+
x?
32+
}
33+
}
34+
35+
// CHECK-LABEL: @control_flow_nop_match_32
36+
#[no_mangle]
37+
pub fn control_flow_nop_match_32(x: ControlFlow<i32, u32>) -> ControlFlow<i32, u32> {
38+
// CHECK: start
39+
// CHECK-NEXT: ret i64 %0
40+
match x {
41+
Continue(x) => Continue(x),
42+
Break(x) => Break(x),
43+
}
44+
}
45+
46+
// CHECK-LABEL: @control_flow_nop_traits_32
47+
#[no_mangle]
48+
pub fn control_flow_nop_traits_32(x: ControlFlow<i32, u32>) -> ControlFlow<i32, u32> {
49+
// CHECK: start
50+
// CHECK-NEXT: ret i64 %0
51+
try {
52+
x?
53+
}
54+
}

0 commit comments

Comments
 (0)