Merge pull request #5608 from mono/xcode9_bockbuild_fix
[mono.git] / mono / mini / arrays.cs
index 65606e0d2b2e90403dbe9a77d332055f0d5095ef..00a3c6b901f86a6b0c92e4b9a2993dbb447f3e78 100644 (file)
@@ -23,11 +23,18 @@ using System.Reflection;
  * the IL code looks.
  */
 
-class Tests {
-
-       static int Main () {
-               return TestDriver.RunTests (typeof (Tests));
-       }
+#if __MOBILE__
+class ArrayTests
+#else
+class Tests
+#endif
+{
+
+#if !__MOBILE__
+       public static int Main (string[] args) {
+               return TestDriver.RunTests (typeof (Tests), args);
+       }
+#endif
        
        public static int test_10_create () {
                int[] a = new int [10];
@@ -101,30 +108,31 @@ class Tests {
                return 0;
        }
 
-       private Int32[] m_array = new int [10];
-       
-       void setBit (int bitIndex, bool value) {
-               int index = bitIndex/32;
-               int shift = bitIndex%32;
+       class BitClass {
+               private Int32[] m_array = new int [10];
 
-               Int32 theBit = 1 << shift;
-               if (value)
-                       m_array[index] |= theBit;
-               else
-                       m_array[index] &= ~theBit;
-       }
-       
-       bool getBit (int bitIndex) {
-               int index = bitIndex/32;
-               int shift = bitIndex%32;
+               public void setBit (int bitIndex, bool value) {
+                       int index = bitIndex/32;
+                       int shift = bitIndex%32;
 
-               Int32 theBit = m_array[index] & (1 << shift);
-               return (theBit == 0) ? false : true;
+                       Int32 theBit = 1 << shift;
+                       if (value)
+                               m_array[index] |= theBit;
+                       else
+                               m_array[index] &= ~theBit;
+               }
+       
+               public bool getBit (int bitIndex) {
+                       int index = bitIndex/32;
+                       int shift = bitIndex%32;
 
+                       Int32 theBit = m_array[index] & (1 << shift);
+                       return (theBit == 0) ? false : true;
+               }
        }
        
        public static int test_1_bit_index () {
-               Tests t = new Tests ();
+               var t = new BitClass ();
                t.setBit (0, true);
                t.setBit (3, true);
                if (t.getBit (1))
@@ -434,6 +442,14 @@ class Tests {
                if (sum != 1800)
                        return 12;
 
+               /* Null check */
+               object[,] a13 = null;
+               try {
+                       a13 [0, 0] = new Object ();
+                       return 13;
+               } catch (NullReferenceException) {
+               }
+
                return 0;
        }
 
@@ -444,6 +460,13 @@ class Tests {
                return test [1, 1, 1];
        }
 
+       public static int test_100_4_dimensional_arrays () {
+        int[,,,] test = new int[10, 10, 10, 10];
+
+               test [1, 1, 1, 1] = 100;
+               return test [1, 1, 1, 1];
+       }
+
        public static int test_0_bug_71454 () {
                int[,] a = new int[4,4];
                int[,] b = new int[4,4];
@@ -484,10 +507,13 @@ class Tests {
                return y;
        }
 
+       class RefClass {
+       }
+
        public static int test_0_stelem_ref_null_opt () {
-               object[] arr = new Tests [1];
+               object[] arr = new RefClass [1];
 
-               arr [0] = new Tests ();
+               arr [0] = new RefClass ();
                arr [0] = null;
 
                return arr [0] == null ? 0 : 1;
@@ -719,7 +745,7 @@ class Tests {
                return 0;
        }
 
-       public static int long_indices () {
+       public static int test_0_long_indices () {
                int[] arr = new int [10];
                int[,] arr2 = new int [10, 10];
                long index = 1;
@@ -731,6 +757,55 @@ class Tests {
                        return 2;
                return 0;
        }
+
+       // #7438
+       public static int test_0_ldelema_2_64bit () {
+        bool[,] test = new bool[201,201];
+        int x,y;
+        for(x=-100;x<100;x++) for(y=-100;y<100;y++){
+            test[x+100,y+100] = true;
+        }
+               return 0;
+       }
+
+       static bool alloc_long (long l) {
+               try {
+                       var arr = new byte[l];
+                       return false;
+               } catch (Exception e) {
+                       return true;
+               }
+       }
+
+       // #13544
+       public static int test_0_newarr_ovf () {
+               if (!alloc_long (5000000000))
+                       return 1;
+               if (!alloc_long (4000000000))
+                       return 2;
+               if (!alloc_long (-1))
+                       return 3;
+               if (!alloc_long (-4000000000))
+                       return 4;
+               if (!alloc_long (-6000000000))
+                       return 5;
+               return 0;
+       }
+
+       static int llvm_ldlen_licm (int[] arr) {
+               int sum = 0;
+               // The ldlen should be moved out of the loop
+               for (int i = 0; i < arr.Length; ++i)
+                       sum += arr [i];
+               return sum;
+       }
+
+       public static int test_10_llvm_ldlen_licm () {
+               int[] arr = new int [10];
+               for (int i = 0; i < 10; ++i)
+                       arr [i] = 1;
+               return llvm_ldlen_licm (arr);
+       }
 }