Skip to content

Commit 8199d0a

Browse files
Fix creation of pointer arrays (#79433)
Creation of pointer arrays is on a similar plan to multi-dim arrays - we create them from a template type, but the template is slightly wrong. Previously, EETypeCreator would massage the bits into the correct shape, but now we mostly just copy the bits from the template. Use a more precise template for pointer arrays. Without this, the base size and element type of pointer arrays was slightly wrong. I'm also deleting the duplicated "use a special template for this one" logic.
1 parent d76ddf3 commit 8199d0a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,6 @@ public static RuntimeTypeHandle CreateEEType(TypeDesc type, TypeBuilderState sta
658658

659659
pTemplateEEType = templateTypeHandle.ToEETypePtr();
660660
}
661-
else if (type.IsMdArray || (type.IsSzArray && ((ArrayType)type).ElementType.IsPointer))
662-
{
663-
// Multidimensional arrays and szarrays of pointers don't implement generic interfaces and
664-
// we don't need to do much for them in terms of type building. We can pretty much just take
665-
// the MethodTable for any of those, massage the bits that matter (GCDesc, element type,
666-
// component size,...) to be of the right shape and we're done.
667-
pTemplateEEType = typeof(object[,]).TypeHandle.ToEETypePtr();
668-
}
669661
else
670662
{
671663
Debug.Assert(state.TemplateType != null && !state.TemplateType.RuntimeTypeHandle.IsNull());

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public TypeDesc TemplateType
5656
{
5757
if (!_templateComputed)
5858
{
59-
// Multidimensional arrays and szarrays of pointers don't implement generic interfaces and are special cases. They use
59+
// Multidimensional arrays don't implement generic interfaces and are special cases. They use
6060
// typeof(object[,]) as their template.
61-
if (TypeBeingBuilt.IsMdArray || (TypeBeingBuilt.IsSzArray && ((ArrayType)TypeBeingBuilt).ElementType.IsPointer))
61+
if (TypeBeingBuilt.IsMdArray)
6262
{
6363
_templateType = TypeBeingBuilt.Context.ResolveRuntimeTypeHandle(typeof(object[,]).TypeHandle);
6464
_templateTypeLoaderNativeLayout = false;
@@ -67,6 +67,17 @@ public TypeDesc TemplateType
6767
return _templateType;
6868
}
6969

70+
// Arrays of pointers don't implement generic interfaces and are special cases. They use
71+
// typeof(char*[]) as their template.
72+
if (TypeBeingBuilt.IsSzArray && ((ArrayType)TypeBeingBuilt).ElementType.IsPointer)
73+
{
74+
_templateType = TypeBeingBuilt.Context.ResolveRuntimeTypeHandle(typeof(char*[]).TypeHandle);
75+
_templateTypeLoaderNativeLayout = false;
76+
_nativeLayoutComputed = _nativeLayoutTokenComputed = _templateComputed = true;
77+
78+
return _templateType;
79+
}
80+
7081
// Locate the template type and native layout info
7182
_templateType = TemplateLocator.TryGetTypeTemplate(TypeBeingBuilt, ref _nativeLayoutInfo);
7283
Debug.Assert(_templateType == null || !_templateType.RuntimeTypeHandle.IsNull());

0 commit comments

Comments
 (0)