using System;
+using System.Text;
using System.Reflection;
using System.Runtime.InteropServices;
+using System.Runtime.CompilerServices;
/*
* Regression tests for the mono JIT.
public byte b2;
}
+// Size=2, Align=1
+struct Foo {
+ bool b1;
+ bool b2;
+}
+
struct Large {
int one;
int two;
return 5;
}
+ static Simple s_v;
+ static int test_5_pass_static_struct () {
+ s_v = get_simple (1);
+ if (receive_simple (7, s_v, 9) != 0)
+ return 0;
+ return 5;
+ }
+
// Test alignment of small structs
static Small get_small (byte v) {
return 0;
}
+ static int receive_small_sparc_many_args (int a, int a2, int a3, int a4, int a5, int a6, Small v, int b) {
+ if (v.b1 != 1)
+ return 1;
+ if (v.b2 != 2)
+ return 2;
+ return 0;
+ }
+
static int test_5_pass_small_struct () {
Small v = get_small (1);
if (receive_small (7, v, 9) != 0)
return 0;
if (receive_small (7, get_small (1), 9) != 0)
return 1;
+ if (receive_small_sparc_many_args (1, 2, 3, 4, 5, 6, v, 9) != 0)
+ return 2;
v = return_small (v);
if (v.b1 != 1)
- return 2;
- if (v.b2 != 2)
return 3;
+ if (v.b2 != 2)
+ return 4;
return 5;
}
+ // 64-bits, 32-bit aligned
+ struct struct1 {
+ public int a;
+ public int b;
+ };
+
+ static int check_struct1(struct1 x) {
+ if (x.a != 1)
+ return 1;
+ if (x.b != 2)
+ return 2;
+ return 0;
+ }
+
+ static int pass_struct1(int a, int b, struct1 x) {
+ if (a != 3)
+ return 3;
+ if (b != 4)
+ return 4;
+ return check_struct1(x);
+ }
+
+ static int pass_struct1(int a, struct1 x) {
+ if (a != 3)
+ return 3;
+ return check_struct1(x);
+ }
+
+ static int pass_struct1(struct1 x) {
+ return check_struct1(x);
+ }
+
+ static int test_0_struct1_args () {
+ int r;
+ struct1 x;
+
+ x.a = 1;
+ x.b = 2;
+ if ((r = check_struct1(x)) != 0)
+ return r;
+ if ((r = pass_struct1(x)) != 0)
+ return r + 10;
+ if ((r = pass_struct1(3, x)) != 0)
+ return r + 20;
+ if ((r = pass_struct1(3, 4, x)) != 0)
+ return r + 30;
+ return 0;
+ }
+
+ // 64-bits, 64-bit aligned
+ struct struct2 {
+ public long a;
+ };
+
+ static int check_struct2(struct2 x) {
+ if (x.a != 1)
+ return 1;
+ return 0;
+ }
+
+ static int pass_struct2(int a, int b, int c, struct2 x) {
+ if (a != 3)
+ return 3;
+ if (b != 4)
+ return 4;
+ if (c != 5)
+ return 5;
+ return check_struct2(x);
+ }
+
+ static int pass_struct2(int a, int b, struct2 x) {
+ if (a != 3)
+ return 3;
+ if (b != 4)
+ return 4;
+ return check_struct2(x);
+ }
+
+ static int pass_struct2(int a, struct2 x) {
+ if (a != 3)
+ return 3;
+ return check_struct2(x);
+ }
+
+ static int pass_struct2(struct2 x) {
+ return check_struct2(x);
+ }
+
+ static int test_0_struct2_args () {
+ int r;
+ struct2 x;
+
+ x.a = 1;
+ if ((r = check_struct2(x)) != 0)
+ return r;
+ if ((r = pass_struct2(x)) != 0)
+ return r + 10;
+ if ((r = pass_struct2(3, x)) != 0)
+ return r + 20;
+ if ((r = pass_struct2(3, 4, x)) != 0)
+ return r + 30;
+ if ((r = pass_struct2(3, 4, 5, x)) != 0)
+ return r + 40;
+ return 0;
+ }
+
+ // 128 bits
+ struct Struct3 {
+ public long i, j, k, l;
+ }
+
+ static int pass_struct3 (int i, int j, int k, int l, int m, int n, int o, int p, Struct3 s, int q) {
+ if (s.i + s.j + s.k + s.l != 10)
+ return 1;
+ else
+ return 0;
+ }
+
+ static int test_0_struct3_args () {
+ Struct3 s = new Struct3 ();
+ s.i = 1;
+ s.j = 2;
+ s.k = 3;
+ s.l = 4;
+
+ return pass_struct3 (1, 2, 3, 4, 5, 6, 7, 8, s, 9);
+ }
+
struct AStruct {
public int i;
{
return arg_only_written ("md.in", null);
}
+
+ static long position = 0;
+
+ public static int test_4_static_inc_long () {
+
+ int count = 4;
+
+ position = 0;
+
+ position += count;
+
+ return (int)position;
+ }
+
+ struct FooStruct {
+
+ public FooStruct (long l) {
+ }
+ }
+
+ static int test_0_calls_opcode_emulation () {
+ // Test that emulated opcodes do not clobber arguments already in
+ // out registers
+ checked {
+ long val = 10000;
+ new FooStruct (val * 10000);
+ }
+ return 0;
+ }
+
+ static int test_0_intrins_string_length () {
+ string s = "ABC";
+
+ return (s.Length == 3) ? 0 : 1;
+ }
+
+ static int test_0_intrins_string_chars () {
+ string s = "ABC";
+
+ return (s [0] == 'A' && s [1] == 'B' && s [2] == 'C') ? 0 : 1;
+ }
+
+ static int test_0_intrins_object_gettype () {
+ object o = 1;
+
+ return (o.GetType () == typeof (int)) ? 0 : 1;
+ }
+
+ static int test_0_intrins_object_gethashcode () {
+ object o = new Object ();
+
+ return (o.GetHashCode () == o.GetHashCode ()) ? 0 : 1;
+ }
+
+ class FooClass {
+ }
+
+ static int test_0_intrins_object_ctor () {
+ object o = new FooClass ();
+
+ return (o != null) ? 0 : 1;
+ }
+
+ static int test_0_intrins_array_rank () {
+ int[,] a = new int [10, 10];
+
+ return (a.Rank == 2) ? 0 : 1;
+ }
+
+ static int test_0_intrins_array_length () {
+ int[,] a = new int [10, 10];
+ Array a2 = a;
+
+ return (a2.Length == 100) ? 0 : 1;
+ }
+
+ static int test_0_intrins_runtimehelpers_offset_to_string_data () {
+ int i = RuntimeHelpers.OffsetToStringData;
+
+ return i - i;
+ }
+
+ static int test_0_intrins_string_setchar () {
+ StringBuilder sb = new StringBuilder ("ABC");
+
+ sb [1] = 'D';
+
+ return sb.ToString () == "ADC" ? 0 : 1;
+ }
+
+ public class Bar {
+ bool allowLocation = true;
+ Foo f = new Foo ();
+ }
+
+ static int test_0_regress_78990_unaligned_structs () {
+ new Bar ();
+
+ return 0;
+ }
+
+ static unsafe int test_97_negative_index () {
+ char[] arr = new char[] {'a', 'b'};
+ fixed (char *p = arr) {
+ char *i = p + 2;
+ char a = i[-2];
+ return a;
+ }
+ }
+
+ /* bug #82281 */
+ static int test_0_unsigned_right_shift_imm0 () {
+ uint temp = 0;
+ byte[] data = new byte[256];
+ for (int i = 0; i < 1; i ++)
+ temp = (uint)(data[temp >> 24] | data[temp >> 0]);
+ return 0;
+ }
+
+ class Foo2 {
+ public virtual int foo () {
+ return 0;
+ }
+ }
+
+ sealed class Bar2 : Foo2 {
+ public override int foo () {
+ return 0;
+ }
+ }
+
+ static int test_0_abcrem_check_this_removal () {
+ Bar2 b = new Bar2 ();
+
+ // The check_this generated here by the JIT should be removed
+ b.foo ();
+
+ return 0;
+ }
+
+ static int invoke_twice (Bar2 b) {
+ b.foo ();
+ // The check_this generated here by the JIT should be removed
+ b.foo ();
+
+ return 0;
+ }
+
+ static int test_0_abcrem_check_this_removal2 () {
+ Bar2 b = new Bar2 ();
+
+ invoke_twice (b);
+
+ return 0;
+ }
+
+ /* #346563 */
+ static int test_0_array_access_64_bit () {
+ int[] arr2 = new int [10];
+ for (int i = 0; i < 10; ++i)
+ arr2 [i] = i;
+ string s = "ABCDEFGH";
+
+ byte[] arr = new byte [4];
+ arr [0] = 252;
+ arr [1] = 255;
+ arr [2] = 255;
+ arr [3] = 255;
+
+ int len = arr [0] | (arr [1] << 8) | (arr [2] << 16) | (arr [3] << 24);
+ int len2 = - (len + 2);
+
+ // Test array and string access with a 32 bit value whose upper 32 bits are
+ // undefined
+ // len2 = 3
+ if (arr2 [len2] != 2)
+ return 1;
+ if (s [len2] != 'C')
+ return 2;
+ return 0;
+ }
+
+ class R4Holder {
+ public static float pi = 3.14f;
+
+ public float float_field;
+ }
+
+ static int test_0_ldsfld_soft_float () {
+ if (R4Holder.pi == 3.14f)
+ return 0;
+ else
+ return 1;
+ }
+
+ static int test_0_ldfld_stfld_soft_float () {
+ R4Holder h = new R4Holder ();
+ h.float_field = 3.14f;
+
+ if (h.float_field == 3.14f)
+ return 0;
+ else
+ return 1;
+ }
+
+ class R4HolderRemote : MarshalByRefObject {
+ public static float pi = 3.14f;
+
+ public float float_field;
+ }
+
+ static int test_0_ldfld_stfld_soft_float_remote () {
+ R4HolderRemote h = new R4HolderRemote ();
+ h.float_field = 3.14f;
+
+ if (h.float_field == 3.14f)
+ return 0;
+ else
+ return 1;
+ }
+
+ static int test_0_locals_soft_float () {
+ float f = 0.0f;
+
+ f = 3.14f;
+
+ if (f == 3.14f)
+ return 0;
+ else
+ return 1;
+ }
}