* iltests.il: New test for LDELEMA on an array of ref types.
[mono.git] / mono / mini / iltests.il
1 .assembly iltests {}
2 .assembly extern TestDriver {}
3 .assembly extern mscorlib {}
4
5 .class public auto ansi sealed beforefieldinit Tests {
6
7         .method static public int32 Main() il managed {
8                 .entrypoint
9                 
10                 ldtoken Tests
11                 call       class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)
12                 call       int32 [TestDriver]TestDriver::RunTests(class [mscorlib]System.Type)
13                 ret
14         }
15
16         // make sure the register allocator works when the return value of
17         // 'div' is discarded
18         .method static public int32 test_0_div_regalloc () il managed {
19                 .locals init (
20                         int32 i
21                 )
22
23                 ldloc 0
24                 ldc.i4.s 0xa
25                 div
26                 pop
27                 ldc.i4.0
28                 ret
29         }
30         
31         
32         .method static public int32 test_1_ceq_to_i4 () il managed {
33                 .locals init (
34                         int32   foo
35                 )
36                 ldc.i4 500
37                 stloc foo
38                 ldloc foo
39                 ldc.i4 500
40                 ceq
41                 stloc foo
42                 ldloc foo
43                 ret
44         }
45         
46         .method static public int32 test_3_shl_regvars () il managed {
47                 .locals init (
48                         int32   a,
49                         int32   b,
50                         int32   r1,
51                         int32   r2,
52                         int32   r3
53                 )
54                         
55                 ldc.i4.2
56                 stloc      a
57                 ldc.i4.1
58                 stloc      b
59         
60                 ldloc      a
61                 ldloc      b
62                 shl 
63                 stloc      r1
64                 
65                 ldloc      a
66                 ldloc      b
67                 shl 
68                 stloc      r2
69                 
70                 ldloc      a
71                 ldloc      b
72                 shl 
73                 stloc      r3
74                 
75                 ldloc      r1
76                 ldc.i4.4
77                 ceq
78                 
79                 ldloc      r2
80                 ldc.i4.4
81                 ceq
82                 
83                 ldloc      r3
84                 ldc.i4.4
85                 ceq
86                 
87                 add
88                 add
89                 
90                 ret
91         }
92         
93         .method static public int32 test_1_fceq_to_i4 () il managed {
94         
95                 .locals init (
96                         float64 foo,
97                         int32   val
98                 )
99
100                 ldc.r8      2
101                 stloc       foo
102                 
103                 ldloc       foo
104                 ldc.r8      2
105                 ceq
106                 stloc       val
107                 
108                 ldloc       val
109                 ret
110         }
111
112         //
113         // This should be manually checked. Basically under -O=linears,
114         // you should not see tons of register spilling.
115         //
116         .method static public int32 test_1_bytedreg_free () il managed {
117                 .locals init (
118                         int32   foo
119                 )
120                 ldc.i4 500
121                 stloc foo
122                 ldloc foo
123                 ldc.i4 500
124                 ceq
125                 stloc foo
126                 
127                 ldloc foo
128                 ldc.i4 1
129                 ceq
130                 stloc foo
131
132                 ldloc foo
133                 ldc.i4 1
134                 ceq
135                 stloc foo
136
137                 ldloc foo
138                 ldc.i4 1
139                 ceq
140                 stloc foo
141                 
142                 ldloc foo
143                 ldc.i4 1
144                 ceq
145                 stloc foo
146                 
147                 ldloc foo
148                 ret
149         }
150         
151         //
152         // This should be manually checked. Basically under -O=linears,
153         // you should not see tons of register spilling.
154         //
155         .method static public int32 test_0_bytesreg1_free () il managed {
156                 .locals init (
157                         unsigned int8      dest,
158                         int32              src,
159                         unsigned int8&     pdest
160                 )
161
162                 ldloca     dest
163                 stloc      pdest
164                 
165                 ldloc      pdest
166                 ldloc      src
167                 stind.i1
168                 
169                 ldloc      pdest
170                 ldloc      src
171                 stind.i1
172                 
173                 ldloc      pdest
174                 ldloc      src
175                 stind.i1
176                 
177                 ldloc      pdest
178                 ldloc      src
179                 stind.i1
180                 
181                 ldloc      pdest
182                 ldloc      src
183                 stind.i1
184                 
185                 ldloc      pdest
186                 ldloc      src
187                 stind.i1
188                 
189                 ldloc      pdest
190                 ldind.i1
191                 ret
192         }
193         
194         .method static public int32 test_1_shift_regvar () il managed {
195         
196                 .locals init (
197                         int32   v7FFFFFFF,
198                         int32   v1
199                 )
200                 
201                 ldc.i4  0x7FFFFFFF
202                 stloc   v7FFFFFFF
203         
204                 ldc.i4.1
205                 stloc v1
206                 
207                 ldloc   v7FFFFFFF
208                 ldloc   v1
209                 shl
210                 ldc.i4  0xFFFFFFFE
211                 ceq
212                 ret
213         }
214         
215         // this only happens with the managed pointer, not an unmanaged one.
216         .method static public int32 test_0_foo () il managed {
217         
218                 .locals init (
219                         int32&  buf
220                 )
221                 
222                 ldc.i4.5
223                 localloc
224                 
225                 stloc buf
226                 ldloc buf
227                 
228                 ldind.i4
229                 
230                 ret
231         }
232
233         .method static public int32 test_0_localloc () cil managed {
234                 .locals init (native int, native int, native int, native int, int32)
235
236                 ldc.i4 6
237                 localloc
238                 conv.i
239                 stloc.0
240
241                 ldc.i4 6
242                 localloc
243                 conv.i
244                 stloc.1
245
246                 ldc.i4 6
247                 localloc
248                 conv.i
249                 stloc.2
250
251                 // Variable length
252                 ldc.i4 128
253                 stloc.s 4
254                 ldloc.s 4
255                 localloc
256                 conv.i
257                 stloc.3
258
259                 // Check zero initialized
260                 ldloc.0
261                 ldind.i4
262                 ldc.i4.0
263                 beq OK1
264                 ldc.i4.1
265                 br FAIL
266
267 OK1:
268                 ldloc.3
269                 ldind.i4
270                 ldc.i4.0
271                 beq OK2
272                 ldc.i4.2
273                 br FAIL
274
275 OK2:
276                 ldloc.3
277                 ldc.i4.s 124
278                 add
279                 ldind.i4
280                 ldc.i4.0
281                 beq OK3
282                 ldc.i4.3
283                 br FAIL
284
285 OK3:
286                 ldloc.1
287                 ldc.i4 999999
288                 stind.i4
289                 ldloc.1
290                 ldind.i4
291                 ldc.i4 999999
292                 beq OK4
293                 ldc.i4.4
294                 br FAIL
295
296 OK4:
297                 ldloc.0
298                 ldc.i4 999999
299                 stind.i4
300                 ldloc.0
301                 ldind.i4
302                 ldc.i4 999999
303                 beq PASS
304                 ldc.i4.5
305                 br FAIL
306
307 FAIL:
308                 ret
309
310 PASS:   ldc.i4.0
311                 ret
312         }
313
314     .method private static void do_localloc () cil managed {
315         .maxstack 3
316         .locals init (
317                 unsigned int8*  V_0)
318         IL_0000:  ldc.i4.1
319         IL_0001:  ldc.i4 131072
320         IL_0006:  mul
321         IL_0007:  localloc
322         IL_0009:  stloc.0
323         IL_000a:  ret
324     }
325
326         // Check that localloc can't be inlined
327         .method static public int32 test_0_localloc_inline () cil managed {
328                 .maxstack 16
329                 .locals init (
330                         int32 i
331                 )
332
333                 ldc.i4.0
334         stloc.0
335         br COND
336
337 START:  call void class Tests::do_localloc()
338         ldloc.0
339         ldc.i4.1
340         add
341         stloc.0
342 COND:   ldloc.0
343         ldc.i4 1000
344         blt START
345
346                 ldc.i4.0
347                 ret
348         }       
349         
350         .method static public int32 test_3_copy_used_bug () il managed {
351
352                 .locals init (
353                         int32 size,
354                         int32 res
355                 )
356
357                 ldc.i4 0
358                 stloc res
359
360                 ldc.i4 1
361                 stloc size
362
363                 ldloc size
364                 ldloc size
365                 ldloc size
366                 add
367                 stloc size
368                 ldloc size
369                 add
370                 stloc res
371
372                 ldloc res
373                 ret
374         }
375
376         // demonstrate that the copy_used_var is not a fix for the above bug
377         .method static public int32 test_3_copy_used_indir_bug () il managed {
378
379                 .locals init (
380                         int32 size,
381                         int32 res
382                 )
383
384                 ldc.i4 0
385                 stloc res
386
387                 ldc.i4 1
388                 stloc size
389
390                 ldloc size
391                 ldloca size
392                 ldloc size
393                 ldloc size
394                 add
395                 stind.i4
396                 ldloc size
397                 add
398                 stloc res
399
400                 ldloc res
401                 ret
402         }
403
404         .method static public void do_nothing (int32 a) il managed {
405                 ret
406         }
407         
408         // demonstrate the block_split failure: needs -O=inline
409         // mini -O=inline --compile Tests:test_0_split_block_bug iltests.exe
410         .method static public int32 test_0_split_block_bug () il managed {
411
412                 .locals init (
413                         int32 i1
414                 )
415
416                 ldc.i4 1
417                 stloc i1
418  test_label:
419                 ldloc i1
420                 call void class Tests::do_nothing (int32)
421                 ldc.i4 0
422                 brtrue test_label
423                 
424                 ldc.i4 0
425                 ret
426         }
427
428         .method public void inline_do_nothing () il managed {
429                 ret
430         }
431         .method static public int32 test_1_checkthis_inlining () il managed {
432                 ldnull
433                 call instance void class Tests::inline_do_nothing ()
434                 ldc.i4 1
435                 ret
436         }
437
438         .class nested private auto ansi sealed beforefieldinit TailCallStruct 
439                 extends [mscorlib]System.ValueType {
440                 .field public int32 a
441                 .field public int32 b
442         }
443
444         .method static valuetype Tests/TailCallStruct tail1 (valuetype Tests/TailCallStruct arg) {
445                 ldarga 0
446                 ldarga 0
447                 ldfld int32 Tests/TailCallStruct::a
448                 ldc.i4.1
449                 add
450                 stfld int32 Tests/TailCallStruct::a
451                 ldarga 0
452                 ldarga 0
453                 ldfld int32 Tests/TailCallStruct::a
454                 ldc.i4.2
455                 add
456                 stfld int32 Tests/TailCallStruct::a
457                 ldarg.0
458                 ret
459         }
460
461         .method static valuetype Tests/TailCallStruct tail2 (valuetype Tests/TailCallStruct arg) {
462                 ldarg.0
463                 tail.
464                 call valuetype Tests/TailCallStruct Tests::tail1 (valuetype Tests/TailCallStruct)
465                 ret
466         }
467
468         .method static public int32 test_0_tail_calls () il managed {
469                 .maxstack 16
470                 .locals init (
471                         valuetype Tests/TailCallStruct arg
472                 )
473                 ldloca 0
474                 ldc.i4.2
475                 stfld int32 Tests/TailCallStruct::a
476                 ldloca 0
477                 ldc.i4.4
478                 stfld int32 Tests/TailCallStruct::b
479                 ldloc.0
480                 call valuetype Tests/TailCallStruct Tests::tail2 (valuetype Tests/TailCallStruct)
481                 stloc.0
482                 ldloca 0
483                 ldfld int32 Tests/TailCallStruct::a
484                 ldloca 0
485                 ldfld int32 Tests/TailCallStruct::b
486                 add
487                 ldc.i4 9
488                 sub
489                 ret
490         }
491
492         .method static public int32 test_11_switch_with_nonempty_stack () il managed {
493                 .maxstack 16
494
495                 ldc.i4.5
496                 ldc.i4.6
497                 ldc.i4.1
498                 switch (L0, L1)
499         L0: 
500                 add
501                 ret
502         L1:
503                 add
504                 ret
505         }
506  
507     .method public static int32 test_5_endfinally_with_nonempty_stack () il managed {
508                 .maxstack 16
509
510         .try {
511           leave IL_0
512         }
513         finally  {
514           ldc.i4.0
515           endfinally
516         }
517         IL_0:  ldc.i4.5
518                 ret
519     }
520
521         .method public static int32 test_0_conv_ovf_i8_neg () il managed {
522                 .maxstack 16
523
524                 ldc.i4.m1
525                 conv.ovf.i8
526                 conv.i4
527                 ldc.i4.m1
528                 beq L_OK
529                 ldc.i4.1
530                 ret
531         L_OK:
532                 ldc.i4.0
533                 ret
534         }               
535
536         .method public static int32 test_0_get_type_from_handle_on_bblock_boundary () cil managed 
537         {
538                 .maxstack 16
539         
540                 ldc.i4.1
541                 brfalse OBJECT
542         
543                 ldtoken [mscorlib]System.String
544                 br AFTER
545         OBJECT:
546                 ldtoken [mscorlib]System.Object
547         AFTER:
548                 call class [mscorlib]'System.Type' class [mscorlib]'System.Type'::'GetTypeFromHandle'(valuetype [mscorlib]'System.RuntimeTypeHandle')
549                 callvirt instance string class [mscorlib]System.Type::get_FullName ()
550                 ldstr "System.String"
551                 callvirt instance bool class [mscorlib]System.Object::Equals(object)
552                 ldc.i4.0
553                 ceq
554                 ret 
555         }
556                 
557         .method public static int32 test_0_bug59580  ()
558         {
559                 ldc.r4          float32(0x7FC00000)
560                 ldc.r4          float32(0x7FC00000)
561                 bge.un          pass
562                 br              fail
563         pass:
564                 ldc.i4.0
565                 ret
566         fail:
567                 ldc.i4.1
568                 ret
569         }
570         
571         .method public static int32 test_1_bug60056  () {
572                 .locals init (int32 m5)
573                         
574                 ldc.i4.m1
575                 stloc.0
576                 
577                 ldc.i4.1
578                 conv.u8
579                 
580                 ldloc.0
581                 conv.i8
582                 mul
583                 
584                 ldc.i4.m1
585                 conv.i8
586                 ceq
587                 ret
588         }
589         
590         .method public static int32 test_1_conv_u8_cfold  () {
591                 ldc.i4.m1
592                 conv.u8
593                 
594                 ldc.i8 0x00000000ffffffff
595                 
596                 ceq
597                 ret
598         }
599         
600         .method public static int32 test_1_array_type_mismatch_ldelema  () {
601                 .locals init (int32 r)
602                 
603                         ldc.i4.1
604                         newarr string
605                         ldc.i4.0 
606                         ldelema string
607                         pop
608                 
609                 .try {
610                         ldc.i4.1
611                         newarr string
612                         ldc.i4.0 
613                         ldelema object
614                         pop
615                         
616                         leave end
617                 } catch [mscorlib]System.ArrayTypeMismatchException {
618                         pop
619                         ldc.i4.1
620                         stloc.0
621                         leave end
622                 }
623         end:
624                 ldloc.0
625                 ret
626         }
627 }