Skip to content

Commit 1612a70

Browse files
committed
test: added codegen tests for permutations of Option::or
1 parent 6e48b44 commit 1612a70

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Tests output of multiple permutations of `Option::or`
2+
//@ compile-flags: -Copt-level=3 -Zmerge-functions=disabled
3+
4+
#![crate_type = "lib"]
5+
6+
// CHECK-LABEL: @or_match_u8
7+
#[no_mangle]
8+
pub fn or_match_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> {
9+
// CHECK: start:
10+
// CHECK-NEXT: or i1 %0
11+
// CHECK-NEXT: select i1 %0
12+
// CHECK-NEXT: insertvalue { i1, i8 }
13+
// CHECK-NEXT: insertvalue { i1, i8 }
14+
// ret { i1, i8 }
15+
match opta {
16+
Some(x) => Some(x),
17+
None => optb,
18+
}
19+
}
20+
21+
// CHECK-LABEL: @or_match_alt_u8
22+
#[no_mangle]
23+
pub fn or_match_alt_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> {
24+
// CHECK: start:
25+
// CHECK-NEXT: select i1
26+
// CHECK-NEXT: or i1
27+
// CHECK-NEXT: insertvalue { i1, i8 }
28+
// CHECK-NEXT: insertvalue { i1, i8 }
29+
// ret { i1, i8 }
30+
match opta {
31+
Some(_) => opta,
32+
None => optb,
33+
}
34+
}
35+
36+
// CHECK-LABEL: @option_or_u8
37+
#[no_mangle]
38+
pub fn option_or_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> {
39+
// CHECK: start:
40+
// CHECK-NEXT: select i1
41+
// CHECK-NEXT: or i1
42+
// CHECK-NEXT: insertvalue { i1, i8 }
43+
// CHECK-NEXT: insertvalue { i1, i8 }
44+
// ret { i1, i8 }
45+
opta.or(optb)
46+
}
47+
48+
// CHECK-LABEL: @if_some_u8
49+
#[no_mangle]
50+
pub fn if_some_u8(opta: Option<u8>, optb: Option<u8>) -> Option<u8> {
51+
// CHECK: start:
52+
// CHECK-NEXT: select i1
53+
// CHECK-NEXT: or i1
54+
// CHECK-NEXT: insertvalue { i1, i8 }
55+
// CHECK-NEXT: insertvalue { i1, i8 }
56+
// ret { i1, i8 }
57+
if opta.is_some() { opta } else { optb }
58+
}
59+
60+
// CHECK-LABEL: @or_match_slice_u8
61+
#[no_mangle]
62+
pub fn or_match_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> {
63+
// CHECK: start:
64+
// CHECK-NEXT: trunc i16 %0 to i1
65+
// CHECK-NEXT: select i1 %2, i16 %0, i16 %1
66+
// ret i16
67+
match opta {
68+
Some(x) => Some(x),
69+
None => optb,
70+
}
71+
}
72+
73+
// CHECK-LABEL: @or_match_slice_alt_u8
74+
#[no_mangle]
75+
pub fn or_match_slice_alt_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> {
76+
// CHECK: start:
77+
// CHECK-NEXT: trunc i16 %0 to i1
78+
// CHECK-NEXT: select i1 %2, i16 %0, i16 %1
79+
// ret i16
80+
match opta {
81+
Some(_) => opta,
82+
None => optb,
83+
}
84+
}
85+
86+
// CHECK-LABEL: @option_or_slice_u8
87+
#[no_mangle]
88+
pub fn option_or_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> {
89+
// CHECK: start:
90+
// CHECK-NEXT: trunc i16 %0 to i1
91+
// CHECK-NEXT: select i1 %2, i16 %0, i16 %1
92+
// ret i16
93+
opta.or(optb)
94+
}
95+
96+
// CHECK-LABEL: @if_some_slice_u8
97+
#[no_mangle]
98+
pub fn if_some_slice_u8(opta: Option<[u8; 1]>, optb: Option<[u8; 1]>) -> Option<[u8; 1]> {
99+
// CHECK: start:
100+
// CHECK-NEXT: trunc i16 %0 to i1
101+
// CHECK-NEXT: select i1 %2, i16 %0, i16 %1
102+
// ret i16
103+
if opta.is_some() { opta } else { optb }
104+
}
105+
106+
pub struct Test {
107+
_a: u8,
108+
_b: u8,
109+
}
110+
111+
// CHECK-LABEL: @or_match_type
112+
#[no_mangle]
113+
pub fn or_match_type(opta: Option<Test>, optb: Option<Test>) -> Option<Test> {
114+
// CHECK: start:
115+
// CHECK-NEXT: trunc i24 %0 to i1
116+
// CHECK-NEXT: select i1 %2, i24 %0, i24 %1
117+
// ret i24
118+
match opta {
119+
Some(x) => Some(x),
120+
None => optb,
121+
}
122+
}
123+
124+
// CHECK-LABEL: @or_match_alt_type
125+
#[no_mangle]
126+
pub fn or_match_alt_type(opta: Option<Test>, optb: Option<Test>) -> Option<Test> {
127+
// CHECK: start:
128+
// CHECK-NEXT: trunc i24 %0 to i1
129+
// CHECK-NEXT: select i1 %2, i24 %0, i24 %1
130+
// ret i24
131+
match opta {
132+
Some(_) => opta,
133+
None => optb,
134+
}
135+
}
136+
137+
// CHECK-LABEL: @option_or_type
138+
#[no_mangle]
139+
pub fn option_or_type(opta: Option<Test>, optb: Option<Test>) -> Option<Test> {
140+
// CHECK: start:
141+
// CHECK-NEXT: trunc i24 %0 to i1
142+
// CHECK-NEXT: select i1 %2, i24 %0, i24 %1
143+
// ret i24
144+
opta.or(optb)
145+
}
146+
147+
// CHECK-LABEL: @if_some_type
148+
#[no_mangle]
149+
pub fn if_some_type(opta: Option<Test>, optb: Option<Test>) -> Option<Test> {
150+
// CHECK: start:
151+
// CHECK-NEXT: trunc i24 %0 to i1
152+
// CHECK-NEXT: select i1 %2, i24 %0, i24 %1
153+
// ret i24
154+
if opta.is_some() { opta } else { optb }
155+
}

0 commit comments

Comments
 (0)