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