1
- // skip-filecheck
2
1
// unit-test: LowerIntrinsics
3
2
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
4
3
7
6
8
7
// EMIT_MIR lower_intrinsics.wrapping.LowerIntrinsics.diff
9
8
pub fn wrapping ( a : i32 , b : i32 ) {
9
+ // CHECK-LABEL: fn wrapping(
10
+ // CHECK: {{_.*}} = Add(
11
+ // CHECK: {{_.*}} = Sub(
12
+ // CHECK: {{_.*}} = Mul(
10
13
let _x = core:: intrinsics:: wrapping_add ( a, b) ;
11
14
let _y = core:: intrinsics:: wrapping_sub ( a, b) ;
12
15
let _z = core:: intrinsics:: wrapping_mul ( a, b) ;
13
16
}
14
17
15
18
// EMIT_MIR lower_intrinsics.unchecked.LowerIntrinsics.diff
16
19
pub unsafe fn unchecked ( a : i32 , b : i32 ) {
20
+ // CHECK-LABEL: fn unchecked(
21
+ // CHECK: {{_.*}} = AddUnchecked(
22
+ // CHECK: {{_.*}} = SubUnchecked(
23
+ // CHECK: {{_.*}} = MulUnchecked(
24
+ // CHECK: {{_.*}} = Div(
25
+ // CHECK: {{_.*}} = Rem(
26
+ // CHECK: {{_.*}} = ShlUnchecked(
27
+ // CHECK: {{_.*}} = ShrUnchecked(
17
28
let _a = core:: intrinsics:: unchecked_add ( a, b) ;
18
29
let _b = core:: intrinsics:: unchecked_sub ( a, b) ;
19
30
let _c = core:: intrinsics:: unchecked_mul ( a, b) ;
@@ -25,60 +36,95 @@ pub unsafe fn unchecked(a: i32, b: i32) {
25
36
26
37
// EMIT_MIR lower_intrinsics.size_of.LowerIntrinsics.diff
27
38
pub fn size_of < T > ( ) -> usize {
39
+ // CHECK-LABEL: fn size_of(
40
+ // CHECK: {{_.*}} = SizeOf(T);
28
41
core:: intrinsics:: size_of :: < T > ( )
29
42
}
30
43
31
44
// EMIT_MIR lower_intrinsics.align_of.LowerIntrinsics.diff
32
45
pub fn align_of < T > ( ) -> usize {
46
+ // CHECK-LABEL: fn align_of(
47
+ // CHECK: {{_.*}} = AlignOf(T);
33
48
core:: intrinsics:: min_align_of :: < T > ( )
34
49
}
35
50
36
51
// EMIT_MIR lower_intrinsics.forget.LowerIntrinsics.diff
37
52
pub fn forget < T > ( t : T ) {
53
+ // CHECK-LABEL: fn forget(
54
+ // CHECK-NOT: Drop(
55
+ // CHECK: return;
56
+ // CHECK-NOT: Drop(
38
57
core:: intrinsics:: forget ( t)
39
58
}
40
59
41
60
// EMIT_MIR lower_intrinsics.unreachable.LowerIntrinsics.diff
42
61
pub fn unreachable ( ) -> ! {
62
+ // CHECK-LABEL: fn unreachable(
63
+ // CHECK: unreachable;
43
64
unsafe { core:: intrinsics:: unreachable ( ) } ;
44
65
}
45
66
46
67
// EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff
47
68
pub fn non_const < T > ( ) -> usize {
69
+ // CHECK-LABEL: fn non_const(
70
+ // CHECK: SizeOf(T);
71
+
48
72
// Check that lowering works with non-const operand as a func.
49
73
let size_of_t = core:: intrinsics:: size_of :: < T > ;
50
74
size_of_t ( )
51
75
}
52
76
53
77
// EMIT_MIR lower_intrinsics.transmute_inhabited.LowerIntrinsics.diff
54
78
pub fn transmute_inhabited ( c : std:: cmp:: Ordering ) -> i8 {
79
+ // CHECK-LABEL: fn transmute_inhabited(
80
+ // CHECK: {{_.*}} = {{.*}} as i8 (Transmute);
81
+
55
82
unsafe { std:: mem:: transmute ( c) }
56
83
}
57
84
58
85
// EMIT_MIR lower_intrinsics.transmute_uninhabited.LowerIntrinsics.diff
59
86
pub unsafe fn transmute_uninhabited ( u : ( ) ) -> Never {
87
+ // CHECK-LABEL: fn transmute_uninhabited(
88
+ // CHECK: {{_.*}} = {{.*}} as Never (Transmute);
89
+ // CHECK: unreachable;
90
+
60
91
unsafe { std:: mem:: transmute :: < ( ) , Never > ( u) }
61
92
}
62
93
63
94
// EMIT_MIR lower_intrinsics.transmute_ref_dst.LowerIntrinsics.diff
64
95
pub unsafe fn transmute_ref_dst < T : ?Sized > ( u : & T ) -> * const T {
96
+ // CHECK-LABEL: fn transmute_ref_dst(
97
+ // CHECK: {{_.*}} = {{.*}} as *const T (Transmute);
98
+
65
99
unsafe { std:: mem:: transmute ( u) }
66
100
}
67
101
68
102
// EMIT_MIR lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.diff
69
103
pub unsafe fn transmute_to_ref_uninhabited ( ) -> ! {
104
+ // CHECK-LABEL: fn transmute_to_ref_uninhabited(
105
+ // CHECK: {{_.*}} = {{.*}} as &Never (Transmute);
106
+ // CHECK: unreachable;
107
+
70
108
let x: & Never = std:: mem:: transmute ( 1usize ) ;
71
109
match * x { }
72
110
}
73
111
74
112
// EMIT_MIR lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.diff
75
113
pub unsafe fn transmute_to_mut_uninhabited ( ) -> ! {
114
+ // CHECK-LABEL: fn transmute_to_mut_uninhabited(
115
+ // CHECK: {{_.*}} = {{.*}} as &mut Never (Transmute);
116
+ // CHECK: unreachable;
117
+
76
118
let x: & mut Never = std:: mem:: transmute ( 1usize ) ;
77
119
match * x { }
78
120
}
79
121
80
122
// EMIT_MIR lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.diff
81
123
pub unsafe fn transmute_to_box_uninhabited ( ) -> ! {
124
+ // CHECK-LABEL: fn transmute_to_box_uninhabited(
125
+ // CHECK: {{_.*}} = {{.*}} as std::boxed::Box<Never> (Transmute);
126
+ // CHECK: unreachable;
127
+
82
128
let x: Box < Never > = std:: mem:: transmute ( 1usize ) ;
83
129
match * x { }
84
130
}
@@ -91,6 +137,12 @@ pub enum E {
91
137
92
138
// EMIT_MIR lower_intrinsics.discriminant.LowerIntrinsics.diff
93
139
pub fn discriminant < T > ( t : T ) {
140
+ // CHECK-LABEL: fn discriminant(
141
+ // CHECK: {{_.*}} = discriminant(
142
+ // CHECK: {{_.*}} = discriminant(
143
+ // CHECK: {{_.*}} = discriminant(
144
+ // CHECK: {{_.*}} = discriminant(
145
+
94
146
core:: intrinsics:: discriminant_value ( & t) ;
95
147
core:: intrinsics:: discriminant_value ( & 0 ) ;
96
148
core:: intrinsics:: discriminant_value ( & ( ) ) ;
@@ -105,6 +157,9 @@ extern "rust-intrinsic" {
105
157
106
158
// EMIT_MIR lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff
107
159
pub fn f_copy_nonoverlapping ( ) {
160
+ // CHECK-LABEL: fn f_copy_nonoverlapping(
161
+ // CHECK: copy_nonoverlapping({{.*}});
162
+
108
163
let src = ( ) ;
109
164
let mut dst = ( ) ;
110
165
unsafe {
@@ -114,37 +169,65 @@ pub fn f_copy_nonoverlapping() {
114
169
115
170
// EMIT_MIR lower_intrinsics.assume.LowerIntrinsics.diff
116
171
pub fn assume ( ) {
172
+ // CHECK-LABEL: fn assume(
173
+ // CHECK: assume({{.*}});
174
+
117
175
unsafe {
118
176
std:: intrinsics:: assume ( true ) ;
119
177
}
120
178
}
121
179
122
180
// EMIT_MIR lower_intrinsics.with_overflow.LowerIntrinsics.diff
123
181
pub fn with_overflow ( a : i32 , b : i32 ) {
182
+ // CHECK-LABEL: fn with_overflow(
183
+ // CHECK: CheckedAdd(
184
+ // CHECK: CheckedSub(
185
+ // CHECK: CheckedMul(
186
+
124
187
let _x = core:: intrinsics:: add_with_overflow ( a, b) ;
125
188
let _y = core:: intrinsics:: sub_with_overflow ( a, b) ;
126
189
let _z = core:: intrinsics:: mul_with_overflow ( a, b) ;
127
190
}
128
191
129
192
// EMIT_MIR lower_intrinsics.read_via_copy_primitive.LowerIntrinsics.diff
130
193
pub fn read_via_copy_primitive ( r : & i32 ) -> i32 {
194
+ // CHECK-LABEL: fn read_via_copy_primitive(
195
+ // CHECK: [[tmp:_.*]] = &raw const (*_1);
196
+ // CHECK: _0 = (*[[tmp]]);
197
+ // CHECK: return;
198
+
131
199
unsafe { core:: intrinsics:: read_via_copy ( r) }
132
200
}
133
201
134
202
// EMIT_MIR lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.diff
135
203
pub fn read_via_copy_uninhabited ( r : & Never ) -> Never {
204
+ // CHECK-LABEL: fn read_via_copy_uninhabited(
205
+ // CHECK: [[tmp:_.*]] = &raw const (*_1);
206
+ // CHECK: _0 = (*[[tmp]]);
207
+ // CHECK: unreachable;
208
+
136
209
unsafe { core:: intrinsics:: read_via_copy ( r) }
137
210
}
138
211
139
212
// EMIT_MIR lower_intrinsics.write_via_move_string.LowerIntrinsics.diff
140
213
pub fn write_via_move_string ( r : & mut String , v : String ) {
214
+ // CHECK-LABEL: fn write_via_move_string(
215
+ // CHECK: [[ptr:_.*]] = &raw mut (*_1);
216
+ // CHECK: [[tmp:_.*]] = move _2;
217
+ // CHECK: (*[[ptr]]) = move [[tmp]];
218
+ // CHECK: return;
219
+
141
220
unsafe { core:: intrinsics:: write_via_move ( r, v) }
142
221
}
143
222
144
223
pub enum Never { }
145
224
146
225
// EMIT_MIR lower_intrinsics.option_payload.LowerIntrinsics.diff
147
226
pub fn option_payload ( o : & Option < usize > , p : & Option < String > ) {
227
+ // CHECK-LABEL: fn option_payload(
228
+ // CHECK: {{_.*}} = &raw const (((*{{_.*}}) as Some).0: usize);
229
+ // CHECK: {{_.*}} = &raw const (((*{{_.*}}) as Some).0: std::string::String);
230
+
148
231
unsafe {
149
232
let _x = core:: intrinsics:: option_payload_ptr ( o) ;
150
233
let _y = core:: intrinsics:: option_payload_ptr ( p) ;
@@ -153,5 +236,8 @@ pub fn option_payload(o: &Option<usize>, p: &Option<String>) {
153
236
154
237
// EMIT_MIR lower_intrinsics.ptr_offset.LowerIntrinsics.diff
155
238
pub unsafe fn ptr_offset ( p : * const i32 , d : isize ) -> * const i32 {
239
+ // CHECK-LABEL: fn ptr_offset(
240
+ // CHECK: _0 = Offset(
241
+
156
242
core:: intrinsics:: offset ( p, d)
157
243
}
0 commit comments