Skip to content

Commit 0a3fb4c

Browse files
VSadovjkotas
andauthored
[NativeAOT] Fix MD array GC series (#86877)
* Fix MD array GC series * add a test Co-authored-by: Jan Kotas <[email protected]>
1 parent da01301 commit 0a3fb4c

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/coreclr/nativeaot/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ private static unsafe int CreateArrayGCDesc(LowLevelList<bool> bitfield, int ran
565565
{
566566
if (numSeries > 0)
567567
{
568-
*ptr-- = (short)((bitfield.Count - last + baseOffset - 2) * IntPtr.Size);
568+
*ptr-- = (short)((bitfield.Count - last) * IntPtr.Size);
569569
*ptr-- = numPtrs;
570570

571571
*(void**)gcdesc = (void*)-numSeries;

src/tests/nativeaot/SmokeTests/DynamicGenerics/B282745.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,54 @@ public static void testMDArrayWithPointerLikeValuesOfKnownStructType()
125125
GenericType<object>.test();
126126
}
127127

128+
struct SomeGenStruct1<T>
129+
{
130+
public T o;
131+
public int i;
132+
public long l;
133+
public long l1;
134+
}
135+
136+
public class GenericType1<T>
137+
{
138+
public static void test()
139+
{
140+
int[] lengths = { 42, 2, 3 };
141+
SomeGenStruct1<T>[,,] array = (SomeGenStruct1<T>[,,])Array.CreateInstance(typeof(SomeGenStruct1<T>), lengths);
142+
143+
for (int i = 0; i < 42; i++)
144+
{
145+
array[i,0,0].o = default(T);
146+
array[i,0,0].i = GetIntPtrOnHeapAsInt();
147+
array[i,0,0].l = GetIntPtrOnHeapAsInt();
148+
149+
array[i,1,2].o = default(T);
150+
array[i,1,2].i = GetIntPtrOnHeapAsInt();
151+
array[i,1,2].l = GetIntPtrOnHeapAsLong();
152+
153+
array[i,1,1].o = default(T);
154+
array[i,1,1].i = GetIntPtrOnHeapAsInt();
155+
array[i,1,1].l = GetIntPtrOnHeapAsLong();
156+
}
157+
158+
GC.Collect();
159+
160+
GC.KeepAlive(array);
161+
162+
RuntimeTypeHandle arrayTypeHandle = array.GetType().TypeHandle;
163+
#if INTERNAL_CONTRACTS
164+
Assert.IsTrue(RuntimeAugments.IsDynamicType(arrayTypeHandle));
165+
#endif
166+
}
167+
}
168+
169+
[MethodImpl(MethodImplOptions.NoInlining)]
170+
[TestMethod]
171+
public static void testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType()
172+
{
173+
GenericType1<object>.test();
174+
}
175+
128176
[MethodImpl(MethodImplOptions.NoInlining)]
129177
[TestMethod]
130178
public static void testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType()

src/tests/nativeaot/SmokeTests/DynamicGenerics/DynamicGenerics.main.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public static int Main(string[] args)
144144
new CoreFXTestLibrary.Internal.TestInfo("B282745.testIntMDArrayWithPointerLikeValues", () => global::B282745.testIntMDArrayWithPointerLikeValues(), null),
145145
new CoreFXTestLibrary.Internal.TestInfo("B282745.testLongMDArrayWithPointerLikeValues", () => global::B282745.testLongMDArrayWithPointerLikeValues(), null),
146146
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfKnownStructType", () => global::B282745.testMDArrayWithPointerLikeValuesOfKnownStructType(), null),
147+
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType", () => global::B282745.testMDArrayWithPointerLikeValuesOfKnownStructTypeLargerType(), null),
147148
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType", () => global::B282745.testMDArrayWithPointerLikeValuesOfUnknownStructReferenceType(), null),
148149
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWithPointerLikeValuesOfUnknownStructPrimitiveType", () => global::B282745.testMDArrayWithPointerLikeValuesOfUnknownStructPrimitiveType(), null),
149150
new CoreFXTestLibrary.Internal.TestInfo("B282745.testMDArrayWith3Dimensions", () => global::B282745.testMDArrayWith3Dimensions(), null),

0 commit comments

Comments
 (0)