imported everything from my branch (which is slightly harmless).
[mono.git] / mono / mini / exceptions.cs
1 using System;
2 using System.Reflection;
3
4 /*
5  * Regression tests for the mono JIT.
6  *
7  * Each test needs to be of the form:
8  *
9  * public static int test_<result>_<name> ();
10  *
11  * where <result> is an integer (the value that needs to be returned by
12  * the method to make it pass.
13  * <name> is a user-displayed name used to identify the test.
14  *
15  * The tests can be driven in two ways:
16  * *) running the program directly: Main() uses reflection to find and invoke
17  *      the test methods (this is useful mostly to check that the tests are correct)
18  * *) with the --regression switch of the jit (this is the preferred way since
19  *      all the tests will be run with optimizations on and off)
20  *
21  * The reflection logic could be moved to a .dll since we need at least another
22  * regression test file written in IL code to have better control on how
23  * the IL code looks.
24  */
25
26 class Tests {
27
28         public static int Main () {
29                 return TestDriver.RunTests (typeof (Tests));
30         }
31
32         public static int test_0_catch () {
33                 Exception x = new Exception ();
34                 
35                 try {
36                         throw x;
37                 } catch (Exception e) {
38                         if (e == x)
39                                 return 0;
40                 }
41                 return 1;
42         }
43
44         public static int test_0_finally_without_exc () {
45                 int x;
46                 
47                 try {
48                         x = 1;
49                 } catch (Exception e) {
50                         x = 2;
51                 } finally {
52                         x = 0;
53                 }
54                 
55                 return x;
56         }
57
58         public static int test_0_finally () {
59                 int x = 1;
60                 
61                 try {
62                         throw new Exception ();
63                 } catch (Exception e) {
64                         x = 2;
65                 } finally {
66                         x = 0;
67                 }
68                 return x;
69         }
70
71         public static int test_0_nested_finally () {
72                 int a;
73
74                 try {
75                         a = 1;
76                 } finally {
77                         try {
78                                 a = 2;
79                         } finally {
80                                 a = 0;
81                         }
82                 }
83                 return a;
84         }               
85
86         public static int test_0_byte_cast () {
87                 int a;
88                 long l;
89                 ulong ul;
90                 byte b = 0;
91                 bool failed;
92
93                 try {
94                         a = 255;
95                         failed = false;
96                         checked {
97                                 b = (byte)a;
98                         }
99                 } catch (OverflowException) {
100                         failed = true;
101                 }
102                 if (failed)
103                         return 1;
104                 if (b != 255)
105                         return -1;
106
107                 try {
108                         a = 0;
109                         failed = false;
110                         checked {
111                                 b = (byte)a;
112                         }
113                 } catch (OverflowException) {
114                         failed = true;
115                 }
116                 if (failed)
117                         return 2;
118                 if (b != 0)
119                         return -2;
120
121
122                 try {
123                         a = 256;
124                         failed = true;
125                         checked {
126                                 b = (byte)a;
127                         }
128                 } catch (OverflowException) {
129                         failed = false;
130                 }
131                 if (failed)
132                         return 3;
133                 if (b != 0)
134                         return -3;
135
136                 try {
137                         a = -1;
138                         failed = true;
139                         checked {
140                                 b = (byte)a;
141                         }
142                 } catch (OverflowException) {
143                         failed = false;
144                 }
145                 if (failed)
146                         return 4;
147                 if (b != 0)
148                         return -4;
149
150                 try {
151                         double d = 0;
152                         failed = false;
153                         checked {
154                                 b = (byte)d;
155                         }
156                 } catch (OverflowException) {
157                         failed = true;
158                 }
159                 if (failed)
160                         return 5;
161                 if (b != 0)
162                         return -5;
163                 
164                 try {
165                         double d = -1;
166                         failed = true;
167                         checked {
168                                 b = (byte)d;
169                         }
170                 } catch (OverflowException) {
171                         failed = false;
172                 }
173                 if (failed)
174                         return 6;
175                 if (b != 0)
176                         return -6;
177
178                 try {
179                         double d = 255;
180                         failed = false;
181                         checked {
182                                 b = (byte)d;
183                         }
184                 } catch (OverflowException) {
185                         failed = true;
186                 }
187                 if (failed)
188                         return 7;
189                 if (b != 255)
190                         return -7;
191
192                 try {
193                         double d = 256;
194                         failed = true;
195                         checked {
196                                 b = (byte)d;
197                         }
198                 } catch (OverflowException) {
199                         failed = false;
200                 }
201                 if (failed)
202                         return 8;
203                 if (b != 255)
204                         return -8;
205
206                 try {
207                         l = 255;
208                         failed = false;
209                         checked {
210                                 b = (byte)l;
211                         }
212                 } catch (OverflowException) {
213                         failed = true;
214                 }
215                 if (failed)
216                         return 9;
217                 if (b != 255)
218                         return -9;
219
220                 try {
221                         l = 0;
222                         failed = false;
223                         checked {
224                                 b = (byte)l;
225                         }
226                 } catch (OverflowException) {
227                         failed = true;
228                 }
229                 if (failed)
230                         return 10;
231                 if (b != 0)
232                         return -10;
233
234                 try {
235                         l = 256;
236                         failed = true;
237                         checked {
238                                 b = (byte)l;
239                         }
240                 } catch (OverflowException) {
241                         failed = false;
242                 }
243                 if (failed)
244                         return 11;
245                 if (b != 0)
246                         return -11;
247
248                 try {
249                         l = -1;
250                         failed = true;
251                         checked {
252                                 b = (byte)l;
253                         }
254                 } catch (OverflowException) {
255                         failed = false;
256                 }
257                 if (failed)
258                         return 12;
259                 if (b != 0)
260                         return -12;
261
262                 try {
263                         ul = 256;
264                         failed = true;
265                         checked {
266                                 b = (byte)ul;
267                         }
268                 }
269                 catch (OverflowException) {
270                         failed = false;
271                 }
272                 if (failed)
273                         return 13;
274                 if (b != 0)
275                         return -13;
276
277                 return 0;
278         }
279         
280         public static int test_0_sbyte_cast () {
281                 int a;
282                 long l;
283                 sbyte b = 0;
284                 bool failed;
285
286                 try {
287                         a = 255;
288                         failed = true;
289                         checked {
290                                 b = (sbyte)a;
291                         }
292                 } catch (OverflowException) {
293                         failed = false;
294                 }
295                 if (failed)
296                         return 1;
297                 if (b != 0)
298                         return -1;
299
300                 try {
301                         a = 0;
302                         failed = false;
303                         checked {
304                                 b = (sbyte)a;
305                         }
306                 } catch (OverflowException) {
307                         failed = true;
308                 }
309                 if (failed)
310                         return 2;
311                 if (b != 0)
312                         return -2;
313
314                 try {
315                         a = 256;
316                         failed = true;
317                         checked {
318                                 b = (sbyte)a;
319                         }
320                 } catch (OverflowException) {
321                         failed = false;
322                 }
323                 if (failed)
324                         return 3;
325                 if (b != 0)
326                         return -3;
327
328                 try {
329                         a = -129;
330                         failed = true;
331                         checked {
332                                 b = (sbyte)a;
333                         }
334                 } catch (OverflowException) {
335                         failed = false;
336                 }
337                 if (failed)
338                         return 4;
339                 if (b != 0)
340                         return -4;
341
342                 try {
343                         a = -1;
344                         failed = false;
345                         checked {
346                                 b = (sbyte)a;
347                         }
348                 } catch (OverflowException) {
349                         failed = true;
350                 }
351                 if (failed)
352                         return 5;
353                 if (b != -1)
354                         return -5;
355
356                 try {
357                         a = -128;
358                         failed = false;
359                         checked {
360                                 b = (sbyte)a;
361                         }
362                 } catch (OverflowException) {
363                         failed = true;
364                 }
365                 if (failed)
366                         return 6;
367                 if (b != -128)
368                         return -6;
369
370                 try {
371                         a = 127;
372                         failed = false;
373                         checked {
374                                 b = (sbyte)a;
375                         }
376                 } catch (OverflowException) {
377                         failed = true;
378                 }
379                 if (failed)
380                         return 7;
381                 if (b != 127)
382                         return -7;
383
384                 try {
385                         a = 128;
386                         failed = true;
387                         checked {
388                                 b = (sbyte)a;
389                         }
390                 } catch (OverflowException) {
391                         failed = false;
392                 }
393                 if (failed)
394                         return 8;
395                 if (b != 127)
396                         return -8;
397
398                 try {
399                         double d = 127;
400                         failed = false;
401                         checked {
402                                 b = (sbyte)d;
403                         }
404                 } catch (OverflowException) {
405                         failed = true;
406                 }
407                 if (failed)
408                         return 9;
409                 if (b != 127)
410                         return -9;
411
412                 try {
413                         double d = -128;
414                         failed = false;
415                         checked {
416                                 b = (sbyte)d;
417                         }
418                 } catch (OverflowException) {
419                         failed = true;
420                 }
421                 if (failed)
422                         return 10;
423                 if (b != -128)
424                         return -10;
425
426                 try {
427                         double d = 128;
428                         failed = true;
429                         checked {
430                                 b = (sbyte)d;
431                         }
432                 } catch (OverflowException) {
433                         failed = false;
434                 }
435                 if (failed)
436                         return 11;
437                 if (b != -128)
438                         return -11;
439
440                 try {
441                         double d = -129;
442                         failed = true;
443                         checked {
444                                 b = (sbyte)d;
445                         }
446                 } catch (OverflowException) {
447                         failed = false;
448                 }
449                 if (failed)
450                         return 12;
451                 if (b != -128)
452                         return -12;
453
454                 try {
455                         l = 255;
456                         failed = true;
457                         checked {
458                                 b = (sbyte)l;
459                         }
460                 } catch (OverflowException) {
461                         failed = false;
462                 }
463                 if (failed)
464                         return 13;
465                 if (b != -128)
466                         return -13;
467
468                 try {
469                         l = 0;
470                         failed = false;
471                         checked {
472                                 b = (sbyte)l;
473                         }
474                 } catch (OverflowException) {
475                         failed = true;
476                 }
477                 if (failed)
478                         return 14;
479                 if (b != 0)
480                         return -14;
481
482                 try {
483                         l = 256;
484                         failed = true;
485                         checked {
486                                 b = (sbyte)l;
487                         }
488                 } catch (OverflowException) {
489                         failed = false;
490                 }
491                 if (failed)
492                         return 15;
493                 if (b != 0)
494                         return -15;
495
496                 try {
497                         l = -129;
498                         failed = true;
499                         checked {
500                                 b = (sbyte)l;
501                         }
502                 } catch (OverflowException) {
503                         failed = false;
504                 }
505                 if (failed)
506                         return 16;
507                 if (b != 0)
508                         return -16;
509
510                 try {
511                         l = -1;
512                         failed = false;
513                         checked {
514                                 b = (sbyte)l;
515                         }
516                 } catch (OverflowException) {
517                         failed = true;
518                 }
519                 if (failed)
520                         return 17;
521                 if (b != -1)
522                         return -17;
523
524                 try {
525                         l = -128;
526                         failed = false;
527                         checked {
528                                 b = (sbyte)l;
529                         }
530                 } catch (OverflowException) {
531                         failed = true;
532                 }
533                 if (failed)
534                         return 18;
535                 if (b != -128)
536                         return -18;
537
538                 try {
539                         l = 127;
540                         failed = false;
541                         checked {
542                                 b = (sbyte)l;
543                         }
544                 } catch (OverflowException) {
545                         failed = true;
546                 }
547                 if (failed)
548                         return 19;
549                 if (b != 127)
550                         return -19;
551
552                 try {
553                         l = 128;
554                         failed = true;
555                         checked {
556                                 b = (sbyte)l;
557                         }
558                 } catch (OverflowException) {
559                         failed = false;
560                 }
561                 if (failed)
562                         return 20;
563                 if (b != 127)
564                         return -20;
565
566                 try {
567                         ulong ul = 128;
568                         failed = true;
569                         checked {
570                                 b = (sbyte)ul;
571                         }
572                 }
573                 catch (OverflowException) {
574                         failed = false;
575                 }
576                 if (failed)
577                         return 21;
578                 if (b != 127)
579                         return -21;
580
581                 return 0;
582         }
583
584         public static int test_0_ushort_cast () {
585                 int a;
586                 long l;
587                 ulong ul;
588                 ushort b;
589                 bool failed;
590
591                 try {
592                         a = System.UInt16.MaxValue;
593                         failed = false;
594                         checked {
595                                 b = (ushort)a;
596                         }
597                 } catch (OverflowException) {
598                         failed = true;
599                 }
600                 if (failed)
601                         return 1;
602
603                 try {
604                         a = 0;
605                         failed = false;
606                         checked {
607                                 b = (ushort)a;
608                         }
609                 } catch (OverflowException) {
610                         failed = true;
611                 }
612                 if (failed)
613                         return 2;
614
615                 try {
616                         a = System.UInt16.MaxValue + 1;
617                         failed = true;
618                         checked {
619                                 b = (ushort)a;
620                         }
621                 } catch (OverflowException) {
622                         failed = false;
623                 }
624                 if (failed)
625                         return 3;
626
627                 try {
628                         a = -1;
629                         failed = true;
630                         checked {
631                                 b = (ushort)a;
632                         }
633                 } catch (OverflowException) {
634                         failed = false;
635                 }
636                 if (failed)
637                         return 4;
638
639                 try {
640                         double d = 0;
641                         failed = false;
642                         checked {
643                                 b = (ushort)d;
644                         }
645                 } catch (OverflowException) {
646                         failed = true;
647                 }
648                 if (failed)
649                         return 5;
650
651                 try {
652                         double d = System.UInt16.MaxValue;
653                         failed = false;
654                         checked {
655                                 b = (ushort)d;
656                         }
657                 } catch (OverflowException) {
658                         failed = true;
659                 }
660                 if (failed)
661                         return 6;
662
663                 try {
664                         double d = -1;
665                         failed = true;
666                         checked {
667                                 b = (ushort)d;
668                         }
669                 } catch (OverflowException) {
670                         failed = false;
671                 }
672                 if (failed)
673                         return 7;
674
675                 try {
676                         double d = System.UInt16.MaxValue + 1.0;
677                         failed = true;
678                         checked {
679                                 b = (ushort)d;
680                         }
681                 } catch (OverflowException) {
682                         failed = false;
683                 }
684                 if (failed)
685                         return 8;
686
687                 try {
688                         l = System.UInt16.MaxValue;
689                         failed = false;
690                         checked {
691                                 b = (ushort)l;
692                         }
693                 } catch (OverflowException) {
694                         failed = true;
695                 }
696                 if (failed)
697                         return 9;
698
699                 try {
700                         l = 0;
701                         failed = false;
702                         checked {
703                                 b = (ushort)l;
704                         }
705                 } catch (OverflowException) {
706                         failed = true;
707                 }
708                 if (failed)
709                         return 10;
710
711                 try {
712                         l = System.UInt16.MaxValue + 1;
713                         failed = true;
714                         checked {
715                                 b = (ushort)l;
716                         }
717                 } catch (OverflowException) {
718                         failed = false;
719                 }
720                 if (failed)
721                         return 11;
722
723                 try {
724                         l = -1;
725                         failed = true;
726                         checked {
727                                 b = (ushort)l;
728                         }
729                 } catch (OverflowException) {
730                         failed = false;
731                 }
732                 if (failed)
733                         return 12;
734
735                 try {
736                         ul = 0xfffff;
737                         failed = true;
738                         checked {
739                                 b = (ushort)ul;
740                         }
741                 } catch (OverflowException) {
742                         failed = false;
743                 }
744                 if (failed)
745                         return 13;
746
747                 return 0;
748         }
749         
750         public static int test_0_short_cast () {
751                 int a;
752                 long l;
753                 short b;
754                 bool failed;
755
756                 try {
757                         a = System.UInt16.MaxValue;
758                         failed = true;
759                         checked {
760                                 b = (short)a;
761                         }
762                 } catch (OverflowException) {
763                         failed = false;
764                 }
765                 if (failed)
766                         return 1;
767
768                 try {
769                         a = 0;
770                         failed = false;
771                         checked {
772                                 b = (short)a;
773                         }
774                 } catch (OverflowException) {
775                         failed = true;
776                 }
777                 if (failed)
778                         return 2;
779
780                 try {
781                         a = System.Int16.MaxValue + 1;
782                         failed = true;
783                         checked {
784                                 b = (short)a;
785                         }
786                 } catch (OverflowException) {
787                         failed = false;
788                 }
789                 if (failed)
790                         return 3;
791
792                 try {
793                         a = System.Int16.MinValue - 1;
794                         failed = true;
795                         checked {
796                                 b = (short)a;
797                         }
798                 } catch (OverflowException) {
799                         failed = false;
800                 }
801                 if (failed)
802                         return 4;
803
804                 try {
805                         a = -1;
806                         failed = false;
807                         checked {
808                                 b = (short)a;
809                         }
810                 } catch (OverflowException) {
811                         failed = true;
812                 }
813                 if (failed)
814                         return 5;
815
816                 try {
817                         a = System.Int16.MinValue;
818                         failed = false;
819                         checked {
820                                 b = (short)a;
821                         }
822                 } catch (OverflowException) {
823                         failed = true;
824                 }
825                 if (failed)
826                         return 6;
827
828                 try {
829                         a = System.Int16.MaxValue;
830                         failed = false;
831                         checked {
832                                 b = (short)a;
833                         }
834                 } catch (OverflowException) {
835                         failed = true;
836                 }
837                 if (failed)
838                         return 7;
839
840                 try {
841                         a = System.Int16.MaxValue + 1;
842                         failed = true;
843                         checked {
844                                 b = (short)a;
845                         }
846                 } catch (OverflowException) {
847                         failed = false;
848                 }
849                 if (failed)
850                         return 8;
851
852                 try {
853                         double d = System.Int16.MaxValue;
854                         failed = false;
855                         checked {
856                                 b = (short)d;
857                         }
858                 } catch (OverflowException) {
859                         failed = true;
860                 }
861                 if (failed)
862                         return 9;
863                 
864                 try {
865                         double d = System.Int16.MinValue;
866                         failed = false;
867                         checked {
868                                 b = (short)d;
869                         }
870                 } catch (OverflowException) {
871                         failed = true;
872                 }
873                 if (failed)
874                         return 10;
875                 
876                 try {
877                         double d = System.Int16.MaxValue + 1.0;
878                         failed = true;
879                         checked {
880                                 b = (short)d;
881                         }
882                 } catch (OverflowException) {
883                         failed = false;
884                 }
885                 if (failed)
886                         return 11;
887
888                 try {
889                         double d = System.Int16.MinValue - 1.0;
890                         failed = true;
891                         checked {
892                                 b = (short)d;
893                         }
894                 } catch (OverflowException) {
895                         failed = false;
896                 }
897                 if (failed)
898                         return 12;
899
900                 try {
901                         l = System.Int16.MaxValue + 1;
902                         failed = true;
903                         checked {
904                                 b = (short)l;
905                         }
906                 } catch (OverflowException) {
907                         failed = false;
908                 }
909                 if (failed)
910                         return 13;
911
912                 try {
913                         l = System.Int16.MaxValue;
914                         failed = false;
915                         checked {
916                                 b = (short)l;
917                         }
918                 } catch (OverflowException) {
919                         failed = true;
920                 }
921                 if (failed)
922                         return 14;
923
924                 try {
925                         l = System.Int16.MinValue - 1;
926                         failed = true;
927                         checked {
928                                 b = (short)l;
929                         }
930                 } catch (OverflowException) {
931                         failed = false;
932                 }
933                 if (failed)
934                         return 15;
935
936                 
937                 try {
938                         l = System.Int16.MinValue;
939                         failed = false;
940                         checked {
941                                 b = (short)l;
942                         }
943                 } catch (OverflowException) {
944                         failed = true;
945                 }
946                 if (failed)
947                         return 16;
948
949                 try {
950                         l = 0x00000000ffffffff;
951                         failed = true;
952                         checked {
953                                 b = (short)l;
954                         }
955                 } catch (OverflowException) {
956                         failed = false;
957                 }
958                 if (failed)
959                         return 17;
960
961                 try {
962                         ulong ul = 32768;
963                         failed = true;
964                         checked {
965                                 b = (short)ul;
966                         }
967                 } catch (OverflowException) {
968                         failed = false;
969                 }
970                 if (failed)
971                         return 18;
972
973                 return 0;
974         }
975         
976         public static int test_0_int_cast () {
977                 int a;
978                 long l;
979                 bool failed;
980
981                 try {
982                         double d = System.Int32.MaxValue + 1.0;
983                         failed = true;
984                         checked {
985                                 a = (int)d;
986                         }
987                 } catch (OverflowException) {
988                         failed = false;
989                 }
990                 if (failed)
991                         return 1;
992
993                 try {
994                         double d = System.Int32.MaxValue;
995                         failed = false;
996                         checked {
997                                 a = (int)d;
998                         }
999                 } catch (OverflowException) {
1000                         failed = true;
1001                 }
1002                 if (failed)
1003                         return 2;
1004                 
1005
1006                 try {
1007                         double d = System.Int32.MinValue;
1008                         failed = false;                 
1009                         checked {
1010                                 a = (int)d;
1011                         }
1012                 } catch (OverflowException) {
1013                         failed = true;
1014                 }
1015                 if (failed)
1016                         return 3;
1017
1018
1019                 try {
1020                         double d =  System.Int32.MinValue - 1.0;
1021                         failed = true;
1022                         checked {
1023                                 a = (int)d;
1024                         }
1025                 } catch (OverflowException) {
1026                         failed = false;
1027                 }
1028                 if (failed)
1029                         return 4;
1030
1031                 try {
1032                         l = System.Int32.MaxValue + (long)1;
1033                         failed = true;
1034                         checked {
1035                                 a = (int)l;
1036                         }
1037                 } catch (OverflowException) {
1038                         failed = false;
1039                 }
1040                 if (failed)
1041                         return 5;
1042
1043                 try {
1044                         l = System.Int32.MaxValue;
1045                         failed = false;
1046                         checked {
1047                                 a = (int)l;
1048                         }
1049                 } catch (OverflowException) {
1050                         failed = true;
1051                 }
1052                 if (failed)
1053                         return 6;
1054                 
1055
1056                 try {
1057                         l = System.Int32.MinValue;
1058                         failed = false;                 
1059                         checked {
1060                                 a = (int)l;
1061                         }
1062                 } catch (OverflowException) {
1063                         failed = true;
1064                 }
1065                 if (failed)
1066                         return 7;
1067
1068
1069                 try {
1070                         l =  System.Int32.MinValue - (long)1;
1071                         failed = true;
1072                         checked {
1073                                 a = (int)l;
1074                         }
1075                 } catch (OverflowException) {
1076                         failed = false;
1077                 }
1078                 if (failed)
1079                         return 8;
1080
1081                 try {
1082                         uint ui = System.UInt32.MaxValue;
1083                         failed = true;
1084                         checked {
1085                                 a = (int)ui;
1086                         }
1087                 }
1088                 catch (OverflowException) {
1089                         failed = false;
1090                 }
1091                 if (failed)
1092                         return 9;
1093
1094                 try {
1095                         ulong ul = (long)(System.Int32.MaxValue) + 1;
1096                         failed = true;
1097                         checked {
1098                                 a = (int)ul;
1099                         }
1100                 }
1101                 catch (OverflowException) {
1102                         failed = false;
1103                 }
1104                 if (failed)
1105                         return 10;
1106
1107
1108                 {
1109                         int i; 
1110                         float f = 1.1f;
1111                         checked {
1112                                 i = (int) f;
1113                         }
1114                 }
1115
1116                 return 0;
1117         }
1118
1119         public static int test_0_uint_cast () {
1120                 uint a;
1121                 long l;
1122                 bool failed;
1123
1124                 try {
1125                         double d =  System.UInt32.MaxValue;
1126                         failed = false;
1127                         checked {
1128                                 a = (uint)d;
1129                         }
1130                 } catch (OverflowException) {
1131                         failed = true;
1132                 }
1133                 if (failed)
1134                         return 1;
1135
1136                 try {
1137                         double d = System.UInt32.MaxValue + 1.0;
1138                         failed = true;
1139                         checked {
1140                                 a = (uint)d;
1141                         }
1142                 } catch (OverflowException) {
1143                         failed = false;
1144                 }
1145                 if (failed)
1146                         return 2;
1147
1148                 try {
1149                         double d = System.UInt32.MinValue;
1150                         failed = false;
1151                         checked {
1152                                 a = (uint)d;
1153                         }
1154                 } catch (OverflowException) {
1155                         failed = true;
1156                 }
1157                 if (failed)
1158                         return 3;
1159
1160                 try {
1161                         double d = System.UInt32.MinValue - 1.0;
1162                         failed = true;
1163                         checked {
1164                                 a = (uint)d;
1165                         }
1166                 } catch (OverflowException) {
1167                         failed = false;
1168                 }
1169                 if (failed)
1170                         return 4;
1171                 
1172                 try {
1173                         l =  System.UInt32.MaxValue;
1174                         failed = false;
1175                         checked {
1176                                 a = (uint)l;
1177                         }
1178                 } catch (OverflowException) {
1179                         failed = true;
1180                 }
1181                 if (failed)
1182                         return 5;
1183
1184                 try {
1185                         l = System.UInt32.MaxValue + (long)1;
1186                         failed = true;
1187                         checked {
1188                                 a = (uint)l;
1189                         }
1190                 } catch (OverflowException) {
1191                         failed = false;
1192                 }
1193                 if (failed)
1194                         return 6;
1195
1196                 try {
1197                         l = System.UInt32.MinValue;
1198                         failed = false;
1199                         checked {
1200                                 a = (uint)l;
1201                         }
1202                 } catch (OverflowException) {
1203                         failed = true;
1204                 }
1205                 if (failed)
1206                         return 7;
1207
1208                 try {
1209                         l = System.UInt32.MinValue - (long)1;
1210                         failed = true;
1211                         checked {
1212                                 a = (uint)l;
1213                         }
1214                 } catch (OverflowException) {
1215                         failed = false;
1216                 }
1217                 if (failed)
1218                         return 8;
1219
1220                 try {
1221                         int i = -1;
1222                         failed = true;
1223                         checked {
1224                                 a = (uint)i;
1225                         }
1226                 }
1227                 catch (OverflowException) {
1228                         failed = false;
1229                 }
1230                 if (failed)
1231                         return 9;
1232
1233                 {
1234                         uint i; 
1235                         float f = 1.1f;
1236                         checked {
1237                                 i = (uint) f;
1238                         }
1239                 }
1240                 
1241                 return 0;
1242         }
1243         
1244         public static int test_0_long_cast () {
1245                 long a;
1246                 bool failed;
1247
1248                 try {
1249                         double d = System.Int64.MaxValue - 512.0;
1250                         failed = true;
1251                         checked {
1252                                 a = (long)d;
1253                         }
1254                 } catch (OverflowException) {
1255                         failed = false;
1256                 }
1257                 if (failed)
1258                         return 1;
1259
1260                 try {
1261                         double d = System.Int64.MaxValue - 513.0;
1262                         failed = false;
1263                         checked {
1264                                 a = (long)d;
1265                         }
1266                 } catch (OverflowException) {
1267                         failed = true;
1268                 }
1269                 if (failed)
1270                         return 2;
1271                 
1272                 try {
1273                         double d = System.Int64.MinValue - 1024.0;
1274                         failed = false;                 
1275                         checked {
1276                                 a = (long)d;
1277                         }
1278                 } catch (OverflowException) {
1279                         failed = true;
1280                 }
1281                 if (failed)
1282                         return 3;
1283
1284                 try {
1285                         double d = System.Int64.MinValue - 1025.0;
1286                         failed = true;
1287                         checked {
1288                                 a = (long)d;
1289                         }
1290                 } catch (OverflowException) {
1291                         failed = false;
1292                 }
1293                 if (failed)
1294                         return 4;
1295
1296                 {
1297                         long i; 
1298                         float f = 1.1f;
1299                         checked {
1300                                 i = (long) f;
1301                         }
1302                 }
1303
1304                 return 0;
1305         }
1306
1307         public static int test_0_ulong_cast () {
1308                 ulong a;
1309                 bool failed;
1310
1311                 /*
1312                  * These tests depend on properties of x86 fp arithmetic so they won't work
1313                  * on other platforms.
1314                  */
1315
1316                 /*
1317                 try {
1318                         double d = System.UInt64.MaxValue - 1024.0;
1319                         failed = true;
1320                         checked {
1321                                 a = (ulong)d;
1322                         }
1323                 } catch (OverflowException) {
1324                         failed = false;
1325                 }
1326                 if (failed)
1327                         return 1;
1328
1329                 try {
1330                         double d = System.UInt64.MaxValue - 1025.0;
1331                         failed = false;
1332                         checked {
1333                                 a = (ulong)d;
1334                         }
1335                 } catch (OverflowException) {
1336                         failed = true;
1337                 }
1338                 if (failed)
1339                         return 2;
1340                 */      
1341
1342                 try {
1343                         double d = 0;
1344                         failed = false;                 
1345                         checked {
1346                                 a = (ulong)d;
1347                         }
1348                 } catch (OverflowException) {
1349                         failed = true;
1350                 }
1351                 if (failed)
1352                         return 3;
1353
1354                 try {
1355                         double d = -1;
1356                         failed = true;
1357                         checked {
1358                                 a = (ulong)d;
1359                         }
1360                 } catch (OverflowException) {
1361                         failed = false;
1362                 }
1363                 if (failed)
1364                         return 4;
1365
1366                 {
1367                         ulong i; 
1368                         float f = 1.1f;
1369                         checked {
1370                                 i = (ulong) f;
1371                         }
1372                 }
1373
1374                 try {
1375                         int i = -1;
1376                         failed = true;
1377                         checked {
1378                                 a = (ulong)i;
1379                         }
1380                 }
1381                 catch (OverflowException) {
1382                         failed = false;
1383                 }
1384                 if (failed)
1385                         return 5;
1386
1387                 try {
1388                         int i = Int32.MinValue;
1389                         failed = true;
1390                         checked {
1391                                 a = (ulong)i;
1392                         }
1393                 }
1394                 catch (OverflowException) {
1395                         failed = false;
1396                 }
1397                 if (failed)
1398                         return 6;
1399
1400                 return 0;
1401         }
1402
1403         public static int test_0_simple_double_casts () {
1404
1405                 double d = 0xffffffff;
1406
1407                 if ((uint)d != 4294967295)
1408                         return 1;
1409
1410                 /*
1411                  * These tests depend on properties of x86 fp arithmetic so they won't work
1412                  * on other platforms.
1413                  */
1414                 /*
1415                 d = 0xffffffffffffffff;
1416
1417                 if ((ulong)d != 0)
1418                         return 2;
1419
1420                 if ((ushort)d != 0)
1421                         return 3;
1422                         
1423                 if ((byte)d != 0)
1424                         return 4;
1425                 */
1426                         
1427                 d = 0xffff;
1428
1429                 if ((ushort)d != 0xffff)
1430                         return 5;
1431                 
1432                 if ((byte)d != 0xff)
1433                         return 6;
1434                         
1435                 return 0;
1436         }
1437         
1438         public static int test_0_div_zero () {
1439                 int d = 1;
1440                 int q = 0;
1441                 int val;
1442                 bool failed;
1443
1444                 try {
1445                         failed = true;
1446                         val = d / q;
1447                 } catch (DivideByZeroException) {
1448                         failed = false;
1449                 }
1450                 if (failed)
1451                         return 1;
1452
1453                 try {
1454                         failed = true;
1455                         val = d % q;
1456                 } catch (DivideByZeroException) {
1457                         failed = false;
1458                 }
1459                 if (failed)
1460                         return 2;
1461
1462                 try {
1463                         failed = true;
1464                         q = -1;
1465                         d = Int32.MinValue;
1466                         val = d / q;
1467                 } catch (DivideByZeroException) {
1468                         /* wrong exception */
1469                 } catch (ArithmeticException) {
1470                         failed = false;
1471                 }
1472                 if (failed)
1473                         return 3;
1474
1475                 try {
1476                         failed = true;
1477                         q = -1;
1478                         d = Int32.MinValue;
1479                         val = d % q;
1480                 } catch (DivideByZeroException) {
1481                         /* wrong exception */
1482                 } catch (ArithmeticException) {
1483                         failed = false;
1484                 }
1485                 if (failed)
1486                         return 4;
1487
1488                 return 0;
1489         }
1490
1491         public static int return_55 () {
1492                 return 55;
1493         }
1494
1495         public static int test_0_cfold_div_zero () {
1496                 // Test that constant folding doesn't cause division by zero exceptions
1497                 if (return_55 () != return_55 ()) {
1498                         int d = 1;
1499                         int q = 0;
1500                         int val;                        
1501
1502                         val = d / q;
1503                         val = d % q;
1504
1505                         q = -1;
1506                         d = Int32.MinValue;
1507                         val = d / q;
1508
1509                         q = -1;
1510                         val = d % q;
1511                 }
1512
1513                 return 0;
1514         }
1515
1516         public static int test_0_udiv_zero () {
1517                 uint d = 1;
1518                 uint q = 0;
1519                 uint val;
1520                 bool failed;
1521
1522                 try {
1523                         failed = true;
1524                         val = d / q;
1525                 } catch (DivideByZeroException) {
1526                         failed = false;
1527                 }
1528                 if (failed)
1529                         return 1;
1530
1531                 try {
1532                         failed = true;
1533                         val = d % q;
1534                 } catch (DivideByZeroException) {
1535                         failed = false;
1536                 }
1537                 if (failed)
1538                         return 2;
1539
1540                 return 0;
1541         }
1542
1543         public static int test_0_long_div_zero () {
1544                 long d = 1;
1545                 long q = 0;
1546                 long val;
1547                 bool failed;
1548
1549                 try {
1550                         failed = true;
1551                         val = d / q;
1552                 } catch (DivideByZeroException) {
1553                         failed = false;
1554                 }
1555                 if (failed)
1556                         return 1;
1557
1558                 try {
1559                         failed = true;
1560                         val = d % q;
1561                 } catch (DivideByZeroException) {
1562                         failed = false;
1563                 }
1564                 if (failed)
1565                         return 2;
1566
1567                 try {
1568                         failed = true;
1569                         q = -1;
1570                         d = Int64.MinValue;
1571                         val = d / q;
1572                 } catch (DivideByZeroException) {
1573                         /* wrong exception */
1574                 } catch (ArithmeticException) {
1575                         failed = false;
1576                 }
1577                 if (failed)
1578                         return 3;
1579
1580                 try {
1581                         failed = true;
1582                         q = -1;
1583                         d = Int64.MinValue;
1584                         val = d % q;
1585                 } catch (DivideByZeroException) {
1586                         /* wrong exception */
1587                 } catch (ArithmeticException) {
1588                         failed = false;
1589                 }
1590                 if (failed)
1591                         return 4;
1592
1593                 return 0;
1594         }
1595
1596         public static int test_0_ulong_div_zero () {
1597                 ulong d = 1;
1598                 ulong q = 0;
1599                 ulong val;
1600                 bool failed;
1601
1602                 try {
1603                         failed = true;
1604                         val = d / q;
1605                 } catch (DivideByZeroException) {
1606                         failed = false;
1607                 }
1608                 if (failed)
1609                         return 1;
1610
1611                 try {
1612                         failed = true;
1613                         val = d % q;
1614                 } catch (DivideByZeroException) {
1615                         failed = false;
1616                 }
1617                 if (failed)
1618                         return 2;
1619
1620                 return 0;
1621         }
1622
1623         public static int test_0_float_div_zero () {
1624                 double d = 1;
1625                 double q = 0;
1626                 double val;
1627                 bool failed;
1628
1629                 try {
1630                         failed = false;
1631                         val = d / q;
1632                 } catch (DivideByZeroException) {
1633                         failed = true;
1634                 }
1635                 if (failed)
1636                         return 1;
1637
1638                 try {
1639                         failed = false;
1640                         val = d % q;
1641                 } catch (DivideByZeroException) {
1642                         failed = true;
1643                 }
1644                 if (failed)
1645                         return 2;
1646
1647                 return 0;
1648         }
1649
1650         public static int test_0_invalid_unbox () {
1651
1652                 int i = 123;
1653                 object o = "Some string";
1654                 int res = 1;
1655                 
1656                 try {
1657                         // Illegal conversion; o contains a string not an int
1658                         i = (int) o;   
1659                 } catch (Exception e) {
1660                         if (i ==123)
1661                                 res = 0;
1662                 }
1663
1664                 return res;
1665         }
1666
1667         // Test that double[] can't be cast to double (bug #46027)
1668         public static int test_0_invalid_unbox_arrays () {
1669                 double[] d1 = { 1.0 };
1670                 double[][] d2 = { d1 };
1671                 Array a = d2;
1672
1673                 try {
1674                         foreach (double d in a) {
1675                         }
1676                         return 1;
1677                 }
1678                 catch (InvalidCastException e) {
1679                         return 0;
1680                 }
1681         }
1682
1683         /* bug# 42190, at least mcs generates a leave for the return that
1684          * jumps out of multiple exception clauses: we used to execute just 
1685          * one enclosing finally block.
1686          */
1687         public static int finally_level;
1688         static void do_something () {
1689                 int a = 0;
1690                 try {
1691                         try {
1692                                 return;
1693                         } finally {
1694                                 a = 1;
1695                         }
1696                 } finally {
1697                         finally_level++;
1698                 }
1699         }
1700
1701         public static int test_2_multiple_finally_clauses () {
1702                 finally_level = 0;
1703                 do_something ();
1704                 if (finally_level == 1)
1705                         return 2;
1706                 return 0;
1707         }
1708
1709         public static int test_3_checked_cast_un () {
1710                 ulong i = 0x8000000034000000;
1711                 long j;
1712
1713                 try {
1714                         checked { j = (long)i; }
1715                 } catch (OverflowException) {
1716                         j = 2;
1717                 }
1718
1719                 if (j != 2)
1720                         return 0;
1721                 return 3;
1722         }
1723         
1724         public static int test_4_checked_cast () {
1725                 long i;
1726                 ulong j;
1727
1728                 unchecked { i = (long)0x8000000034000000;};
1729                 try {
1730                         checked { j = (ulong)i; }
1731                 } catch (OverflowException) {
1732                         j = 3;
1733                 }
1734
1735                 if (j != 3)
1736                         return 0;
1737                 return 4;
1738         }
1739
1740         static readonly int[] mul_dim_results = new int[] {
1741                 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1742                 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1743                 2, 0, 2, 1, 2, 8, 
1744                 3, 0, 3, 1, 3, 8, 
1745                 4, 0, 4, 1, 4, 8, 
1746                 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1747                 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1748                 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1749         };
1750
1751         public static int test_0_multi_dim_array_access () {
1752                 int [,] a = System.Array.CreateInstance (typeof (int),
1753                         new int [] {3,6}, new int [] {2,2 }) as int[,];
1754                 int x, y;
1755                 int result_idx = 0;
1756                 for (x = 0; x < 8; ++x) {
1757                         for (y = 0; y < 9; ++y) {
1758                                 bool got_ex = false;
1759                                 try {
1760                                         a [x, y] = 1;
1761                                 } catch {
1762                                         got_ex = true;
1763                                 }
1764                                 if (got_ex) {
1765                                         if (result_idx >= mul_dim_results.Length)
1766                                                 return -1;
1767                                         if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1768                                                 return result_idx + 1;
1769                                         }
1770                                         result_idx += 2;
1771                                 }
1772                         }
1773                 }
1774                 if (result_idx == mul_dim_results.Length)
1775                         return 0;
1776                 return 200;
1777         }
1778
1779         static void helper_out_obj (out object o) {
1780                 o = (object)"buddy";
1781         }
1782
1783         static void helper_out_string (out string o) {
1784                 o = "buddy";
1785         }
1786
1787         public static int test_2_array_mismatch () {
1788                 string[] a = { "hello", "world" };
1789                 object[] b = a;
1790                 bool passed = false;
1791
1792                 try {
1793                         helper_out_obj (out b [1]);
1794                 } catch (ArrayTypeMismatchException) {
1795                         passed = true;
1796                 }
1797                 if (!passed)
1798                         return 0;
1799                 helper_out_string (out a [1]);
1800                 if (a [1] != "buddy")
1801                         return 1;
1802                 return 2;
1803         }
1804
1805         public static int test_0_ovf () {
1806                 int ocount = 0;
1807                 
1808                 checked {
1809
1810                         ocount = 0;
1811                         try {
1812                                 ulong a =  UInt64.MaxValue - 1;
1813                                 ulong t = a++;
1814                         } catch {
1815                                 ocount++;
1816                         }
1817                         if (ocount != 0)
1818                                 return 1;
1819
1820                         ocount = 0;
1821                         try {
1822                                 ulong a =  UInt64.MaxValue;
1823                                 ulong t = a++;
1824                         } catch {
1825                                 ocount++;
1826                         }
1827                         if (ocount != 1)
1828                                 return 2;
1829
1830                         ocount = 0;
1831                         try {
1832                                 long a = Int64.MaxValue - 1;
1833                                 long t = a++;
1834                         } catch {
1835                                 ocount++;
1836                         }
1837                         if (ocount != 0)
1838                                 return 3;
1839
1840                         try {
1841                                 long a = Int64.MaxValue;
1842                                 long t = a++;
1843                         } catch {
1844                                 ocount++;
1845                         }
1846                         if (ocount != 1)
1847                                 return 4;
1848
1849                         ocount = 0;
1850                         try {
1851                                 ulong a = UInt64.MaxValue - 1;
1852                                 ulong t = a++;
1853                         } catch {
1854                                 ocount++;
1855                         }
1856                         if (ocount != 0)
1857                                 return 5;
1858
1859                         try {
1860                                 ulong a = UInt64.MaxValue;
1861                                 ulong t = a++;
1862                         } catch {
1863                                 ocount++;
1864                         }
1865                         if (ocount != 1)
1866                                 return 6;
1867
1868                         ocount = 0;
1869                         try {
1870                                 long a = Int64.MinValue + 1;
1871                                 long t = a--;
1872                         } catch {
1873                                 ocount++;
1874                         }
1875                         if (ocount != 0)
1876                                 return 7;
1877
1878                         ocount = 0;
1879                         try {
1880                                 long a = Int64.MinValue;
1881                                 long t = a--;
1882                         } catch {
1883                                 ocount++;
1884                         }
1885                         if (ocount != 1)
1886                                 return 8;
1887
1888                         ocount = 0;
1889                         try {
1890                                 ulong a = UInt64.MinValue + 1;
1891                                 ulong t = a--;
1892                         } catch {
1893                                 ocount++;
1894                         }
1895                         if (ocount != 0)
1896                                 return 9;
1897
1898                         ocount = 0;
1899                         try {
1900                                 ulong a = UInt64.MinValue;
1901                                 ulong t = a--;
1902                         } catch {
1903                                 ocount++;
1904                         }
1905                         if (ocount != 1)
1906                                 return 10;
1907
1908                         ocount = 0;
1909                         try {
1910                                 int a = Int32.MinValue + 1;
1911                                 int t = a--;
1912                         } catch {
1913                                 ocount++;
1914                         }
1915                         if (ocount != 0)
1916                                 return 11;
1917
1918                         ocount = 0;
1919                         try {
1920                                 int a = Int32.MinValue;
1921                                 int t = a--;
1922                         } catch {
1923                                 ocount++;
1924                         }
1925                         if (ocount != 1)
1926                                 return 12;
1927
1928                         ocount = 0;
1929                         try {
1930                                 uint a = 1;
1931                                 uint t = a--;
1932                         } catch {
1933                                 ocount++;
1934                         }
1935                         if (ocount != 0)
1936                                 return 13;
1937
1938                         ocount = 0;
1939                         try {
1940                                 uint a = 0;
1941                                 uint t = a--;
1942                         } catch {
1943                                 ocount++;
1944                         }
1945                         if (ocount != 1)
1946                                 return 14;
1947
1948                         ocount = 0;
1949                         try {
1950                                 sbyte a = 126;
1951                                 sbyte t = a++;
1952                         } catch {
1953                                 ocount++;
1954                         }
1955                         if (ocount != 0)
1956                                 return 15;
1957
1958                         ocount = 0;
1959                         try {
1960                                 sbyte a = 127;
1961                                 sbyte t = a++;
1962                         } catch {
1963                                 ocount++;
1964                         }
1965                         if (ocount != 1)
1966                                 return 16;
1967
1968                         ocount = 0;
1969                         try {
1970                         } catch {
1971                                 ocount++;
1972                         }
1973                         if (ocount != 0)
1974                                 return 17;
1975
1976                         ocount = 0;
1977                         try {
1978                                 int a = 1 << 29;
1979                                 int t = a*2;
1980                         } catch {
1981                                 ocount++;
1982                         }
1983                         if (ocount != 0)
1984                                 return 18;
1985
1986                         ocount = 0;
1987                         try {
1988                                 int a = 1 << 30;
1989                                 int t = a*2;
1990                         } catch {
1991                                 ocount++;
1992                         }
1993                         if (ocount != 1)
1994                                 return 19;
1995
1996                         ocount = 0;
1997                         try {
1998                                 ulong a = 0xffffffffff;
1999                                 ulong t = a*0x0ffffff;
2000                         } catch {
2001                                 ocount++;
2002                         }
2003                         if (ocount != 0)
2004                                 return 20;
2005
2006                         ocount = 0;
2007                         try {
2008                                 ulong a = 0xffffffffff;
2009                                 ulong t = a*0x0fffffff;
2010                         } catch {
2011                                 ocount++;
2012                         }
2013                         if (ocount != 1)
2014                                 return 21;
2015
2016                         ocount = 0;
2017                         try {
2018                                 long a = Int64.MinValue;
2019                                 long b = 10;
2020                                 long v = a * b;
2021                         } catch {
2022                                 ocount ++;
2023                         }
2024                         if (ocount != 1)
2025                                 return 22;
2026
2027                         ocount = 0;
2028                         try {
2029                                 long a = 10;
2030                                 long b = Int64.MinValue;
2031                                 long v = a * b;
2032                         } catch {
2033                                 ocount ++;
2034                         }
2035                         if (ocount != 1)
2036                                 return 23;
2037                 }
2038                 
2039                 return 0;
2040         }
2041
2042         class Broken {
2043                 public static int i;
2044
2045                 static Broken () {
2046                         throw new Exception ("Ugh!");
2047                 }
2048         
2049                 public static int DoSomething () {
2050                         return i;
2051                 }
2052         }
2053
2054         public static int test_0_exception_in_cctor () {
2055                 try {
2056                         Broken.DoSomething ();
2057                 }
2058                 catch (TypeInitializationException) {
2059                         // This will only happen once even if --regression is used
2060                 }
2061                 return 0;
2062         }
2063
2064         public static int test_5_regalloc () {
2065                 int i = 0;
2066
2067                 try {
2068                         for (i = 0; i < 10; ++i) {
2069                                 if (i == 5)
2070                                         throw new Exception ();
2071                         }
2072                 }
2073                 catch (Exception) {
2074                         if (i != 5)
2075                                 return i;
2076                 }
2077
2078                 // Check that variables written in catch clauses are volatile
2079                 int j = 0;
2080                 try {
2081                         throw new Exception ();
2082                 }
2083                 catch (Exception) {
2084                         j = 5;
2085                 }
2086                 if (j != 5)
2087                         return 6;
2088
2089                 int k = 0;
2090                 try {
2091                         try {
2092                                 throw new Exception ();
2093                         }
2094                         finally {
2095                                 k = 5;
2096                         }
2097                 }
2098                 catch (Exception) {
2099                 }
2100                 if (k != 5)
2101                         return 7;
2102
2103                 return i;
2104         }
2105
2106         /* MarshalByRefObject prevents the methods from being inlined */
2107         class ThrowClass : MarshalByRefObject {
2108                 public static void rethrow1 () {
2109                         throw new Exception ();
2110                 }
2111
2112                 public static void rethrow2 () {
2113                         rethrow1 ();
2114                 }
2115         }
2116
2117         public static int test_0_rethrow_stacktrace () {
2118                 // Check that rethrowing an exception preserves the original stack trace
2119                 try {
2120                         try {
2121                                 ThrowClass.rethrow2 ();
2122                         }
2123                         catch (Exception ex) {
2124                                 // Check that each catch clause has its own exception variable
2125                                 // If not, the throw below will overwrite the exception used
2126                                 // by the rethrow
2127                                 try {
2128                                         throw new DivideByZeroException ();
2129                                 }
2130                                 catch (Exception foo) {
2131                                 }
2132
2133                                 throw;
2134                         }
2135                 }
2136                 catch (Exception ex) {
2137                         if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2138                                 return 0;
2139                 }
2140
2141                 return 1;
2142         }
2143         
2144         interface IFace {}
2145         class Face : IFace {}
2146                 
2147         public static int test_1_array_mismatch_2 () {
2148                 try {
2149                         object [] o = new Face [1];
2150                         o [0] = 1;
2151                         return 0;
2152                 } catch (ArrayTypeMismatchException) {
2153                         return 1;
2154                 }
2155         }
2156         
2157         public static int test_1_array_mismatch_3 () {
2158                 try {
2159                         object [] o = new IFace [1];
2160                         o [0] = 1;
2161                         return 0;
2162                 } catch (ArrayTypeMismatchException) {
2163                         return 1;
2164                 }
2165         }
2166         
2167         public static int test_1_array_mismatch_4 () {
2168                 try {
2169                         object [][] o = new Face [5] [];
2170                         o [0] = new object [5];
2171                         
2172                         return 0;
2173                 } catch (ArrayTypeMismatchException) {
2174                         return 1;
2175                 }
2176         }
2177
2178         public static int test_0_array_size () {
2179                 bool failed;
2180
2181                 try {
2182                         failed = true;
2183                         int[] mem1 = new int [Int32.MaxValue];
2184                 }
2185                 catch (OutOfMemoryException e) {
2186                         failed = false;
2187                 }
2188                 if (failed)
2189                         return 1;
2190
2191                 try {
2192                         failed = true;
2193                         int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2194                 }
2195                 catch (OutOfMemoryException e) {
2196                         failed = false;
2197                 }
2198                 if (failed)
2199                         return 2;
2200
2201                 return 0;
2202         }
2203
2204         struct S {
2205                 int i, j, k, l, m, n;
2206         }
2207
2208         static IntPtr[] addr;
2209
2210         static unsafe void throw_func (int i, S s) {
2211                 addr [i] = new IntPtr (&i);
2212                 throw new Exception ();
2213         }
2214
2215         /* Test that arguments are correctly popped off the stack during unwinding */
2216         public static int test_0_stack_unwind () {
2217                 addr = new IntPtr [1000];
2218                 S s = new S ();
2219                 for (int j = 0; j < 1000; j++) {
2220                         try {
2221                                 throw_func (j, s);
2222                         }
2223                         catch (Exception) {
2224                         }
2225                 }
2226                 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
2227         }
2228
2229         public static int test_0_regress_73242 () {
2230                 int [] arr = new int [10];
2231                 for (int i = 0; i < 10; ++i)
2232                         arr [i] = 0;
2233                 try {
2234                         throw new Exception ();
2235                 }
2236                 catch {
2237                 }
2238                 return 0;
2239     }
2240
2241         public static int test_0_nullref () {
2242                 try {
2243                         Array foo = null;
2244                         foo.Clone();
2245                 } catch (NullReferenceException e) {
2246                         return 0;
2247                 }
2248                 return 1;
2249         }
2250 }
2251