+
+ // Sign extension tests
+ // 0x55 == 85 == 01010101
+ // 0xAA == 170 == 10101010
+ // 0x5555 == 21845 == 0101010101010101
+ // 0xAAAA == 43690 == 1010101010101010
+ // 0x55555555 == 1431655765
+ // 0xAAAAAAAA == 2863311530
+ // 0x5555555555555555 == 6148914691236517205
+ // 0xAAAAAAAAAAAAAAAA == 12297829382473034410
+
+ public interface SEFace<T> {
+ T Copy (int a, int b, int c, int d, T t);
+ }
+
+ class SEClass<T> : SEFace<T> {
+ public T Copy (int a, int b, int c, int d, T t) {
+ return t;
+ }
+ }
+
+ // Test extension
+ static int test_20_signextension_sbyte () {
+ Type t = typeof (sbyte);
+ object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+ var i = (SEFace<sbyte>)o;
+
+ long zz = i.Copy (1,2,3,4,(sbyte)(-0x55));
+
+ bool success = zz == -0x55;
+ return success ? 20 : 1;
+ }
+
+ static int test_20_signextension_byte () {
+ Type t = typeof (byte);
+ object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+ var i = (SEFace<byte>)o;
+
+ ulong zz = i.Copy (1,2,3,4,(byte)(0xAA));
+
+ bool success = zz == 0xAA;
+ return success ? 20 : 1;
+ }
+
+ static int test_20_signextension_short () {
+ Type t = typeof (short);
+ object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+ var i = (SEFace<short>)o;
+
+ long zz = i.Copy (1,2,3,4,(short)(-0x5555));
+
+ bool success = zz == -0x5555;
+ return success ? 20 : 1;
+ }
+
+ static int test_20_signextension_ushort () {
+ Type t = typeof (ushort);
+ object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+ var i = (SEFace<ushort>)o;
+
+ ulong zz = i.Copy (1,2,3,4,(ushort)(0xAAAA));
+
+ bool success = zz == 0xAAAA;
+ return success ? 20 : 1;
+ }
+
+ static int test_20_signextension_int () {
+ Type t = typeof (int);
+ object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+ var i = (SEFace<int>)o;
+
+ long zz = i.Copy (1,2,3,4,(int)(-0x55555555));
+
+ bool success = zz == -0x55555555;
+ return success ? 20 : 1;
+ }
+
+ static int test_20_signextension_uint () {
+ Type t = typeof (uint);
+ object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+ var i = (SEFace<uint>)o;
+
+ ulong zz = i.Copy (1,2,3,4,(uint)(0xAAAAAAAA));
+
+ bool success = zz == 0xAAAAAAAA;
+ return success ? 20 : 1;
+ }
+
+ static int test_20_signextension_long () {
+ Type t = typeof (long);
+ object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+ var i = (SEFace<long>)o;
+
+ long zz = i.Copy (1,2,3,4,(long)(-0x5555555555555555));
+
+ bool success = zz == -0x5555555555555555;
+ return success ? 20 : 1;
+ }
+
+ static int test_20_signextension_ulong () {
+ Type t = typeof (ulong);
+ object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t }));
+ var i = (SEFace<ulong>)o;
+
+ ulong zz = i.Copy (1,2,3,4,(ulong)(0xAAAAAAAAAAAAAAAA));
+
+ bool success = zz == 0xAAAAAAAAAAAAAAAA;
+ return success ? 20 : 1;
+ }
+
+ void gsharedvt_try_at_offset_0<T> (ref T disposable)
+ where T : class, IDisposable {
+ try {
+ disposable.Dispose ();
+ } finally {
+ disposable = null;
+ }
+ }
+
+ [MethodImplAttribute (MethodImplOptions.NoInlining)]
+ static DateTimeOffset gsharedvt_vphi_inner<T> (T t) {
+ return DateTimeOffset.MinValue;
+ }
+
+ static DateTimeOffset gsharedvt_vphi<T> (T t) {
+ int[] arr = new int [10];
+
+ try {
+ DateTimeOffset v;
+ if (arr [0] == 0)
+ v = gsharedvt_vphi_inner (t);
+ else
+ v = gsharedvt_vphi_inner (t);
+ return v;
+ } catch {
+ return DateTimeOffset.MinValue;
+ }
+ }
+
+ static int test_0_gsharedvt_vphi_volatile () {
+ gsharedvt_vphi (0);
+ return 0;
+ }
+
+ struct AStruct3<T1, T2, T3> {
+ T1 t1;
+ T2 t2;
+ T3 t3;
+ }
+
+ interface IFaceIsRef {
+ bool is_ref<T> ();
+ }
+
+ class ClassIsRef : IFaceIsRef {
+ [MethodImplAttribute (MethodImplOptions.NoInlining)]
+ public bool is_ref<T> () {
+ return RuntimeHelpers.IsReferenceOrContainsReferences<T> ();
+ }
+ }
+
+ public static int test_0_isreference_intrins () {
+ IFaceIsRef iface = new ClassIsRef ();
+ if (iface.is_ref<AStruct3<int, int, int>> ())
+ return 1;
+ if (!iface.is_ref<AStruct3<string, int, int>> ())
+ return 2;
+ return 0;
+ }