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