Fix missing array ctor(int32,int32) test failures. (#34764)
authormonojenkins <jo.shields+jenkins@xamarin.com>
Wed, 15 Apr 2020 08:44:56 +0000 (04:44 -0400)
committerGitHub <noreply@github.com>
Wed, 15 Apr 2020 08:44:56 +0000 (10:44 +0200)
commitfdf812fe0faff670980f6f118987ddf1980c0b21
treef3ffd37cc6da4f9b6d7898b081f992db27ff7f6e
parentdd22ce809f235b40f20737b56458bacdb8ec2b46
Fix missing array ctor(int32,int32) test failures. (#34764)

According to ECMA, VES should add the following methods to arrays:

* A constructor that takes a sequence of int32 arguments, one for each dimension of the array, that specify the number of elements in each dimension beginning with the first dimension. A lower bound of zero is assumed.

* A constructor that takes twice as many int32 arguments as there are dimensions of the array. These arguments occur in pairs—one pair per dimension—with the first argument of each pair specifying the lower bound for that dimension, and the second argument specifying the total number of elements in that dimension.

* Get.

* Set.

* Address.

In Mono's case we only added the `ctor (int32, int32)` for rank 1 arrays if they were "jagged" array. Array with rank 1-4 executed an optimized code path always using the one int32 per rank constructor.

This doesn't work in cases where the array is constructed using both a length and a lower bound pattern, like:

`newobj instance void int32[10000...10005]::.ctor(int32, int32)`

this would trigger a method not found exception, since its not a jagged array, Mono wouldn't add the `ctor(int32, int32)` constructor for this type.

Fix will make sure we follow ECMA's definition of this and fix code to use right instance methods of arrays. Code also adds an assert to trap if a jagged array is created through this code path
(shouldn't happen) since current implementation would have handled it as
a 2 ranked array.

Fix also adds several tests into iltests.il allocating different variations of arrays using lower/upper bounds and validating length, rank, upper/lower bounds of allocated arrays.

Co-authored-by: lateralusX <lateralusX@users.noreply.github.com>
src/mono/mono/metadata/class-init.c
src/mono/mono/mini/iltests.il
src/mono/mono/mini/method-to-ir.c