2005-03-20 Zoltan Varga <vargaz@freemail.hu>
[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  * 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         static int Main () {
29                 return TestDriver.RunTests (typeof (Tests));
30         }
31
32         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         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         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         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         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         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                 return 0;
567         }
568
569         static int test_0_ushort_cast () {
570                 int a;
571                 long l;
572                 ulong ul;
573                 ushort b;
574                 bool failed;
575
576                 try {
577                         a = System.UInt16.MaxValue;
578                         failed = false;
579                         checked {
580                                 b = (ushort)a;
581                         }
582                 } catch (OverflowException) {
583                         failed = true;
584                 }
585                 if (failed)
586                         return 1;
587
588                 try {
589                         a = 0;
590                         failed = false;
591                         checked {
592                                 b = (ushort)a;
593                         }
594                 } catch (OverflowException) {
595                         failed = true;
596                 }
597                 if (failed)
598                         return 2;
599
600                 try {
601                         a = System.UInt16.MaxValue + 1;
602                         failed = true;
603                         checked {
604                                 b = (ushort)a;
605                         }
606                 } catch (OverflowException) {
607                         failed = false;
608                 }
609                 if (failed)
610                         return 3;
611
612                 try {
613                         a = -1;
614                         failed = true;
615                         checked {
616                                 b = (ushort)a;
617                         }
618                 } catch (OverflowException) {
619                         failed = false;
620                 }
621                 if (failed)
622                         return 4;
623
624                 try {
625                         double d = 0;
626                         failed = false;
627                         checked {
628                                 b = (ushort)d;
629                         }
630                 } catch (OverflowException) {
631                         failed = true;
632                 }
633                 if (failed)
634                         return 5;
635
636                 try {
637                         double d = System.UInt16.MaxValue;
638                         failed = false;
639                         checked {
640                                 b = (ushort)d;
641                         }
642                 } catch (OverflowException) {
643                         failed = true;
644                 }
645                 if (failed)
646                         return 6;
647
648                 try {
649                         double d = -1;
650                         failed = true;
651                         checked {
652                                 b = (ushort)d;
653                         }
654                 } catch (OverflowException) {
655                         failed = false;
656                 }
657                 if (failed)
658                         return 7;
659
660                 try {
661                         double d = System.UInt16.MaxValue + 1.0;
662                         failed = true;
663                         checked {
664                                 b = (ushort)d;
665                         }
666                 } catch (OverflowException) {
667                         failed = false;
668                 }
669                 if (failed)
670                         return 8;
671
672                 try {
673                         l = System.UInt16.MaxValue;
674                         failed = false;
675                         checked {
676                                 b = (ushort)l;
677                         }
678                 } catch (OverflowException) {
679                         failed = true;
680                 }
681                 if (failed)
682                         return 9;
683
684                 try {
685                         l = 0;
686                         failed = false;
687                         checked {
688                                 b = (ushort)l;
689                         }
690                 } catch (OverflowException) {
691                         failed = true;
692                 }
693                 if (failed)
694                         return 10;
695
696                 try {
697                         l = System.UInt16.MaxValue + 1;
698                         failed = true;
699                         checked {
700                                 b = (ushort)l;
701                         }
702                 } catch (OverflowException) {
703                         failed = false;
704                 }
705                 if (failed)
706                         return 11;
707
708                 try {
709                         l = -1;
710                         failed = true;
711                         checked {
712                                 b = (ushort)l;
713                         }
714                 } catch (OverflowException) {
715                         failed = false;
716                 }
717                 if (failed)
718                         return 12;
719
720                 try {
721                         ul = 0xfffff;
722                         failed = true;
723                         checked {
724                                 b = (ushort)ul;
725                         }
726                 } catch (OverflowException) {
727                         failed = false;
728                 }
729                 if (failed)
730                         return 13;
731
732                 return 0;
733         }
734         
735         static int test_0_short_cast () {
736                 int a;
737                 long l;
738                 short b;
739                 bool failed;
740
741                 try {
742                         a = System.UInt16.MaxValue;
743                         failed = true;
744                         checked {
745                                 b = (short)a;
746                         }
747                 } catch (OverflowException) {
748                         failed = false;
749                 }
750                 if (failed)
751                         return 1;
752
753                 try {
754                         a = 0;
755                         failed = false;
756                         checked {
757                                 b = (short)a;
758                         }
759                 } catch (OverflowException) {
760                         failed = true;
761                 }
762                 if (failed)
763                         return 2;
764
765                 try {
766                         a = System.Int16.MaxValue + 1;
767                         failed = true;
768                         checked {
769                                 b = (short)a;
770                         }
771                 } catch (OverflowException) {
772                         failed = false;
773                 }
774                 if (failed)
775                         return 3;
776
777                 try {
778                         a = System.Int16.MinValue - 1;
779                         failed = true;
780                         checked {
781                                 b = (short)a;
782                         }
783                 } catch (OverflowException) {
784                         failed = false;
785                 }
786                 if (failed)
787                         return 4;
788
789                 try {
790                         a = -1;
791                         failed = false;
792                         checked {
793                                 b = (short)a;
794                         }
795                 } catch (OverflowException) {
796                         failed = true;
797                 }
798                 if (failed)
799                         return 5;
800
801                 try {
802                         a = System.Int16.MinValue;
803                         failed = false;
804                         checked {
805                                 b = (short)a;
806                         }
807                 } catch (OverflowException) {
808                         failed = true;
809                 }
810                 if (failed)
811                         return 6;
812
813                 try {
814                         a = System.Int16.MaxValue;
815                         failed = false;
816                         checked {
817                                 b = (short)a;
818                         }
819                 } catch (OverflowException) {
820                         failed = true;
821                 }
822                 if (failed)
823                         return 7;
824
825                 try {
826                         a = System.Int16.MaxValue + 1;
827                         failed = true;
828                         checked {
829                                 b = (short)a;
830                         }
831                 } catch (OverflowException) {
832                         failed = false;
833                 }
834                 if (failed)
835                         return 8;
836
837                 try {
838                         double d = System.Int16.MaxValue;
839                         failed = false;
840                         checked {
841                                 b = (short)d;
842                         }
843                 } catch (OverflowException) {
844                         failed = true;
845                 }
846                 if (failed)
847                         return 9;
848                 
849                 try {
850                         double d = System.Int16.MinValue;
851                         failed = false;
852                         checked {
853                                 b = (short)d;
854                         }
855                 } catch (OverflowException) {
856                         failed = true;
857                 }
858                 if (failed)
859                         return 10;
860                 
861                 try {
862                         double d = System.Int16.MaxValue + 1.0;
863                         failed = true;
864                         checked {
865                                 b = (short)d;
866                         }
867                 } catch (OverflowException) {
868                         failed = false;
869                 }
870                 if (failed)
871                         return 11;
872
873                 try {
874                         double d = System.Int16.MinValue - 1.0;
875                         failed = true;
876                         checked {
877                                 b = (short)d;
878                         }
879                 } catch (OverflowException) {
880                         failed = false;
881                 }
882                 if (failed)
883                         return 12;
884
885                 try {
886                         l = System.Int16.MaxValue + 1;
887                         failed = true;
888                         checked {
889                                 b = (short)l;
890                         }
891                 } catch (OverflowException) {
892                         failed = false;
893                 }
894                 if (failed)
895                         return 13;
896
897                 try {
898                         l = System.Int16.MaxValue;
899                         failed = false;
900                         checked {
901                                 b = (short)l;
902                         }
903                 } catch (OverflowException) {
904                         failed = true;
905                 }
906                 if (failed)
907                         return 14;
908
909                 try {
910                         l = System.Int16.MinValue - 1;
911                         failed = true;
912                         checked {
913                                 b = (short)l;
914                         }
915                 } catch (OverflowException) {
916                         failed = false;
917                 }
918                 if (failed)
919                         return 15;
920
921                 
922                 try {
923                         l = System.Int16.MinValue;
924                         failed = false;
925                         checked {
926                                 b = (short)l;
927                         }
928                 } catch (OverflowException) {
929                         failed = true;
930                 }
931                 if (failed)
932                         return 16;
933
934                 try {
935                         l = 0x00000000ffffffff;
936                         failed = true;
937                         checked {
938                                 b = (short)l;
939                         }
940                 } catch (OverflowException) {
941                         failed = false;
942                 }
943                 if (failed)
944                         return 17;
945
946                 return 0;
947         }
948         
949         static int test_0_int_cast () {
950                 int a;
951                 long l;
952                 bool failed;
953
954                 try {
955                         double d = System.Int32.MaxValue + 1.0;
956                         failed = true;
957                         checked {
958                                 a = (int)d;
959                         }
960                 } catch (OverflowException) {
961                         failed = false;
962                 }
963                 if (failed)
964                         return 1;
965
966                 try {
967                         double d = System.Int32.MaxValue;
968                         failed = false;
969                         checked {
970                                 a = (int)d;
971                         }
972                 } catch (OverflowException) {
973                         failed = true;
974                 }
975                 if (failed)
976                         return 2;
977                 
978
979                 try {
980                         double d = System.Int32.MinValue;
981                         failed = false;                 
982                         checked {
983                                 a = (int)d;
984                         }
985                 } catch (OverflowException) {
986                         failed = true;
987                 }
988                 if (failed)
989                         return 3;
990
991
992                 try {
993                         double d =  System.Int32.MinValue - 1.0;
994                         failed = true;
995                         checked {
996                                 a = (int)d;
997                         }
998                 } catch (OverflowException) {
999                         failed = false;
1000                 }
1001                 if (failed)
1002                         return 4;
1003
1004                 try {
1005                         l = System.Int32.MaxValue + (long)1;
1006                         failed = true;
1007                         checked {
1008                                 a = (int)l;
1009                         }
1010                 } catch (OverflowException) {
1011                         failed = false;
1012                 }
1013                 if (failed)
1014                         return 5;
1015
1016                 try {
1017                         l = System.Int32.MaxValue;
1018                         failed = false;
1019                         checked {
1020                                 a = (int)l;
1021                         }
1022                 } catch (OverflowException) {
1023                         failed = true;
1024                 }
1025                 if (failed)
1026                         return 6;
1027                 
1028
1029                 try {
1030                         l = System.Int32.MinValue;
1031                         failed = false;                 
1032                         checked {
1033                                 a = (int)l;
1034                         }
1035                 } catch (OverflowException) {
1036                         failed = true;
1037                 }
1038                 if (failed)
1039                         return 7;
1040
1041
1042                 try {
1043                         l =  System.Int32.MinValue - (long)1;
1044                         failed = true;
1045                         checked {
1046                                 a = (int)l;
1047                         }
1048                 } catch (OverflowException) {
1049                         failed = false;
1050                 }
1051                 if (failed)
1052                         return 8;
1053
1054                 try {
1055                         uint ui = System.UInt32.MaxValue;
1056                         failed = true;
1057                         checked {
1058                                 a = (int)ui;
1059                         }
1060                 }
1061                 catch (OverflowException) {
1062                         failed = false;
1063                 }
1064                 if (failed)
1065                         return 9;
1066
1067                 try {
1068                         ulong ul = (long)(System.Int32.MaxValue) + 1;
1069                         failed = true;
1070                         checked {
1071                                 a = (int)ul;
1072                         }
1073                 }
1074                 catch (OverflowException) {
1075                         failed = false;
1076                 }
1077                 if (failed)
1078                         return 10;
1079
1080
1081                 {
1082                         int i; 
1083                         float f = 1.1f;
1084                         checked {
1085                                 i = (int) f;
1086                         }
1087                 }
1088
1089                 return 0;
1090         }
1091
1092         static int test_0_uint_cast () {
1093                 uint a;
1094                 long l;
1095                 bool failed;
1096
1097                 try {
1098                         double d =  System.UInt32.MaxValue;
1099                         failed = false;
1100                         checked {
1101                                 a = (uint)d;
1102                         }
1103                 } catch (OverflowException) {
1104                         failed = true;
1105                 }
1106                 if (failed)
1107                         return 1;
1108
1109                 try {
1110                         double d = System.UInt32.MaxValue + 1.0;
1111                         failed = true;
1112                         checked {
1113                                 a = (uint)d;
1114                         }
1115                 } catch (OverflowException) {
1116                         failed = false;
1117                 }
1118                 if (failed)
1119                         return 2;
1120
1121                 try {
1122                         double d = System.UInt32.MinValue;
1123                         failed = false;
1124                         checked {
1125                                 a = (uint)d;
1126                         }
1127                 } catch (OverflowException) {
1128                         failed = true;
1129                 }
1130                 if (failed)
1131                         return 3;
1132
1133                 try {
1134                         double d = System.UInt32.MinValue - 1.0;
1135                         failed = true;
1136                         checked {
1137                                 a = (uint)d;
1138                         }
1139                 } catch (OverflowException) {
1140                         failed = false;
1141                 }
1142                 if (failed)
1143                         return 4;
1144                 
1145                 try {
1146                         l =  System.UInt32.MaxValue;
1147                         failed = false;
1148                         checked {
1149                                 a = (uint)l;
1150                         }
1151                 } catch (OverflowException) {
1152                         failed = true;
1153                 }
1154                 if (failed)
1155                         return 5;
1156
1157                 try {
1158                         l = System.UInt32.MaxValue + (long)1;
1159                         failed = true;
1160                         checked {
1161                                 a = (uint)l;
1162                         }
1163                 } catch (OverflowException) {
1164                         failed = false;
1165                 }
1166                 if (failed)
1167                         return 6;
1168
1169                 try {
1170                         l = System.UInt32.MinValue;
1171                         failed = false;
1172                         checked {
1173                                 a = (uint)l;
1174                         }
1175                 } catch (OverflowException) {
1176                         failed = true;
1177                 }
1178                 if (failed)
1179                         return 7;
1180
1181                 try {
1182                         l = System.UInt32.MinValue - (long)1;
1183                         failed = true;
1184                         checked {
1185                                 a = (uint)l;
1186                         }
1187                 } catch (OverflowException) {
1188                         failed = false;
1189                 }
1190                 if (failed)
1191                         return 8;
1192
1193                 try {
1194                         int i = -1;
1195                         failed = true;
1196                         checked {
1197                                 a = (uint)i;
1198                         }
1199                 }
1200                 catch (OverflowException) {
1201                         failed = false;
1202                 }
1203                 if (failed)
1204                         return 9;
1205
1206                 {
1207                         uint i; 
1208                         float f = 1.1f;
1209                         checked {
1210                                 i = (uint) f;
1211                         }
1212                 }
1213                 
1214                 return 0;
1215         }
1216         
1217         static int test_0_long_cast () {
1218                 long a;
1219                 bool failed;
1220
1221                 try {
1222                         double d = System.Int64.MaxValue - 512.0;
1223                         failed = true;
1224                         checked {
1225                                 a = (long)d;
1226                         }
1227                 } catch (OverflowException) {
1228                         failed = false;
1229                 }
1230                 if (failed)
1231                         return 1;
1232
1233                 try {
1234                         double d = System.Int64.MaxValue - 513.0;
1235                         failed = false;
1236                         checked {
1237                                 a = (long)d;
1238                         }
1239                 } catch (OverflowException) {
1240                         failed = true;
1241                 }
1242                 if (failed)
1243                         return 2;
1244                 
1245                 try {
1246                         double d = System.Int64.MinValue - 1024.0;
1247                         failed = false;                 
1248                         checked {
1249                                 a = (long)d;
1250                         }
1251                 } catch (OverflowException) {
1252                         failed = true;
1253                 }
1254                 if (failed)
1255                         return 3;
1256
1257                 try {
1258                         double d = System.Int64.MinValue - 1025.0;
1259                         failed = true;
1260                         checked {
1261                                 a = (long)d;
1262                         }
1263                 } catch (OverflowException) {
1264                         failed = false;
1265                 }
1266                 if (failed)
1267                         return 4;
1268
1269                 {
1270                         long i; 
1271                         float f = 1.1f;
1272                         checked {
1273                                 i = (long) f;
1274                         }
1275                 }
1276
1277                 return 0;
1278         }
1279
1280         static int test_0_ulong_cast () {
1281                 ulong a;
1282                 bool failed;
1283
1284                 /*
1285                  * These tests depend on properties of x86 fp arithmetic so they won't work
1286                  * on other platforms.
1287                  */
1288
1289                 /*
1290                 try {
1291                         double d = System.UInt64.MaxValue - 1024.0;
1292                         failed = true;
1293                         checked {
1294                                 a = (ulong)d;
1295                         }
1296                 } catch (OverflowException) {
1297                         failed = false;
1298                 }
1299                 if (failed)
1300                         return 1;
1301
1302                 try {
1303                         double d = System.UInt64.MaxValue - 1025.0;
1304                         failed = false;
1305                         checked {
1306                                 a = (ulong)d;
1307                         }
1308                 } catch (OverflowException) {
1309                         failed = true;
1310                 }
1311                 if (failed)
1312                         return 2;
1313                 */      
1314
1315                 try {
1316                         double d = 0;
1317                         failed = false;                 
1318                         checked {
1319                                 a = (ulong)d;
1320                         }
1321                 } catch (OverflowException) {
1322                         failed = true;
1323                 }
1324                 if (failed)
1325                         return 3;
1326
1327                 try {
1328                         double d = -1;
1329                         failed = true;
1330                         checked {
1331                                 a = (ulong)d;
1332                         }
1333                 } catch (OverflowException) {
1334                         failed = false;
1335                 }
1336                 if (failed)
1337                         return 4;
1338
1339                 {
1340                         ulong i; 
1341                         float f = 1.1f;
1342                         checked {
1343                                 i = (ulong) f;
1344                         }
1345                 }
1346
1347                 try {
1348                         int i = -1;
1349                         failed = true;
1350                         checked {
1351                                 a = (ulong)i;
1352                         }
1353                 }
1354                 catch (OverflowException) {
1355                         failed = false;
1356                 }
1357                 if (failed)
1358                         return 5;
1359
1360                 try {
1361                         int i = Int32.MinValue;
1362                         failed = true;
1363                         checked {
1364                                 a = (ulong)i;
1365                         }
1366                 }
1367                 catch (OverflowException) {
1368                         failed = false;
1369                 }
1370                 if (failed)
1371                         return 6;
1372
1373                 return 0;
1374         }
1375
1376         static int test_0_simple_double_casts () {
1377
1378                 double d = 0xffffffff;
1379
1380                 if ((uint)d != 4294967295)
1381                         return 1;
1382
1383                 /*
1384                  * These tests depend on properties of x86 fp arithmetic so they won't work
1385                  * on other platforms.
1386                  */
1387                 /*
1388                 d = 0xffffffffffffffff;
1389
1390                 if ((ulong)d != 0)
1391                         return 2;
1392
1393                 if ((ushort)d != 0)
1394                         return 3;
1395                         
1396                 if ((byte)d != 0)
1397                         return 4;
1398                 */
1399                         
1400                 d = 0xffff;
1401
1402                 if ((ushort)d != 0xffff)
1403                         return 5;
1404                 
1405                 if ((byte)d != 0xff)
1406                         return 6;
1407                         
1408                 return 0;
1409         }
1410         
1411         static int test_0_div_zero () {
1412                 int d = 1;
1413                 int q = 0;
1414                 int val;
1415                 bool failed;
1416
1417                 try {
1418                         failed = true;
1419                         val = d / q;
1420                 } catch (DivideByZeroException) {
1421                         failed = false;
1422                 }
1423                 if (failed)
1424                         return 1;
1425
1426                 try {
1427                         failed = true;
1428                         val = d % q;
1429                 } catch (DivideByZeroException) {
1430                         failed = false;
1431                 }
1432                 if (failed)
1433                         return 2;
1434
1435                 try {
1436                         failed = true;
1437                         q = -1;
1438                         d = Int32.MinValue;
1439                         val = d / q;
1440                 } catch (DivideByZeroException) {
1441                         /* wrong exception */
1442                 } catch (ArithmeticException) {
1443                         failed = false;
1444                 }
1445                 if (failed)
1446                         return 3;
1447
1448                 try {
1449                         failed = true;
1450                         q = -1;
1451                         d = Int32.MinValue;
1452                         val = d % q;
1453                 } catch (DivideByZeroException) {
1454                         /* wrong exception */
1455                 } catch (ArithmeticException) {
1456                         failed = false;
1457                 }
1458                 if (failed)
1459                         return 4;
1460
1461                 return 0;
1462         }
1463
1464         static int return_55 () {
1465                 return 55;
1466         }
1467
1468         static int test_0_cfold_div_zero () {
1469                 // Test that constant folding doesn't cause division by zero exceptions
1470                 if (return_55 () != return_55 ()) {
1471                         int d = 1;
1472                         int q = 0;
1473                         int val;                        
1474
1475                         val = d / q;
1476                         val = d % q;
1477
1478                         q = -1;
1479                         d = Int32.MinValue;
1480                         val = d / q;
1481
1482                         q = -1;
1483                         val = d % q;
1484                 }
1485
1486                 return 0;
1487         }
1488
1489         static int test_0_udiv_zero () {
1490                 uint d = 1;
1491                 uint q = 0;
1492                 uint val;
1493                 bool failed;
1494
1495                 try {
1496                         failed = true;
1497                         val = d / q;
1498                 } catch (DivideByZeroException) {
1499                         failed = false;
1500                 }
1501                 if (failed)
1502                         return 1;
1503
1504                 try {
1505                         failed = true;
1506                         val = d % q;
1507                 } catch (DivideByZeroException) {
1508                         failed = false;
1509                 }
1510                 if (failed)
1511                         return 2;
1512
1513                 return 0;
1514         }
1515
1516         static int test_0_long_div_zero () {
1517                 long d = 1;
1518                 long q = 0;
1519                 long val;
1520                 bool failed;
1521
1522                 try {
1523                         failed = true;
1524                         val = d / q;
1525                 } catch (DivideByZeroException) {
1526                         failed = false;
1527                 }
1528                 if (failed)
1529                         return 1;
1530
1531                 try {
1532                         failed = true;
1533                         val = d % q;
1534                 } catch (DivideByZeroException) {
1535                         failed = false;
1536                 }
1537                 if (failed)
1538                         return 2;
1539
1540                 try {
1541                         failed = true;
1542                         q = -1;
1543                         d = Int64.MinValue;
1544                         val = d / q;
1545                 } catch (DivideByZeroException) {
1546                         /* wrong exception */
1547                 } catch (ArithmeticException) {
1548                         failed = false;
1549                 }
1550                 if (failed)
1551                         return 3;
1552
1553                 try {
1554                         failed = true;
1555                         q = -1;
1556                         d = Int64.MinValue;
1557                         val = d % q;
1558                 } catch (DivideByZeroException) {
1559                         /* wrong exception */
1560                 } catch (ArithmeticException) {
1561                         failed = false;
1562                 }
1563                 if (failed)
1564                         return 4;
1565
1566                 return 0;
1567         }
1568
1569         static int test_0_ulong_div_zero () {
1570                 ulong d = 1;
1571                 ulong q = 0;
1572                 ulong val;
1573                 bool failed;
1574
1575                 try {
1576                         failed = true;
1577                         val = d / q;
1578                 } catch (DivideByZeroException) {
1579                         failed = false;
1580                 }
1581                 if (failed)
1582                         return 1;
1583
1584                 try {
1585                         failed = true;
1586                         val = d % q;
1587                 } catch (DivideByZeroException) {
1588                         failed = false;
1589                 }
1590                 if (failed)
1591                         return 2;
1592
1593                 return 0;
1594         }
1595
1596         static int test_0_float_div_zero () {
1597                 double d = 1;
1598                 double q = 0;
1599                 double val;
1600                 bool failed;
1601
1602                 try {
1603                         failed = false;
1604                         val = d / q;
1605                 } catch (DivideByZeroException) {
1606                         failed = true;
1607                 }
1608                 if (failed)
1609                         return 1;
1610
1611                 try {
1612                         failed = false;
1613                         val = d % q;
1614                 } catch (DivideByZeroException) {
1615                         failed = true;
1616                 }
1617                 if (failed)
1618                         return 2;
1619
1620                 return 0;
1621         }
1622
1623         static int test_0_invalid_unbox () {
1624
1625                 int i = 123;
1626                 object o = "Some string";
1627                 int res = 1;
1628                 
1629                 try {
1630                         // Illegal conversion; o contains a string not an int
1631                         i = (int) o;   
1632                 } catch (Exception e) {
1633                         if (i ==123)
1634                                 res = 0;
1635                 }
1636
1637                 return res;
1638         }
1639
1640         // Test that double[] can't be cast to double (bug #46027)
1641         static int test_0_invalid_unbox_arrays () {
1642                 double[] d1 = { 1.0 };
1643                 double[][] d2 = { d1 };
1644                 Array a = d2;
1645
1646                 try {
1647                         foreach (double d in a) {
1648                         }
1649                         return 1;
1650                 }
1651                 catch (InvalidCastException e) {
1652                         return 0;
1653                 }
1654         }
1655
1656         /* bug# 42190, at least mcs generates a leave for the return that
1657          * jumps out of multiple exception clauses: we used to execute just 
1658          * one enclosing finally block.
1659          */
1660         static int finally_level;
1661         static void do_something () {
1662                 int a = 0;
1663                 try {
1664                         try {
1665                                 return;
1666                         } finally {
1667                                 a = 1;
1668                         }
1669                 } finally {
1670                         finally_level++;
1671                 }
1672         }
1673
1674         static int test_2_multiple_finally_clauses () {
1675                 finally_level = 0;
1676                 do_something ();
1677                 if (finally_level == 1)
1678                         return 2;
1679                 return 0;
1680         }
1681
1682         static int test_3_checked_cast_un () {
1683                 ulong i = 0x8000000034000000;
1684                 long j;
1685
1686                 try {
1687                         checked { j = (long)i; }
1688                 } catch (OverflowException) {
1689                         j = 2;
1690                 }
1691
1692                 if (j != 2)
1693                         return 0;
1694                 return 3;
1695         }
1696         
1697         static int test_4_checked_cast () {
1698                 long i;
1699                 ulong j;
1700
1701                 unchecked { i = (long)0x8000000034000000;};
1702                 try {
1703                         checked { j = (ulong)i; }
1704                 } catch (OverflowException) {
1705                         j = 3;
1706                 }
1707
1708                 if (j != 3)
1709                         return 0;
1710                 return 4;
1711         }
1712
1713         static readonly int[] mul_dim_results = new int[] {
1714                 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1715                 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1716                 2, 0, 2, 1, 2, 8, 
1717                 3, 0, 3, 1, 3, 8, 
1718                 4, 0, 4, 1, 4, 8, 
1719                 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1720                 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1721                 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1722         };
1723
1724         static int test_0_multi_dim_array_access () {
1725                 int [,] a = System.Array.CreateInstance (typeof (int),
1726                         new int [] {3,6}, new int [] {2,2 }) as int[,];
1727                 int x, y;
1728                 int result_idx = 0;
1729                 for (x = 0; x < 8; ++x) {
1730                         for (y = 0; y < 9; ++y) {
1731                                 bool got_ex = false;
1732                                 try {
1733                                         a [x, y] = 1;
1734                                 } catch {
1735                                         got_ex = true;
1736                                 }
1737                                 if (got_ex) {
1738                                         if (result_idx >= mul_dim_results.Length)
1739                                                 return -1;
1740                                         if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1741                                                 return result_idx + 1;
1742                                         }
1743                                         result_idx += 2;
1744                                 }
1745                         }
1746                 }
1747                 if (result_idx == mul_dim_results.Length)
1748                         return 0;
1749                 return 200;
1750         }
1751
1752         static void helper_out_obj (out object o) {
1753                 o = (object)"buddy";
1754         }
1755
1756         static void helper_out_string (out string o) {
1757                 o = "buddy";
1758         }
1759
1760         static int test_2_array_mismatch () {
1761                 string[] a = { "hello", "world" };
1762                 object[] b = a;
1763                 bool passed = false;
1764
1765                 try {
1766                         helper_out_obj (out b [1]);
1767                 } catch (ArrayTypeMismatchException) {
1768                         passed = true;
1769                 }
1770                 if (!passed)
1771                         return 0;
1772                 helper_out_string (out a [1]);
1773                 if (a [1] != "buddy")
1774                         return 1;
1775                 return 2;
1776         }
1777
1778         static int test_0_ovf () {
1779                 int ocount = 0;
1780                 
1781                 checked {
1782
1783                         ocount = 0;
1784                         try {
1785                                 ulong a =  UInt64.MaxValue - 1;
1786                                 ulong t = a++;
1787                         } catch {
1788                                 ocount++;
1789                         }
1790                         if (ocount != 0)
1791                                 return 1;
1792
1793                         ocount = 0;
1794                         try {
1795                                 ulong a =  UInt64.MaxValue;
1796                                 ulong t = a++;
1797                         } catch {
1798                                 ocount++;
1799                         }
1800                         if (ocount != 1)
1801                                 return 2;
1802
1803                         ocount = 0;
1804                         try {
1805                                 long a = Int64.MaxValue - 1;
1806                                 long t = a++;
1807                         } catch {
1808                                 ocount++;
1809                         }
1810                         if (ocount != 0)
1811                                 return 3;
1812
1813                         try {
1814                                 long a = Int64.MaxValue;
1815                                 long t = a++;
1816                         } catch {
1817                                 ocount++;
1818                         }
1819                         if (ocount != 1)
1820                                 return 4;
1821
1822                         ocount = 0;
1823                         try {
1824                                 ulong a = UInt64.MaxValue - 1;
1825                                 ulong t = a++;
1826                         } catch {
1827                                 ocount++;
1828                         }
1829                         if (ocount != 0)
1830                                 return 5;
1831
1832                         try {
1833                                 ulong a = UInt64.MaxValue;
1834                                 ulong t = a++;
1835                         } catch {
1836                                 ocount++;
1837                         }
1838                         if (ocount != 1)
1839                                 return 6;
1840
1841                         ocount = 0;
1842                         try {
1843                                 long a = Int64.MinValue + 1;
1844                                 long t = a--;
1845                         } catch {
1846                                 ocount++;
1847                         }
1848                         if (ocount != 0)
1849                                 return 7;
1850
1851                         ocount = 0;
1852                         try {
1853                                 long a = Int64.MinValue;
1854                                 long t = a--;
1855                         } catch {
1856                                 ocount++;
1857                         }
1858                         if (ocount != 1)
1859                                 return 8;
1860
1861                         ocount = 0;
1862                         try {
1863                                 ulong a = UInt64.MinValue + 1;
1864                                 ulong t = a--;
1865                         } catch {
1866                                 ocount++;
1867                         }
1868                         if (ocount != 0)
1869                                 return 9;
1870
1871                         ocount = 0;
1872                         try {
1873                                 ulong a = UInt64.MinValue;
1874                                 ulong t = a--;
1875                         } catch {
1876                                 ocount++;
1877                         }
1878                         if (ocount != 1)
1879                                 return 10;
1880
1881                         ocount = 0;
1882                         try {
1883                                 int a = Int32.MinValue + 1;
1884                                 int t = a--;
1885                         } catch {
1886                                 ocount++;
1887                         }
1888                         if (ocount != 0)
1889                                 return 11;
1890
1891                         ocount = 0;
1892                         try {
1893                                 int a = Int32.MinValue;
1894                                 int t = a--;
1895                         } catch {
1896                                 ocount++;
1897                         }
1898                         if (ocount != 1)
1899                                 return 12;
1900
1901                         ocount = 0;
1902                         try {
1903                                 uint a = 1;
1904                                 uint t = a--;
1905                         } catch {
1906                                 ocount++;
1907                         }
1908                         if (ocount != 0)
1909                                 return 13;
1910
1911                         ocount = 0;
1912                         try {
1913                                 uint a = 0;
1914                                 uint t = a--;
1915                         } catch {
1916                                 ocount++;
1917                         }
1918                         if (ocount != 1)
1919                                 return 14;
1920
1921                         ocount = 0;
1922                         try {
1923                                 sbyte a = 126;
1924                                 sbyte t = a++;
1925                         } catch {
1926                                 ocount++;
1927                         }
1928                         if (ocount != 0)
1929                                 return 15;
1930
1931                         ocount = 0;
1932                         try {
1933                                 sbyte a = 127;
1934                                 sbyte t = a++;
1935                         } catch {
1936                                 ocount++;
1937                         }
1938                         if (ocount != 1)
1939                                 return 16;
1940
1941                         ocount = 0;
1942                         try {
1943                         } catch {
1944                                 ocount++;
1945                         }
1946                         if (ocount != 0)
1947                                 return 17;
1948
1949                         ocount = 0;
1950                         try {
1951                                 int a = 1 << 29;
1952                                 int t = a*2;
1953                         } catch {
1954                                 ocount++;
1955                         }
1956                         if (ocount != 0)
1957                                 return 18;
1958
1959                         ocount = 0;
1960                         try {
1961                                 int a = 1 << 30;
1962                                 int t = a*2;
1963                         } catch {
1964                                 ocount++;
1965                         }
1966                         if (ocount != 1)
1967                                 return 19;
1968
1969                         ocount = 0;
1970                         try {
1971                                 ulong a = 0xffffffffff;
1972                                 ulong t = a*0x0ffffff;
1973                         } catch {
1974                                 ocount++;
1975                         }
1976                         if (ocount != 0)
1977                                 return 20;
1978
1979                         ocount = 0;
1980                         try {
1981                                 ulong a = 0xffffffffff;
1982                                 ulong t = a*0x0fffffff;
1983                         } catch {
1984                                 ocount++;
1985                         }
1986                         if (ocount != 1)
1987                                 return 21;
1988
1989                         ocount = 0;
1990                         try {
1991                                 long a = Int64.MinValue;
1992                                 long b = 10;
1993                                 long v = a * b;
1994                         } catch {
1995                                 ocount ++;
1996                         }
1997                         if (ocount != 1)
1998                                 return 22;
1999
2000                         ocount = 0;
2001                         try {
2002                                 long a = 10;
2003                                 long b = Int64.MinValue;
2004                                 long v = a * b;
2005                         } catch {
2006                                 ocount ++;
2007                         }
2008                         if (ocount != 1)
2009                                 return 23;
2010                 }
2011                 
2012                 return 0;
2013         }
2014
2015         class Broken {
2016                 static int i;
2017
2018                 static Broken () {
2019                         throw new Exception ("Ugh!");
2020                 }
2021         
2022                 public static int DoSomething () {
2023                         return i;
2024                 }
2025         }
2026
2027         static int test_0_exception_in_cctor () {
2028                 try {
2029                         Broken.DoSomething ();
2030                 }
2031                 catch (TypeInitializationException) {
2032                         // This will only happen once even if --regression is used
2033                 }
2034                 return 0;
2035         }
2036
2037         static int test_5_regalloc () {
2038                 int i = 0;
2039
2040                 try {
2041                         for (i = 0; i < 10; ++i) {
2042                                 if (i == 5)
2043                                         throw new Exception ();
2044                         }
2045                 }
2046                 catch (Exception) {
2047                         if (i != 5)
2048                                 return i;
2049                 }
2050
2051                 // Check that variables written in catch clauses are volatile
2052                 int j = 0;
2053                 try {
2054                         throw new Exception ();
2055                 }
2056                 catch (Exception) {
2057                         j = 5;
2058                 }
2059                 if (j != 5)
2060                         return 6;
2061
2062                 int k = 0;
2063                 try {
2064                         try {
2065                                 throw new Exception ();
2066                         }
2067                         finally {
2068                                 k = 5;
2069                         }
2070                 }
2071                 catch (Exception) {
2072                 }
2073                 if (k != 5)
2074                         return 7;
2075
2076                 return i;
2077         }
2078
2079         /* MarshalByRefObject prevents the methods from being inlined */
2080         class ThrowClass : MarshalByRefObject {
2081                 public static void rethrow1 () {
2082                         throw new Exception ();
2083                 }
2084
2085                 public static void rethrow2 () {
2086                         rethrow1 ();
2087                 }
2088         }
2089
2090         static int test_0_rethrow_stacktrace () {
2091                 // Check that rethrowing an exception preserves the original stack trace
2092                 try {
2093                         try {
2094                                 ThrowClass.rethrow2 ();
2095                         }
2096                         catch (Exception ex) {
2097                                 // Check that each catch clause has its own exception variable
2098                                 // If not, the throw below will overwrite the exception used
2099                                 // by the rethrow
2100                                 try {
2101                                         throw new DivideByZeroException ();
2102                                 }
2103                                 catch (Exception foo) {
2104                                 }
2105
2106                                 throw;
2107                         }
2108                 }
2109                 catch (Exception ex) {
2110                         if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2111                                 return 0;
2112                 }
2113
2114                 return 1;
2115         }
2116         
2117         interface IFace {}
2118         class Face : IFace {}
2119                 
2120         static int test_1_array_mismatch_2 () {
2121                 try {
2122                         object [] o = new Face [1];
2123                         o [0] = 1;
2124                         return 0;
2125                 } catch (ArrayTypeMismatchException) {
2126                         return 1;
2127                 }
2128         }
2129         
2130         static int test_1_array_mismatch_3 () {
2131                 try {
2132                         object [] o = new IFace [1];
2133                         o [0] = 1;
2134                         return 0;
2135                 } catch (ArrayTypeMismatchException) {
2136                         return 1;
2137                 }
2138         }
2139         
2140         static int test_1_array_mismatch_4 () {
2141                 try {
2142                         object [][] o = new Face [5] [];
2143                         o [0] = new object [5];
2144                         
2145                         return 0;
2146                 } catch (ArrayTypeMismatchException) {
2147                         return 1;
2148                 }
2149         }
2150
2151         static int test_0_array_size () {
2152                 bool failed;
2153
2154                 try {
2155                         failed = true;
2156                         int[] mem1 = new int [Int32.MaxValue];
2157                 }
2158                 catch (OutOfMemoryException e) {
2159                         failed = false;
2160                 }
2161                 if (failed)
2162                         return 1;
2163
2164                 try {
2165                         failed = true;
2166                         int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2167                 }
2168                 catch (OutOfMemoryException e) {
2169                         failed = false;
2170                 }
2171                 if (failed)
2172                         return 2;
2173
2174                 return 0;
2175         }
2176
2177         struct S {
2178                 int i, j, k, l, m, n;
2179         }
2180
2181         static IntPtr[] addr;
2182
2183         static unsafe void throw_func (int i, S s) {
2184                 addr [i] = new IntPtr (&i);
2185                 throw new Exception ();
2186         }
2187
2188         /* Test that arguments are correctly popped off the stack during unwinding */
2189         static int test_0_stack_unwind () {
2190                 addr = new IntPtr [1000];
2191                 S s = new S ();
2192                 for (int j = 0; j < 1000; j++) {
2193                         try {
2194                                 throw_func (j, s);
2195                         }
2196                         catch (Exception) {
2197                         }
2198                 }
2199                 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
2200         }               
2201 }
2202