Skip to content

Commit 4016510

Browse files
test merging of multiple match branches that access fields of the same offset
1 parent c1017d4 commit 4016510

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//! This test checks that match branches which all access a field
2+
//! at the same offset are merged together.
3+
//!
4+
//@ compile-flags: -O
5+
#![crate_type = "lib"]
6+
7+
#[repr(C)]
8+
pub struct A {
9+
x: f64,
10+
y: u64,
11+
}
12+
#[repr(C)]
13+
pub struct B {
14+
x: f64,
15+
y: u32,
16+
}
17+
#[repr(C)]
18+
pub struct C {
19+
x: f64,
20+
y: u16,
21+
}
22+
#[repr(C)]
23+
pub struct D {
24+
x: f64,
25+
y: u8,
26+
}
27+
28+
pub enum E {
29+
A(A),
30+
B(B),
31+
C(C),
32+
D(D),
33+
}
34+
35+
// CHECK-LABEL: @match_on_e
36+
#[no_mangle]
37+
pub fn match_on_e(e: &E) -> &f64 {
38+
// CHECK: start:
39+
// CHECK-NEXT: getelementptr
40+
// CHECK-NEXT: ret
41+
match e {
42+
E::A(A { x, .. }) | E::B(B { x, .. }) | E::C(C { x, .. }) | E::D(D { x, .. }) => x,
43+
}
44+
}

0 commit comments

Comments
 (0)