Skip to content

Commit a5035c9

Browse files
authored
Rollup merge of rust-lang#82874 - erikdesjardins:cgtests, r=nagisa
Add codegen tests for some issues closed by LLVM 12 Namely rust-lang#73031, rust-lang#75546, and rust-lang#77812
2 parents a55b192 + 9386370 commit a5035c9

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

src/test/codegen/issue-73031.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// min-llvm-version: 12.0.0
2+
// compile-flags: -O
3+
#![crate_type = "lib"]
4+
5+
// Test that LLVM can eliminate the unreachable `All::None` branch.
6+
7+
pub enum All {
8+
None,
9+
Foo,
10+
Bar,
11+
}
12+
13+
// CHECK-LABEL: @issue_73031
14+
#[no_mangle]
15+
pub fn issue_73031(a: &mut All, q: i32) -> i32 {
16+
*a = if q == 5 {
17+
All::Foo
18+
} else {
19+
All::Bar
20+
};
21+
match *a {
22+
// CHECK-NOT: panic
23+
All::None => panic!(),
24+
All::Foo => 1,
25+
All::Bar => 2,
26+
}
27+
}

src/test/codegen/issue-75546.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// min-llvm-version: 12.0.0
2+
// compile-flags: -O
3+
#![crate_type = "lib"]
4+
5+
// Test that LLVM can eliminate the impossible `i == 0` check.
6+
7+
// CHECK-LABEL: @issue_75546
8+
#[no_mangle]
9+
pub fn issue_75546() {
10+
let mut i = 1u32;
11+
while i < u32::MAX {
12+
// CHECK-NOT: panic
13+
if i == 0 { panic!(); }
14+
i += 1;
15+
}
16+
}

src/test/codegen/issue-77812.rs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// min-llvm-version: 12.0.0
2+
// compile-flags: -O
3+
#![crate_type = "lib"]
4+
5+
// Test that LLVM can eliminate the unreachable `Variant::Zero` branch.
6+
7+
#[derive(Copy, Clone, Eq, PartialEq)]
8+
pub enum Variant {
9+
Zero,
10+
One,
11+
Two,
12+
}
13+
14+
extern {
15+
fn exf1();
16+
fn exf2();
17+
}
18+
19+
pub static mut GLOBAL: Variant = Variant::Zero;
20+
21+
// CHECK-LABEL: @issue_77812
22+
#[no_mangle]
23+
pub unsafe fn issue_77812() {
24+
let g = GLOBAL;
25+
if g != Variant::Zero {
26+
match g {
27+
Variant::One => exf1(),
28+
Variant::Two => exf2(),
29+
// CHECK-NOT: panic
30+
Variant::Zero => panic!(),
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)