Add this for backwards compatibility
[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
1246                 /*
1247                  * These tests depend on properties of x86 fp arithmetic so they won't work
1248                  * on other platforms.
1249                  */
1250                 /*
1251                 long a;
1252                 bool failed;
1253
1254                 try {
1255                         double d = System.Int64.MaxValue - 512.0;
1256                         failed = true;
1257                         checked {
1258                                 a = (long)d;
1259                         }
1260                 } catch (OverflowException) {
1261                         failed = false;
1262                 }
1263                 if (failed)
1264                         return 1;
1265
1266                 try {
1267                         double d = System.Int64.MaxValue - 513.0;
1268                         failed = false;
1269                         checked {
1270                                 a = (long)d;
1271                         }
1272                 } catch (OverflowException) {
1273                         failed = true;
1274                 }
1275                 if (failed)
1276                         return 2;
1277                 
1278                 try {
1279                         double d = System.Int64.MinValue - 1024.0;
1280                         failed = false;                 
1281                         checked {
1282                                 a = (long)d;
1283                         }
1284                 } catch (OverflowException) {
1285                         failed = true;
1286                 }
1287                 if (failed)
1288                         return 3;
1289
1290                 try {
1291                         double d = System.Int64.MinValue - 1025.0;
1292                         failed = true;
1293                         checked {
1294                                 a = (long)d;
1295                         }
1296                 } catch (OverflowException) {
1297                         failed = false;
1298                 }
1299                 if (failed)
1300                         return 4;
1301                 */
1302
1303                 {
1304                         long i; 
1305                         float f = 1.1f;
1306                         checked {
1307                                 i = (long) f;
1308                         }
1309                 }
1310
1311                 return 0;
1312         }
1313
1314         public static int test_0_ulong_cast () {
1315                 ulong a;
1316                 bool failed;
1317
1318                 /*
1319                  * These tests depend on properties of x86 fp arithmetic so they won't work
1320                  * on other platforms.
1321                  */
1322
1323                 /*
1324                 try {
1325                         double d = System.UInt64.MaxValue - 1024.0;
1326                         failed = true;
1327                         checked {
1328                                 a = (ulong)d;
1329                         }
1330                 } catch (OverflowException) {
1331                         failed = false;
1332                 }
1333                 if (failed)
1334                         return 1;
1335
1336                 try {
1337                         double d = System.UInt64.MaxValue - 1025.0;
1338                         failed = false;
1339                         checked {
1340                                 a = (ulong)d;
1341                         }
1342                 } catch (OverflowException) {
1343                         failed = true;
1344                 }
1345                 if (failed)
1346                         return 2;
1347                 */      
1348
1349                 try {
1350                         double d = 0;
1351                         failed = false;                 
1352                         checked {
1353                                 a = (ulong)d;
1354                         }
1355                 } catch (OverflowException) {
1356                         failed = true;
1357                 }
1358                 if (failed)
1359                         return 3;
1360
1361                 try {
1362                         double d = -1;
1363                         failed = true;
1364                         checked {
1365                                 a = (ulong)d;
1366                         }
1367                 } catch (OverflowException) {
1368                         failed = false;
1369                 }
1370                 if (failed)
1371                         return 4;
1372
1373                 {
1374                         ulong i; 
1375                         float f = 1.1f;
1376                         checked {
1377                                 i = (ulong) f;
1378                         }
1379                 }
1380
1381                 try {
1382                         int i = -1;
1383                         failed = true;
1384                         checked {
1385                                 a = (ulong)i;
1386                         }
1387                 }
1388                 catch (OverflowException) {
1389                         failed = false;
1390                 }
1391                 if (failed)
1392                         return 5;
1393
1394                 try {
1395                         int i = Int32.MinValue;
1396                         failed = true;
1397                         checked {
1398                                 a = (ulong)i;
1399                         }
1400                 }
1401                 catch (OverflowException) {
1402                         failed = false;
1403                 }
1404                 if (failed)
1405                         return 6;
1406
1407                 return 0;
1408         }
1409
1410         public static int test_0_simple_double_casts () {
1411
1412                 double d = 0xffffffff;
1413
1414                 if ((uint)d != 4294967295)
1415                         return 1;
1416
1417                 /*
1418                  * These tests depend on properties of x86 fp arithmetic so they won't work
1419                  * on other platforms.
1420                  */
1421                 /*
1422                 d = 0xffffffffffffffff;
1423
1424                 if ((ulong)d != 0)
1425                         return 2;
1426
1427                 if ((ushort)d != 0)
1428                         return 3;
1429                         
1430                 if ((byte)d != 0)
1431                         return 4;
1432                 */
1433                         
1434                 d = 0xffff;
1435
1436                 if ((ushort)d != 0xffff)
1437                         return 5;
1438                 
1439                 if ((byte)d != 0xff)
1440                         return 6;
1441                         
1442                 return 0;
1443         }
1444         
1445         public static int test_0_div_zero () {
1446                 int d = 1;
1447                 int q = 0;
1448                 int val;
1449                 bool failed;
1450
1451                 try {
1452                         failed = true;
1453                         val = d / q;
1454                 } catch (DivideByZeroException) {
1455                         failed = false;
1456                 }
1457                 if (failed)
1458                         return 1;
1459
1460                 try {
1461                         failed = true;
1462                         val = d % q;
1463                 } catch (DivideByZeroException) {
1464                         failed = false;
1465                 }
1466                 if (failed)
1467                         return 2;
1468
1469                 try {
1470                         failed = true;
1471                         q = -1;
1472                         d = Int32.MinValue;
1473                         val = d / q;
1474                 } catch (DivideByZeroException) {
1475                         /* wrong exception */
1476                 } catch (ArithmeticException) {
1477                         failed = false;
1478                 }
1479                 if (failed)
1480                         return 3;
1481
1482                 try {
1483                         failed = true;
1484                         q = -1;
1485                         d = Int32.MinValue;
1486                         val = d % q;
1487                 } catch (DivideByZeroException) {
1488                         /* wrong exception */
1489                 } catch (ArithmeticException) {
1490                         failed = false;
1491                 }
1492                 if (failed)
1493                         return 4;
1494
1495                 return 0;
1496         }
1497
1498         public static int return_55 () {
1499                 return 55;
1500         }
1501
1502         public static int test_0_cfold_div_zero () {
1503                 // Test that constant folding doesn't cause division by zero exceptions
1504                 if (return_55 () != return_55 ()) {
1505                         int d = 1;
1506                         int q = 0;
1507                         int val;                        
1508
1509                         val = d / q;
1510                         val = d % q;
1511
1512                         q = -1;
1513                         d = Int32.MinValue;
1514                         val = d / q;
1515
1516                         q = -1;
1517                         val = d % q;
1518                 }
1519
1520                 return 0;
1521         }
1522
1523         public static int test_0_udiv_zero () {
1524                 uint d = 1;
1525                 uint q = 0;
1526                 uint val;
1527                 bool failed;
1528
1529                 try {
1530                         failed = true;
1531                         val = d / q;
1532                 } catch (DivideByZeroException) {
1533                         failed = false;
1534                 }
1535                 if (failed)
1536                         return 1;
1537
1538                 try {
1539                         failed = true;
1540                         val = d % q;
1541                 } catch (DivideByZeroException) {
1542                         failed = false;
1543                 }
1544                 if (failed)
1545                         return 2;
1546
1547                 return 0;
1548         }
1549
1550         public static int test_0_long_div_zero () {
1551                 long d = 1;
1552                 long q = 0;
1553                 long val;
1554                 bool failed;
1555
1556                 try {
1557                         failed = true;
1558                         val = d / q;
1559                 } catch (DivideByZeroException) {
1560                         failed = false;
1561                 }
1562                 if (failed)
1563                         return 1;
1564
1565                 try {
1566                         failed = true;
1567                         val = d % q;
1568                 } catch (DivideByZeroException) {
1569                         failed = false;
1570                 }
1571                 if (failed)
1572                         return 2;
1573
1574                 try {
1575                         failed = true;
1576                         q = -1;
1577                         d = Int64.MinValue;
1578                         val = d / q;
1579                 } catch (DivideByZeroException) {
1580                         /* wrong exception */
1581                 } catch (ArithmeticException) {
1582                         failed = false;
1583                 }
1584                 if (failed)
1585                         return 3;
1586
1587                 try {
1588                         failed = true;
1589                         q = -1;
1590                         d = Int64.MinValue;
1591                         val = d % q;
1592                 } catch (DivideByZeroException) {
1593                         /* wrong exception */
1594                 } catch (ArithmeticException) {
1595                         failed = false;
1596                 }
1597                 if (failed)
1598                         return 4;
1599
1600                 return 0;
1601         }
1602
1603         public static int test_0_ulong_div_zero () {
1604                 ulong d = 1;
1605                 ulong q = 0;
1606                 ulong val;
1607                 bool failed;
1608
1609                 try {
1610                         failed = true;
1611                         val = d / q;
1612                 } catch (DivideByZeroException) {
1613                         failed = false;
1614                 }
1615                 if (failed)
1616                         return 1;
1617
1618                 try {
1619                         failed = true;
1620                         val = d % q;
1621                 } catch (DivideByZeroException) {
1622                         failed = false;
1623                 }
1624                 if (failed)
1625                         return 2;
1626
1627                 return 0;
1628         }
1629
1630         public static int test_0_float_div_zero () {
1631                 double d = 1;
1632                 double q = 0;
1633                 double val;
1634                 bool failed;
1635
1636                 try {
1637                         failed = false;
1638                         val = d / q;
1639                 } catch (DivideByZeroException) {
1640                         failed = true;
1641                 }
1642                 if (failed)
1643                         return 1;
1644
1645                 try {
1646                         failed = false;
1647                         val = d % q;
1648                 } catch (DivideByZeroException) {
1649                         failed = true;
1650                 }
1651                 if (failed)
1652                         return 2;
1653
1654                 return 0;
1655         }
1656
1657         public static int test_0_invalid_unbox () {
1658
1659                 int i = 123;
1660                 object o = "Some string";
1661                 int res = 1;
1662                 
1663                 try {
1664                         // Illegal conversion; o contains a string not an int
1665                         i = (int) o;   
1666                 } catch (Exception e) {
1667                         if (i ==123)
1668                                 res = 0;
1669                 }
1670
1671                 return res;
1672         }
1673
1674         // Test that double[] can't be cast to double (bug #46027)
1675         public static int test_0_invalid_unbox_arrays () {
1676                 double[] d1 = { 1.0 };
1677                 double[][] d2 = { d1 };
1678                 Array a = d2;
1679
1680                 try {
1681                         foreach (double d in a) {
1682                         }
1683                         return 1;
1684                 }
1685                 catch (InvalidCastException e) {
1686                         return 0;
1687                 }
1688         }
1689
1690         /* bug# 42190, at least mcs generates a leave for the return that
1691          * jumps out of multiple exception clauses: we used to execute just 
1692          * one enclosing finally block.
1693          */
1694         public static int finally_level;
1695         static void do_something () {
1696                 int a = 0;
1697                 try {
1698                         try {
1699                                 return;
1700                         } finally {
1701                                 a = 1;
1702                         }
1703                 } finally {
1704                         finally_level++;
1705                 }
1706         }
1707
1708         public static int test_2_multiple_finally_clauses () {
1709                 finally_level = 0;
1710                 do_something ();
1711                 if (finally_level == 1)
1712                         return 2;
1713                 return 0;
1714         }
1715
1716         public static int test_3_checked_cast_un () {
1717                 ulong i = 0x8000000034000000;
1718                 long j;
1719
1720                 try {
1721                         checked { j = (long)i; }
1722                 } catch (OverflowException) {
1723                         j = 2;
1724                 }
1725
1726                 if (j != 2)
1727                         return 0;
1728                 return 3;
1729         }
1730         
1731         public static int test_4_checked_cast () {
1732                 long i;
1733                 ulong j;
1734
1735                 unchecked { i = (long)0x8000000034000000;};
1736                 try {
1737                         checked { j = (ulong)i; }
1738                 } catch (OverflowException) {
1739                         j = 3;
1740                 }
1741
1742                 if (j != 3)
1743                         return 0;
1744                 return 4;
1745         }
1746
1747         static readonly int[] mul_dim_results = new int[] {
1748                 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1749                 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1750                 2, 0, 2, 1, 2, 8, 
1751                 3, 0, 3, 1, 3, 8, 
1752                 4, 0, 4, 1, 4, 8, 
1753                 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1754                 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1755                 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1756         };
1757
1758         public static int test_0_multi_dim_array_access () {
1759                 int [,] a = System.Array.CreateInstance (typeof (int),
1760                         new int [] {3,6}, new int [] {2,2 }) as int[,];
1761                 int x, y;
1762                 int result_idx = 0;
1763                 for (x = 0; x < 8; ++x) {
1764                         for (y = 0; y < 9; ++y) {
1765                                 bool got_ex = false;
1766                                 try {
1767                                         a [x, y] = 1;
1768                                 } catch {
1769                                         got_ex = true;
1770                                 }
1771                                 if (got_ex) {
1772                                         if (result_idx >= mul_dim_results.Length)
1773                                                 return -1;
1774                                         if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1775                                                 return result_idx + 1;
1776                                         }
1777                                         result_idx += 2;
1778                                 }
1779                         }
1780                 }
1781                 if (result_idx == mul_dim_results.Length)
1782                         return 0;
1783                 return 200;
1784         }
1785
1786         static void helper_out_obj (out object o) {
1787                 o = (object)"buddy";
1788         }
1789
1790         static void helper_out_string (out string o) {
1791                 o = "buddy";
1792         }
1793
1794         public static int test_2_array_mismatch () {
1795                 string[] a = { "hello", "world" };
1796                 object[] b = a;
1797                 bool passed = false;
1798
1799                 try {
1800                         helper_out_obj (out b [1]);
1801                 } catch (ArrayTypeMismatchException) {
1802                         passed = true;
1803                 }
1804                 if (!passed)
1805                         return 0;
1806                 helper_out_string (out a [1]);
1807                 if (a [1] != "buddy")
1808                         return 1;
1809                 return 2;
1810         }
1811
1812         public static int test_0_ovf () {
1813                 int ocount = 0;
1814                 
1815                 checked {
1816
1817                         ocount = 0;
1818                         try {
1819                                 ulong a =  UInt64.MaxValue - 1;
1820                                 ulong t = a++;
1821                         } catch {
1822                                 ocount++;
1823                         }
1824                         if (ocount != 0)
1825                                 return 1;
1826
1827                         ocount = 0;
1828                         try {
1829                                 ulong a =  UInt64.MaxValue;
1830                                 ulong t = a++;
1831                         } catch {
1832                                 ocount++;
1833                         }
1834                         if (ocount != 1)
1835                                 return 2;
1836
1837                         ocount = 0;
1838                         try {
1839                                 long a = Int64.MaxValue - 1;
1840                                 long t = a++;
1841                         } catch {
1842                                 ocount++;
1843                         }
1844                         if (ocount != 0)
1845                                 return 3;
1846
1847                         try {
1848                                 long a = Int64.MaxValue;
1849                                 long t = a++;
1850                         } catch {
1851                                 ocount++;
1852                         }
1853                         if (ocount != 1)
1854                                 return 4;
1855
1856                         ocount = 0;
1857                         try {
1858                                 ulong a = UInt64.MaxValue - 1;
1859                                 ulong t = a++;
1860                         } catch {
1861                                 ocount++;
1862                         }
1863                         if (ocount != 0)
1864                                 return 5;
1865
1866                         try {
1867                                 ulong a = UInt64.MaxValue;
1868                                 ulong t = a++;
1869                         } catch {
1870                                 ocount++;
1871                         }
1872                         if (ocount != 1)
1873                                 return 6;
1874
1875                         ocount = 0;
1876                         try {
1877                                 long a = Int64.MinValue + 1;
1878                                 long t = a--;
1879                         } catch {
1880                                 ocount++;
1881                         }
1882                         if (ocount != 0)
1883                                 return 7;
1884
1885                         ocount = 0;
1886                         try {
1887                                 long a = Int64.MinValue;
1888                                 long t = a--;
1889                         } catch {
1890                                 ocount++;
1891                         }
1892                         if (ocount != 1)
1893                                 return 8;
1894
1895                         ocount = 0;
1896                         try {
1897                                 ulong a = UInt64.MinValue + 1;
1898                                 ulong t = a--;
1899                         } catch {
1900                                 ocount++;
1901                         }
1902                         if (ocount != 0)
1903                                 return 9;
1904
1905                         ocount = 0;
1906                         try {
1907                                 ulong a = UInt64.MinValue;
1908                                 ulong t = a--;
1909                         } catch {
1910                                 ocount++;
1911                         }
1912                         if (ocount != 1)
1913                                 return 10;
1914
1915                         ocount = 0;
1916                         try {
1917                                 int a = Int32.MinValue + 1;
1918                                 int t = a--;
1919                         } catch {
1920                                 ocount++;
1921                         }
1922                         if (ocount != 0)
1923                                 return 11;
1924
1925                         ocount = 0;
1926                         try {
1927                                 int a = Int32.MinValue;
1928                                 int t = a--;
1929                         } catch {
1930                                 ocount++;
1931                         }
1932                         if (ocount != 1)
1933                                 return 12;
1934
1935                         ocount = 0;
1936                         try {
1937                                 uint a = 1;
1938                                 uint t = a--;
1939                         } catch {
1940                                 ocount++;
1941                         }
1942                         if (ocount != 0)
1943                                 return 13;
1944
1945                         ocount = 0;
1946                         try {
1947                                 uint a = 0;
1948                                 uint t = a--;
1949                         } catch {
1950                                 ocount++;
1951                         }
1952                         if (ocount != 1)
1953                                 return 14;
1954
1955                         ocount = 0;
1956                         try {
1957                                 sbyte a = 126;
1958                                 sbyte t = a++;
1959                         } catch {
1960                                 ocount++;
1961                         }
1962                         if (ocount != 0)
1963                                 return 15;
1964
1965                         ocount = 0;
1966                         try {
1967                                 sbyte a = 127;
1968                                 sbyte t = a++;
1969                         } catch {
1970                                 ocount++;
1971                         }
1972                         if (ocount != 1)
1973                                 return 16;
1974
1975                         ocount = 0;
1976                         try {
1977                         } catch {
1978                                 ocount++;
1979                         }
1980                         if (ocount != 0)
1981                                 return 17;
1982
1983                         ocount = 0;
1984                         try {
1985                                 int a = 1 << 29;
1986                                 int t = a*2;
1987                         } catch {
1988                                 ocount++;
1989                         }
1990                         if (ocount != 0)
1991                                 return 18;
1992
1993                         ocount = 0;
1994                         try {
1995                                 int a = 1 << 30;
1996                                 int t = a*2;
1997                         } catch {
1998                                 ocount++;
1999                         }
2000                         if (ocount != 1)
2001                                 return 19;
2002
2003                         ocount = 0;
2004                         try {
2005                                 ulong a = 0xffffffffff;
2006                                 ulong t = a*0x0ffffff;
2007                         } catch {
2008                                 ocount++;
2009                         }
2010                         if (ocount != 0)
2011                                 return 20;
2012
2013                         ocount = 0;
2014                         try {
2015                                 ulong a = 0xffffffffff;
2016                                 ulong t = a*0x0fffffff;
2017                         } catch {
2018                                 ocount++;
2019                         }
2020                         if (ocount != 1)
2021                                 return 21;
2022
2023                         ocount = 0;
2024                         try {
2025                                 long a = Int64.MinValue;
2026                                 long b = 10;
2027                                 long v = a * b;
2028                         } catch {
2029                                 ocount ++;
2030                         }
2031                         if (ocount != 1)
2032                                 return 22;
2033
2034                         ocount = 0;
2035                         try {
2036                                 long a = 10;
2037                                 long b = Int64.MinValue;
2038                                 long v = a * b;
2039                         } catch {
2040                                 ocount ++;
2041                         }
2042                         if (ocount != 1)
2043                                 return 23;
2044                 }
2045                 
2046                 return 0;
2047         }
2048
2049         class Broken {
2050                 public static int i;
2051
2052                 static Broken () {
2053                         throw new Exception ("Ugh!");
2054                 }
2055         
2056                 public static int DoSomething () {
2057                         return i;
2058                 }
2059         }
2060
2061         public static int test_0_exception_in_cctor () {
2062                 try {
2063                         Broken.DoSomething ();
2064                 }
2065                 catch (TypeInitializationException) {
2066                         // This will only happen once even if --regression is used
2067                 }
2068                 return 0;
2069         }
2070
2071         public static int test_5_regalloc () {
2072                 int i = 0;
2073
2074                 try {
2075                         for (i = 0; i < 10; ++i) {
2076                                 if (i == 5)
2077                                         throw new Exception ();
2078                         }
2079                 }
2080                 catch (Exception) {
2081                         if (i != 5)
2082                                 return i;
2083                 }
2084
2085                 // Check that variables written in catch clauses are volatile
2086                 int j = 0;
2087                 try {
2088                         throw new Exception ();
2089                 }
2090                 catch (Exception) {
2091                         j = 5;
2092                 }
2093                 if (j != 5)
2094                         return 6;
2095
2096                 int k = 0;
2097                 try {
2098                         try {
2099                                 throw new Exception ();
2100                         }
2101                         finally {
2102                                 k = 5;
2103                         }
2104                 }
2105                 catch (Exception) {
2106                 }
2107                 if (k != 5)
2108                         return 7;
2109
2110                 return i;
2111         }
2112
2113         /* MarshalByRefObject prevents the methods from being inlined */
2114         class ThrowClass : MarshalByRefObject {
2115                 public static void rethrow1 () {
2116                         throw new Exception ();
2117                 }
2118
2119                 public static void rethrow2 () {
2120                         rethrow1 ();
2121                 }
2122         }
2123
2124         public static int test_0_rethrow_stacktrace () {
2125                 // Check that rethrowing an exception preserves the original stack trace
2126                 try {
2127                         try {
2128                                 ThrowClass.rethrow2 ();
2129                         }
2130                         catch (Exception ex) {
2131                                 // Check that each catch clause has its own exception variable
2132                                 // If not, the throw below will overwrite the exception used
2133                                 // by the rethrow
2134                                 try {
2135                                         throw new DivideByZeroException ();
2136                                 }
2137                                 catch (Exception foo) {
2138                                 }
2139
2140                                 throw;
2141                         }
2142                 }
2143                 catch (Exception ex) {
2144                         if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2145                                 return 0;
2146                 }
2147
2148                 return 1;
2149         }
2150         
2151         interface IFace {}
2152         class Face : IFace {}
2153                 
2154         public static int test_1_array_mismatch_2 () {
2155                 try {
2156                         object [] o = new Face [1];
2157                         o [0] = 1;
2158                         return 0;
2159                 } catch (ArrayTypeMismatchException) {
2160                         return 1;
2161                 }
2162         }
2163         
2164         public static int test_1_array_mismatch_3 () {
2165                 try {
2166                         object [] o = new IFace [1];
2167                         o [0] = 1;
2168                         return 0;
2169                 } catch (ArrayTypeMismatchException) {
2170                         return 1;
2171                 }
2172         }
2173         
2174         public static int test_1_array_mismatch_4 () {
2175                 try {
2176                         object [][] o = new Face [5] [];
2177                         o [0] = new object [5];
2178                         
2179                         return 0;
2180                 } catch (ArrayTypeMismatchException) {
2181                         return 1;
2182                 }
2183         }
2184
2185         public static int test_0_array_size () {
2186                 bool failed;
2187
2188                 try {
2189                         failed = true;
2190                         int[] mem1 = new int [Int32.MaxValue];
2191                 }
2192                 catch (OutOfMemoryException e) {
2193                         failed = false;
2194                 }
2195                 if (failed)
2196                         return 1;
2197
2198                 try {
2199                         failed = true;
2200                         int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2201                 }
2202                 catch (OutOfMemoryException e) {
2203                         failed = false;
2204                 }
2205                 if (failed)
2206                         return 2;
2207
2208                 return 0;
2209         }
2210
2211         struct S {
2212                 int i, j, k, l, m, n;
2213         }
2214
2215         static IntPtr[] addr;
2216
2217         static unsafe void throw_func (int i, S s) {
2218                 addr [i] = new IntPtr (&i);
2219                 throw new Exception ();
2220         }
2221
2222         /* Test that arguments are correctly popped off the stack during unwinding */
2223         public static int test_0_stack_unwind () {
2224                 addr = new IntPtr [1000];
2225                 S s = new S ();
2226                 for (int j = 0; j < 1000; j++) {
2227                         try {
2228                                 throw_func (j, s);
2229                         }
2230                         catch (Exception) {
2231                         }
2232                 }
2233                 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
2234         }
2235
2236         public static int test_0_regress_73242 () {
2237                 int [] arr = new int [10];
2238                 for (int i = 0; i < 10; ++i)
2239                         arr [i] = 0;
2240                 try {
2241                         throw new Exception ();
2242                 }
2243                 catch {
2244                 }
2245                 return 0;
2246     }
2247
2248         public static int test_0_nullref () {
2249                 try {
2250                         Array foo = null;
2251                         foo.Clone();
2252                 } catch (NullReferenceException e) {
2253                         return 0;
2254                 }
2255                 return 1;
2256         }
2257 }
2258