diff --git a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs index 20e5377e27323..9e44b2ec46ab2 100644 --- a/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs +++ b/src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs @@ -565,7 +565,7 @@ private static unsafe int CreateArrayGCDesc(LowLevelList bitfield, int ran { if (numSeries > 0) { - *ptr-- = (short)((bitfield.Count - last + baseOffset - 2) * IntPtr.Size); + *ptr-- = (short)((bitfield.Count - last) * IntPtr.Size); *ptr-- = numPtrs; *(void**)gcdesc = (void*)-numSeries; diff --git a/src/tests/nativeaot/SmokeTests/DynamicGenerics/B282745.cs b/src/tests/nativeaot/SmokeTests/DynamicGenerics/B282745.cs index dada3d9fdea7a..7e9ea6ae78d43 100644 --- a/src/tests/nativeaot/SmokeTests/DynamicGenerics/B282745.cs +++ b/src/tests/nativeaot/SmokeTests/DynamicGenerics/B282745.cs @@ -125,6 +125,54 @@ public static void testMDArrayWithPointerLikeValuesOfKnownStructType() GenericType.test(); } + struct SomeGenStruct1 + { + public T o; + public int i; + public long l; + public long l1; + } + + public class GenericType1 + { + public static void test() + { + int[] lengths = { 42, 2, 3 }; + SomeGenStruct1[,,] array = (SomeGenStruct1[,,])Array.CreateInstance(typeof(SomeGenStruct1), lengths); + + for (int i = 0; i < 42; i++) + { + array[i,0,0].o = default(T); + array[i,0,0].i = GetIntPtrOnHeapAsInt(); + array[i,0,0].l = GetIntPtrOnHeapAsInt(); + + array[i,1,2].o = default(T); + array[i,1,2].i = GetIntPtrOnHeapAsInt(); + array[i,1,2].l = GetIntPtrOnHeapAsLong(); + + array[i,1,1].o = default(T); + array[i,1,1].i = GetIntPtrOnHeapAsInt(); + array[i,1,1].l = GetIntPtrOnHeapAsLong(); + } + + GC.Collect(); + + GC.KeepAlive(array); + + RuntimeTypeHandle arrayTypeHandle = array.GetType().TypeHandle; +#if INTERNAL_CONTRACTS + Assert.IsTrue(RuntimeAugments.IsDynamicType(arrayTypeHandle)); +#endif + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + [TestMethod] + public static void testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType() + { + GenericType1.test(); + } + [MethodImpl(MethodImplOptions.NoInlining)] [TestMethod] public static void testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType() diff --git a/src/tests/nativeaot/SmokeTests/DynamicGenerics/DynamicGenerics.main.cs b/src/tests/nativeaot/SmokeTests/DynamicGenerics/DynamicGenerics.main.cs index 483cbdf1ac506..ea5682578b439 100644 --- a/src/tests/nativeaot/SmokeTests/DynamicGenerics/DynamicGenerics.main.cs +++ b/src/tests/nativeaot/SmokeTests/DynamicGenerics/DynamicGenerics.main.cs @@ -144,6 +144,7 @@ public static int Main(string[] args) new CoreFXTestLibrary.Internal.TestInfo("B282745.testIntMDArrayWithPointerLikeValues", () => global::B282745.testIntMDArrayWithPointerLikeValues(), null), new CoreFXTestLibrary.Internal.TestInfo("B282745.testLongMDArrayWithPointerLikeValues", () => global::B282745.testLongMDArrayWithPointerLikeValues(), null), new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfKnownStructType", () => global::B282745.testMDArrayWithPointerLikeValuesOfKnownStructType(), null), +new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType", () => global::B282745.testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType(), null), new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType", () => global::B282745.testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType(), null), new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfUnknownStructPrimitiveType", () => global::B282745.testMDArrayWithPointerLikeValuesOfUnknownStructPrimitiveType(), null), new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWith3Dimensions", () => global::B282745.testMDArrayWith3Dimensions(), null),