1- // skip-filecheck
21// unit-test: LowerIntrinsics
32// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
43
76
87// EMIT_MIR lower_intrinsics.wrapping.LowerIntrinsics.diff
98pub fn wrapping ( a : i32 , b : i32 ) {
9+ // CHECK-LABEL: fn wrapping(
10+ // CHECK: {{_.*}} = Add(
11+ // CHECK: {{_.*}} = Sub(
12+ // CHECK: {{_.*}} = Mul(
1013 let _x = core:: intrinsics:: wrapping_add ( a, b) ;
1114 let _y = core:: intrinsics:: wrapping_sub ( a, b) ;
1215 let _z = core:: intrinsics:: wrapping_mul ( a, b) ;
1316}
1417
1518// EMIT_MIR lower_intrinsics.unchecked.LowerIntrinsics.diff
1619pub 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(
1728 let _a = core:: intrinsics:: unchecked_add ( a, b) ;
1829 let _b = core:: intrinsics:: unchecked_sub ( a, b) ;
1930 let _c = core:: intrinsics:: unchecked_mul ( a, b) ;
@@ -25,60 +36,95 @@ pub unsafe fn unchecked(a: i32, b: i32) {
2536
2637// EMIT_MIR lower_intrinsics.size_of.LowerIntrinsics.diff
2738pub fn size_of < T > ( ) -> usize {
39+ // CHECK-LABEL: fn size_of(
40+ // CHECK: {{_.*}} = SizeOf(T);
2841 core:: intrinsics:: size_of :: < T > ( )
2942}
3043
3144// EMIT_MIR lower_intrinsics.align_of.LowerIntrinsics.diff
3245pub fn align_of < T > ( ) -> usize {
46+ // CHECK-LABEL: fn align_of(
47+ // CHECK: {{_.*}} = AlignOf(T);
3348 core:: intrinsics:: min_align_of :: < T > ( )
3449}
3550
3651// EMIT_MIR lower_intrinsics.forget.LowerIntrinsics.diff
3752pub fn forget < T > ( t : T ) {
53+ // CHECK-LABEL: fn forget(
54+ // CHECK-NOT: Drop(
55+ // CHECK: return;
56+ // CHECK-NOT: Drop(
3857 core:: intrinsics:: forget ( t)
3958}
4059
4160// EMIT_MIR lower_intrinsics.unreachable.LowerIntrinsics.diff
4261pub fn unreachable ( ) -> ! {
62+ // CHECK-LABEL: fn unreachable(
63+ // CHECK: unreachable;
4364 unsafe { core:: intrinsics:: unreachable ( ) } ;
4465}
4566
4667// EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff
4768pub fn non_const < T > ( ) -> usize {
69+ // CHECK-LABEL: fn non_const(
70+ // CHECK: SizeOf(T);
71+
4872 // Check that lowering works with non-const operand as a func.
4973 let size_of_t = core:: intrinsics:: size_of :: < T > ;
5074 size_of_t ( )
5175}
5276
5377// EMIT_MIR lower_intrinsics.transmute_inhabited.LowerIntrinsics.diff
5478pub fn transmute_inhabited ( c : std:: cmp:: Ordering ) -> i8 {
79+ // CHECK-LABEL: fn transmute_inhabited(
80+ // CHECK: {{_.*}} = {{.*}} as i8 (Transmute);
81+
5582 unsafe { std:: mem:: transmute ( c) }
5683}
5784
5885// EMIT_MIR lower_intrinsics.transmute_uninhabited.LowerIntrinsics.diff
5986pub unsafe fn transmute_uninhabited ( u : ( ) ) -> Never {
87+ // CHECK-LABEL: fn transmute_uninhabited(
88+ // CHECK: {{_.*}} = {{.*}} as Never (Transmute);
89+ // CHECK: unreachable;
90+
6091 unsafe { std:: mem:: transmute :: < ( ) , Never > ( u) }
6192}
6293
6394// EMIT_MIR lower_intrinsics.transmute_ref_dst.LowerIntrinsics.diff
6495pub 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+
6599 unsafe { std:: mem:: transmute ( u) }
66100}
67101
68102// EMIT_MIR lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.diff
69103pub unsafe fn transmute_to_ref_uninhabited ( ) -> ! {
104+ // CHECK-LABEL: fn transmute_to_ref_uninhabited(
105+ // CHECK: {{_.*}} = {{.*}} as &Never (Transmute);
106+ // CHECK: unreachable;
107+
70108 let x: & Never = std:: mem:: transmute ( 1usize ) ;
71109 match * x { }
72110}
73111
74112// EMIT_MIR lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.diff
75113pub unsafe fn transmute_to_mut_uninhabited ( ) -> ! {
114+ // CHECK-LABEL: fn transmute_to_mut_uninhabited(
115+ // CHECK: {{_.*}} = {{.*}} as &mut Never (Transmute);
116+ // CHECK: unreachable;
117+
76118 let x: & mut Never = std:: mem:: transmute ( 1usize ) ;
77119 match * x { }
78120}
79121
80122// EMIT_MIR lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.diff
81123pub 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+
82128 let x: Box < Never > = std:: mem:: transmute ( 1usize ) ;
83129 match * x { }
84130}
@@ -91,6 +137,12 @@ pub enum E {
91137
92138// EMIT_MIR lower_intrinsics.discriminant.LowerIntrinsics.diff
93139pub fn discriminant < T > ( t : T ) {
140+ // CHECK-LABEL: fn discriminant(
141+ // CHECK: {{_.*}} = discriminant(
142+ // CHECK: {{_.*}} = discriminant(
143+ // CHECK: {{_.*}} = discriminant(
144+ // CHECK: {{_.*}} = discriminant(
145+
94146 core:: intrinsics:: discriminant_value ( & t) ;
95147 core:: intrinsics:: discriminant_value ( & 0 ) ;
96148 core:: intrinsics:: discriminant_value ( & ( ) ) ;
@@ -105,6 +157,9 @@ extern "rust-intrinsic" {
105157
106158// EMIT_MIR lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff
107159pub fn f_copy_nonoverlapping ( ) {
160+ // CHECK-LABEL: fn f_copy_nonoverlapping(
161+ // CHECK: copy_nonoverlapping({{.*}});
162+
108163 let src = ( ) ;
109164 let mut dst = ( ) ;
110165 unsafe {
@@ -114,37 +169,65 @@ pub fn f_copy_nonoverlapping() {
114169
115170// EMIT_MIR lower_intrinsics.assume.LowerIntrinsics.diff
116171pub fn assume ( ) {
172+ // CHECK-LABEL: fn assume(
173+ // CHECK: assume({{.*}});
174+
117175 unsafe {
118176 std:: intrinsics:: assume ( true ) ;
119177 }
120178}
121179
122180// EMIT_MIR lower_intrinsics.with_overflow.LowerIntrinsics.diff
123181pub fn with_overflow ( a : i32 , b : i32 ) {
182+ // CHECK-LABEL: fn with_overflow(
183+ // CHECK: CheckedAdd(
184+ // CHECK: CheckedSub(
185+ // CHECK: CheckedMul(
186+
124187 let _x = core:: intrinsics:: add_with_overflow ( a, b) ;
125188 let _y = core:: intrinsics:: sub_with_overflow ( a, b) ;
126189 let _z = core:: intrinsics:: mul_with_overflow ( a, b) ;
127190}
128191
129192// EMIT_MIR lower_intrinsics.read_via_copy_primitive.LowerIntrinsics.diff
130193pub 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+
131199 unsafe { core:: intrinsics:: read_via_copy ( r) }
132200}
133201
134202// EMIT_MIR lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.diff
135203pub 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+
136209 unsafe { core:: intrinsics:: read_via_copy ( r) }
137210}
138211
139212// EMIT_MIR lower_intrinsics.write_via_move_string.LowerIntrinsics.diff
140213pub 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+
141220 unsafe { core:: intrinsics:: write_via_move ( r, v) }
142221}
143222
144223pub enum Never { }
145224
146225// EMIT_MIR lower_intrinsics.option_payload.LowerIntrinsics.diff
147226pub 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+
148231 unsafe {
149232 let _x = core:: intrinsics:: option_payload_ptr ( o) ;
150233 let _y = core:: intrinsics:: option_payload_ptr ( p) ;
@@ -153,5 +236,8 @@ pub fn option_payload(o: &Option<usize>, p: &Option<String>) {
153236
154237// EMIT_MIR lower_intrinsics.ptr_offset.LowerIntrinsics.diff
155238pub unsafe fn ptr_offset ( p : * const i32 , d : isize ) -> * const i32 {
239+ // CHECK-LABEL: fn ptr_offset(
240+ // CHECK: _0 = Offset(
241+
156242 core:: intrinsics:: offset ( p, d)
157243}
0 commit comments