for TARGET_J2EE only:
[mono.git] / mono / mini / objects.cs
1 using System;
2 using System.Text;
3 using System.Reflection;
4 using System.Runtime.InteropServices;
5 using System.Runtime.CompilerServices;
6
7 /*
8  * Regression tests for the mono JIT.
9  *
10  * Each test needs to be of the form:
11  *
12  * static int test_<result>_<name> ();
13  *
14  * where <result> is an integer (the value that needs to be returned by
15  * the method to make it pass.
16  * <name> is a user-displayed name used to identify the test.
17  *
18  * The tests can be driven in two ways:
19  * *) running the program directly: Main() uses reflection to find and invoke
20  *      the test methods (this is useful mostly to check that the tests are correct)
21  * *) with the --regression switch of the jit (this is the preferred way since
22  *      all the tests will be run with optimizations on and off)
23  *
24  * The reflection logic could be moved to a .dll since we need at least another
25  * regression test file written in IL code to have better control on how
26  * the IL code looks.
27  */
28
29 struct Simple {
30         public int a;
31         public byte b;
32         public short c;
33         public long d;
34 }
35
36 struct Small {
37         public byte b1;
38         public byte b2;
39 }
40
41 // Size=2, Align=1
42 struct Foo {
43         bool b1;
44         bool b2;
45 }
46
47 struct Large {
48         int one;
49         int two;
50         long three;
51         long four;
52         int five;
53         long six;
54         int seven;
55         long eight;
56         long nine;
57         long ten;
58
59         public void populate ()
60         {
61                 one = 1; two = 2;
62                 three = 3; four = 4;
63                 five = 5; six = 6;
64                 seven = 7; eight = 8;
65                 nine = 9; ten = 10;
66         }
67         public bool check ()
68         {
69                 return one == 1  && two == 2  &&
70                         three == 3  && four == 4  &&
71                         five == 5  && six == 6  &&
72                         seven == 7  && eight == 8  &&
73                         nine == 9  && ten == 10;
74         }
75 }
76
77 class Sample {
78         public int a;
79         public Sample (int v) {
80                 a = v;
81         }
82 }
83
84 [StructLayout ( LayoutKind.Explicit )]
85 struct StructWithBigOffsets {
86                 [ FieldOffset(10000) ] public byte b;
87                 [ FieldOffset(10001) ] public sbyte sb;
88                 [ FieldOffset(11000) ] public short s;
89                 [ FieldOffset(11002) ] public ushort us;
90                 [ FieldOffset(12000) ] public uint i;
91                 [ FieldOffset(12004) ] public int si;
92                 [ FieldOffset(13000) ] public long l;
93                 [ FieldOffset(14000) ] public float f;
94                 [ FieldOffset(15000) ] public double d;
95 }
96
97 enum SampleEnum {
98         A,
99         B,
100         C
101 }
102
103 class Tests {
104
105         static int Main () {
106                 return TestDriver.RunTests (typeof (Tests));
107         }
108         
109         static int test_0_return () {
110                 Simple s;
111                 s.a = 1;
112                 s.b = 2;
113                 s.c = (short)(s.a + s.b);
114                 s.d = 4;
115                 return s.a - 1;
116         }
117
118         static int test_0_string_access () {
119                 string s = "Hello";
120                 if (s [1] != 'e')
121                         return 1;
122                 return 0;
123         }
124
125         static int test_0_string_virtual_call () {
126                 string s = "Hello";
127                 string s2 = s.ToString ();
128                 if (s2 [1] != 'e')
129                         return 1;
130                 return 0;
131         }
132
133         static int test_0_iface_call () {
134                 string s = "Hello";
135                 object o = ((ICloneable)s).Clone ();
136                 return 0;
137         }
138
139         static int test_5_newobj () {
140                 Sample s = new Sample (5);
141                 return s.a;
142         }
143
144         static int test_4_box () {
145                 object obj = 4;
146                 return (int)obj;
147         }
148
149         static int test_0_enum_unbox () {
150                 SampleEnum x = SampleEnum.A;
151                 object o = x;
152                 
153                 int res = 1;
154
155                 res = (int)o;
156                 
157                 return res;
158         }
159         
160         static Simple get_simple (int v) {
161                 Simple r = new Simple ();
162                 r.a = v;
163                 r.b = (byte)(v + 1);
164                 r.c = (short)(v + 2);
165                 r.d = v + 3;
166
167                 return r;
168         }
169
170         static int test_3_return_struct () {
171                 Simple v = get_simple (1);
172
173                 if (v.a != 1)
174                         return 0;
175                 if (v.b != 2)
176                         return 0;
177                 if (v.c != 3)
178                         return 0;
179                 if (v.d != 4)
180                         return 0;
181                 return 3;
182         }
183
184         public virtual Simple v_get_simple (int v)
185         {
186                 return get_simple (v);
187         }
188         
189         static int test_2_return_struct_virtual () {
190                 Tests t = new Tests ();
191                 Simple v = t.v_get_simple (2);
192
193                 if (v.a != 2)
194                         return 0;
195                 if (v.b != 3)
196                         return 0;
197                 if (v.c != 4)
198                         return 0;
199                 if (v.d != 5)
200                         return 0;
201                 return 2;
202         }
203
204         static int receive_simple (int a, Simple v, int b) {
205                 if (v.a != 1)
206                         return 1;
207                 if (v.b != 2)
208                         return 2;
209                 if (v.c != 3)
210                         return 3;
211                 if (v.d != 4)
212                         return 4;
213                 if (a != 7)
214                         return 5;
215                 if (b != 9)
216                         return 6;
217                 return 0;
218         }
219         
220         static int test_5_pass_struct () {
221                 Simple v = get_simple (1);
222                 if (receive_simple (7, v, 9) != 0)
223                         return 0;
224                 if (receive_simple (7, get_simple (1), 9) != 0)
225                         return 1;
226                 return 5;
227         }
228
229         // Test alignment of small structs
230
231         static Small get_small (byte v) {
232                 Small r = new Small ();
233         
234                 r.b1 = v;
235                 r.b2 = (byte)(v + 1);
236
237                 return r;
238         }
239
240         static Small return_small (Small s) {
241                 return s;
242         }
243
244         static int receive_small (int a, Small v, int b) {
245                 if (v.b1 != 1)
246                         return 1;
247                 if (v.b2 != 2)
248                         return 2;
249                 return 0;
250         }
251
252         static int receive_small_sparc_many_args (int a, int a2, int a3, int a4, int a5, int a6, Small v, int b) {
253                 if (v.b1 != 1)
254                         return 1;
255                 if (v.b2 != 2)
256                         return 2;
257                 return 0;
258         }
259
260         static int test_5_pass_small_struct () {
261                 Small v = get_small (1);
262                 if (receive_small (7, v, 9) != 0)
263                         return 0;
264                 if (receive_small (7, get_small (1), 9) != 0)
265                         return 1;
266                 if (receive_small_sparc_many_args (1, 2, 3, 4, 5, 6, v, 9) != 0)
267                         return 2;
268                 v = return_small (v);
269                 if (v.b1 != 1)
270                         return 3;
271                 if (v.b2 != 2)
272                         return 4;
273                 return 5;
274         }
275
276         struct AStruct {
277                 public int i;
278
279                 public AStruct (int i) {
280                         this.i = i;
281                 }
282
283                 public override int GetHashCode () {
284                         return i;
285                 }
286         }
287
288         // Test that vtypes are unboxed during a virtual call
289         static int test_44_unbox_trampoline () {
290                 AStruct s = new AStruct (44);
291                 object o = s;
292                 return o.GetHashCode ();
293         }
294
295         static int test_0_unbox_trampoline2 () {
296                 int i = 12;
297                 object o = i;
298                         
299                 if (i.ToString () != "12")
300                         return 1;
301                 if (((Int32)o).ToString () != "12")
302                         return 2;
303                 if (o.ToString () != "12")
304                         return 3;
305                 return 0;
306         }
307
308         // Test fields with big offsets
309         static int test_0_fields_with_big_offsets () {
310                 StructWithBigOffsets s = new StructWithBigOffsets ();
311                 StructWithBigOffsets s2 = new StructWithBigOffsets ();
312
313                 s.b = 0xde;
314                 s.sb = 0xe;
315                 s.s = 0x12de;
316                 s.us = 0x12da;
317                 s.i = 0xdeadbeef;
318                 s.si = 0xcafe;
319                 s.l = 0xcafebabe;
320                 s.f = 3.14F;
321                 s.d = 3.14;
322
323                 s2.b = s.b;
324                 s2.sb = s.sb;
325                 s2.s = s.s;
326                 s2.us = s.us;
327                 s2.i = s.i;
328                 s2.si = s.si;
329                 s2.l = s.l;
330                 s2.f = s.f;
331                 s2.d = s.d;
332
333                 if (s2.b != 0xde)
334                         return 1;
335                 if (s2.s != 0x12de)
336                         return 2;
337                 if (s2.i != 0xdeadbeef)
338                         return 3;
339                 if (s2.l != 0xcafebabe)
340                         return 4;
341                 if (s2.f != 3.14F)
342                         return 5;
343                 if (s2.d != 3.14)
344                         return 6;
345                 if (s2.sb != 0xe)
346                         return 7;
347                 if (s2.us != 0x12da)
348                         return 9;
349                 if (s2.si != 0xcafe)
350                         return 10;
351
352                 return 0;
353         }
354
355         class TestRegA {
356
357                 long buf_start;
358                 int buf_length, buf_offset;
359
360                 public TestRegA () {
361                         buf_start = 0;
362                         buf_length = 0;
363                         buf_offset = 0;
364                 }
365         
366                 public long Seek (long position) {
367                         long pos = position;
368                         /* interaction between the register allocator and
369                          * allocating arguments to registers */
370                         if (pos >= buf_start && pos <= buf_start + buf_length) {
371                                 buf_offset = (int) (pos - buf_start);
372                                 return pos;
373                         }
374                         return buf_start;
375                 }
376
377         }
378
379         static int test_0_seektest () {
380                 TestRegA t = new TestRegA ();
381                 return (int)t.Seek (0);
382         }
383
384         class Super : ICloneable {
385                 public virtual object Clone () {
386                         return null;
387                 }
388         }
389         class Duper: Super {
390         }
391
392         static int test_0_null_cast () {
393                 object o = null;
394
395                 Super s = (Super)o;
396
397                 return 0;
398         }
399         
400         static int test_0_super_cast () {
401                 Duper d = new Duper ();
402                 Super sup = d;
403                 Object o = d;
404
405                 if (!(o is Super))
406                         return 1;
407                 try {
408                         d = (Duper)sup;
409                 } catch {
410                         return 2;
411                 }
412                 if (!(d is Object))
413                         return 3;
414                 try {
415                         d = (Duper)(object)sup;
416                 } catch {
417                         return 4;
418                 }
419                 return 0;
420         }
421
422         static int test_0_super_cast_array () {
423                 Duper[] d = new Duper [0];
424                 Super[] sup = d;
425                 Object[] o = d;
426
427                 if (!(o is Super[]))
428                         return 1;
429                 try {
430                         d = (Duper[])sup;
431                 } catch {
432                         return 2;
433                 }
434                 if (!(d is Object[]))
435                         return 3;
436                 try {
437                         d = (Duper[])(object[])sup;
438                 } catch {
439                         return 4;
440                 }
441                 return 0;
442         }
443
444         static int test_0_multi_array_cast () {
445                 Duper[,] d = new Duper [1, 1];
446                 object[,] o = d;
447
448                 try {
449                         o [0, 0] = new Super ();
450                         return 1;
451                 }
452                 catch (ArrayTypeMismatchException) {
453                 }
454
455                 return 0;
456         }
457
458         static int test_0_vector_array_cast () {
459                 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
460                 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
461
462                 if (arr1.GetType () != typeof (int[]))
463                         return 1;
464
465                 if (arr2.GetType () == typeof (int[]))
466                         return 2;
467
468                 int[] b;
469
470                 b = (int[])arr1;
471
472                 try {
473                         b = (int[])arr2;
474                         return 3;
475                 }
476                 catch (InvalidCastException) {
477                 }
478
479                 if (arr2 is int[])
480                         return 4;
481
482                 return 0;
483         }
484
485         static int test_0_enum_array_cast () {
486                 TypeCode[] tc = new TypeCode [0];
487                 object[] oa;
488                 ValueType[] vta;
489                 int[] inta;
490                 Array a = tc;
491                 bool ok;
492
493                 if (a is object[])
494                         return 1;
495                 if (a is ValueType[])
496                         return 2;
497                 if (a is Enum[])
498                         return 3;
499                 try {
500                         ok = false;
501                         oa = (object[])a;
502                 } catch {
503                         ok = true;
504                 }
505                 if (!ok)
506                         return 4;
507                 try {
508                         ok = false;
509                         vta = (ValueType[])a;
510                 } catch {
511                         ok = true;
512                 }
513                 if (!ok)
514                         return 5;
515                 try {
516                         ok = true;
517                         inta = (int[])a;
518                 } catch {
519                         ok = false;
520                 }
521                 if (!ok)
522                         return 6;
523                 return 0;
524         }
525
526         static int test_0_more_cast_corner_cases () {
527                 ValueType[] vta = new ValueType [0];
528                 Enum[] ea = new Enum [0];
529                 Array a = vta;
530                 object[] oa;
531                 bool ok;
532
533                 if (!(a is object[]))
534                         return 1;
535                 if (!(a is ValueType[]))
536                         return 2;
537                 if (a is Enum[])
538                         return 3;
539                 a = ea;
540                 if (!(a is object[]))
541                         return 4;
542                 if (!(a is ValueType[]))
543                         return 5;
544                 if (!(a is Enum[]))
545                         return 6;
546
547                 try {
548                         ok = true;
549                         oa = (object[])a;
550                 } catch {
551                         ok = false;
552                 }
553                 if (!ok)
554                         return 7;
555         
556                 try {
557                         ok = true;
558                         oa = (Enum[])a;
559                 } catch {
560                         ok = false;
561                 }
562                 if (!ok)
563                         return 8;
564         
565                 try {
566                         ok = true;
567                         oa = (ValueType[])a;
568                 } catch {
569                         ok = false;
570                 }
571                 if (!ok)
572                         return 9;
573
574                 a = vta;
575                 try {
576                         ok = true;
577                         oa = (object[])a;
578                 } catch {
579                         ok = false;
580                 }
581                 if (!ok)
582                         return 10;
583         
584                 try {
585                         ok = true;
586                         oa = (ValueType[])a;
587                 } catch {
588                         ok = false;
589                 }
590                 if (!ok)
591                         return 11;
592         
593                 try {
594                         ok = false;
595                         vta = (Enum[])a;
596                 } catch {
597                         ok = true;
598                 }
599                 if (!ok)
600                         return 12;
601                 return 0;
602         }
603
604         static int test_0_cast_iface_array () {
605                 object o = new ICloneable [0];
606                 object o2 = new Duper [0];
607                 object t;
608                 bool ok;
609
610                 if (!(o is object[]))
611                         return 1;
612                 if (!(o2 is ICloneable[]))
613                         return 2;
614
615                 try {
616                         ok = true;
617                         t = (object[])o;
618                 } catch {
619                         ok = false;
620                 }
621                 if (!ok)
622                         return 3;
623         
624                 try {
625                         ok = true;
626                         t = (ICloneable[])o2;
627                 } catch {
628                         ok = false;
629                 }
630                 if (!ok)
631                         return 4;
632
633                 try {
634                         ok = true;
635                         t = (ICloneable[])o;
636                 } catch {
637                         ok = false;
638                 }
639                 if (!ok)
640                         return 5;
641
642                 if (!(o is ICloneable[]))
643                         return 6;
644
645                 /* add tests for interfaces that 'inherit' interfaces */
646                 return 0;
647         }
648
649         private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
650
651         private static int AbsoluteDays (int year, int month, int day)
652         {
653                 int temp = 0, m = 1;
654                 int[] days = daysmonthleap;
655                 while (m < month)
656                         temp += days[m++];
657                 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
658         }
659
660         static int test_719162_complex_div () {
661                 int adays = AbsoluteDays (1970, 1, 1);
662                 return adays;
663         }
664
665         delegate int GetIntDel ();
666
667         static int return4 () {
668                 return 4;
669         }
670
671         int return5 () {
672                 return 5;
673         }
674
675         static int test_2_static_delegate () {
676                 GetIntDel del = new GetIntDel (return4);
677                 int v = del ();
678                 if (v != 4)
679                         return 0;
680                 return 2;
681         }
682
683         static int test_2_instance_delegate () {
684                 Tests t = new Tests ();
685                 GetIntDel del = new GetIntDel (t.return5);
686                 int v = del ();
687                 if (v != 5)
688                         return 0;
689                 return 2;
690         }
691
692         static int test_1_store_decimal () {
693                 decimal[,] a = {{1}};
694
695                 if (a[0,0] != 1m)
696                         return 0;
697                 return 1;
698         }
699
700         static int test_2_intptr_stobj () {
701                 System.IntPtr [] arr = { new System.IntPtr () };
702
703                 if (arr [0] != (System.IntPtr)0)
704                         return 1;
705                 return 2;
706         }
707
708         static int llmult (int a, int b, int c, int d) {
709                 return a + b + c + d;
710         }
711
712         /* 
713          * Test that evaluation of complex arguments does not overwrite the
714          * arguments already in outgoing registers.
715          */
716         static int test_155_regalloc () {
717                 int a = 10;
718                 int b = 10;
719
720                 int c = 0;
721                 int d = 0;
722                 int[] arr = new int [5];
723
724                 return llmult (arr [c + d], 150, 5, 0);
725         }
726
727         static bool large_struct_test (Large a, Large b, Large c, Large d)
728         {
729                 if (!a.check ()) return false;
730                 if (!b.check ()) return false;
731                 if (!c.check ()) return false;
732                 if (!d.check ()) return false;
733                 return true;
734         }
735
736         static int test_2_large_struct_pass ()
737         {
738                 Large a, b, c, d;
739                 a = new Large ();
740                 b = new Large ();
741                 c = new Large ();
742                 d = new Large ();
743                 a.populate ();
744                 b.populate ();
745                 c.populate ();
746                 d.populate ();
747                 if (large_struct_test (a, b, c, d))
748                         return 2;
749                 return 0;
750         }
751
752         public static unsafe int test_0_pin_string () {
753                 string x = "xxx";
754                 fixed (char *c = x) {
755                         if (*c != 'x')
756                                 return 1;
757                 }
758                 return 0;
759         }
760         
761         public static int my_flags;
762         public static int test_0_and_cmp_static ()
763         {
764                 
765                 /* various forms of test [mem], imm */
766                 
767                 my_flags = 0x01020304;
768                 
769                 if ((my_flags & 0x01020304) == 0)
770                         return 1;
771                 
772                 if ((my_flags & 0x00000304) == 0)
773                         return 2;
774                 
775                 if ((my_flags & 0x00000004) == 0)
776                         return 3;
777                 
778                 if ((my_flags & 0x00000300) == 0)
779                         return 4;
780                 
781                 if ((my_flags & 0x00020000) == 0)
782                         return 5;
783                 
784                 if ((my_flags & 0x01000000) == 0)
785                         return 6;
786                 
787                 return 0;
788         }
789         
790         static byte b;
791         public static int test_0_byte_compares ()
792         {
793                 b = 0xff;
794                 if (b == -1)
795                         return 1;
796                 b = 0;
797                 if (!(b < System.Byte.MaxValue))
798                         return 2;
799                 
800                 if (!(b <= System.Byte.MaxValue))
801                         return 3;
802                 
803                 return 0;
804         }
805
806         public static int test_71_long_shift_right () {
807                 ulong value = 38654838087;
808                 int x = 0;
809                 byte [] buffer = new byte [1];
810                 buffer [x] = ((byte)(value >> x));
811                 return buffer [x];
812         }
813         
814         static long x;
815         public static int test_0_addsub_mem ()
816         {
817                 x = 0;
818                 x += 5;
819                 
820                 if (x != 5)
821                         return 1;
822                 
823                 x -= 10;
824                 
825                 if (x != -5)
826                         return 2;
827                 
828                 return 0;
829         }
830         
831         static ulong y;
832         public static int test_0_sh32_mem ()
833         {
834                 y = 0x0102130405060708;
835                 y >>= 32;
836                 
837                 if (y != 0x01021304)
838                         return 1;
839                 
840                 y = 0x0102130405060708;
841                 y <<= 32;
842                 
843                 if (y != 0x0506070800000000)
844                         return 2;
845                 
846                 x = 0x0102130405060708;
847                 x <<= 32;
848                 
849                 if (x != 0x0506070800000000)
850                         return 2;
851                 
852                 return 0;
853         }
854
855
856         static uint dum_de_dum = 1;
857         static int test_0_long_arg_opt ()
858         {
859                 return Foo (0x1234567887654321, dum_de_dum);
860         }
861         
862         static int Foo (ulong x, ulong y)
863         {
864                 if (x != 0x1234567887654321)
865                         return 1;
866                 
867                 if (y != 1)
868                         return 2;
869                 
870                 return 0;
871         }
872         
873         static int test_0_long_ret_opt ()
874         {
875                 ulong x = X ();
876                 if (x != 0x1234567887654321)
877                         return 1;
878                 ulong y = Y ();
879                 if (y != 1)
880                         return 2;
881                 
882                 return 0;
883         }
884         
885         static ulong X ()
886         {
887                 return 0x1234567887654321;
888         }
889         
890         static ulong Y ()
891         {
892                 return dum_de_dum;
893         }
894
895         /* from bug# 71515 */
896         static int counter = 0;
897         static bool WriteStuff () {
898                 counter = 10;
899                 return true;
900         }
901         static int test_0_cond_branch_side_effects () {
902                 counter = 5;
903                 if (WriteStuff());
904                 if (counter == 10)
905                         return 0;
906                 return 1;
907         }
908
909         // bug #74992
910         public static int arg_only_written (string file_name, int[]
911 ncells ) {
912                 if (file_name == null)
913                         return 1;
914
915                 ncells = foo ();
916                 bar (ncells [0]);
917
918                 return 0;
919         }
920
921         public static int[] foo () {
922                 return new int [3];
923         }
924
925         public static void bar (int i) {
926         }
927         
928
929         public static int test_0_arg_only_written ()
930         {
931                 return arg_only_written ("md.in", null);
932         }               
933
934         static long position = 0;
935
936         public static int test_4_static_inc_long () {
937
938                 int count = 4;
939
940                 position = 0;
941
942                 position += count;
943
944                 return (int)position;
945         }
946
947         struct FooStruct {
948
949                 public FooStruct (long l) {
950                 }
951         }
952
953         static int test_0_calls_opcode_emulation () {
954                 // Test that emulated opcodes do not clobber arguments already in
955                 // out registers
956                 checked {
957                         long val = 10000;
958                         new FooStruct (val * 10000);
959                 }
960                 return 0;
961         }
962
963         static int test_0_intrins_string_length () {
964                 string s = "ABC";
965
966                 return (s.Length == 3) ? 0 : 1;
967         }
968
969         static int test_0_intrins_string_chars () {
970                 string s = "ABC";
971
972                 return (s [0] == 'A' && s [1] == 'B' && s [2] == 'C') ? 0 : 1;
973         }
974
975         static int test_0_intrins_object_gettype () {
976                 object o = 1;
977
978                 return (o.GetType () == typeof (int)) ? 0 : 1;
979         }
980
981         static int test_0_intrins_object_gethashcode () {
982                 object o = new Object ();
983
984                 return (o.GetHashCode () == o.GetHashCode ()) ? 0 : 1;
985         }
986
987         class FooClass {
988         }
989
990         static int test_0_intrins_object_ctor () {
991                 object o = new FooClass ();
992
993                 return (o != null) ? 0 : 1;
994         }
995
996         static int test_0_intrins_array_rank () {
997                 int[,] a = new int [10, 10];
998
999                 return (a.Rank == 2) ? 0 : 1;
1000         }
1001
1002         static int test_0_intrins_array_length () {
1003                 int[,] a = new int [10, 10];
1004                 Array a2 = a;
1005
1006                 return (a2.Length == 100) ? 0 : 1;
1007         }
1008
1009         static int test_0_intrins_runtimehelpers_offset_to_string_data () {
1010                 int i = RuntimeHelpers.OffsetToStringData;
1011                 
1012                 return i - i;
1013         }
1014
1015         static int test_0_intrins_string_setchar () {
1016                 StringBuilder sb = new StringBuilder ("ABC");
1017
1018                 sb [1] = 'D';
1019
1020                 return sb.ToString () == "ADC" ? 0 : 1;
1021         }
1022
1023         public class Bar {
1024                 bool allowLocation = true;
1025         Foo f = new Foo ();     
1026         }
1027
1028         static int test_0_regress_78990_unaligned_structs () {
1029                 new Bar ();
1030
1031                 return 0;
1032         }
1033
1034         static unsafe int test_97_negative_index () {
1035                 char[] arr = new char[] {'a', 'b'};
1036                 fixed (char *p = arr) {
1037                         char *i = p + 2;
1038                         char a = i[-2];
1039                         return a;
1040                 }
1041         }
1042
1043         /* bug #82281 */
1044         static int test_0_unsigned_right_shift_imm0 () {
1045                 uint temp = 0;
1046                 byte[] data = new byte[256];
1047                 for (int i = 0; i < 1; i ++)
1048                         temp = (uint)(data[temp >> 24] | data[temp >> 0]);
1049                 return 0;
1050         }
1051
1052         /* #346563 */
1053         static int test_0_array_access_64_bit () {
1054                 int[] arr2 = new int [10];
1055                 for (int i = 0; i < 10; ++i)
1056                         arr2 [i] = i;
1057                 string s = "ABCDEFGH";
1058
1059                 byte[] arr = new byte [4];
1060                 arr [0] = 252;
1061                 arr [1] = 255;
1062                 arr [2] = 255;
1063                 arr [3] = 255;
1064
1065                 int len = arr [0] | (arr [1] << 8) | (arr [2] << 16) | (arr [3] << 24);
1066                 int len2 = - (len + 2);
1067
1068                 // Test array and string access with a 32 bit value whose upper 32 bits are
1069                 // undefined
1070                 // len2 = 3
1071                 if (arr2 [len2] != 2)
1072                         return 1;
1073                 if (s [len2] != 'C')
1074                         return 2;
1075                 return 0;
1076         }
1077 }
1078