Skip to content

Fix creation of pointer arrays #79433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -658,14 +658,6 @@ public static RuntimeTypeHandle CreateEEType(TypeDesc type, TypeBuilderState sta

pTemplateEEType = templateTypeHandle.ToEETypePtr();
}
else if (type.IsMdArray || (type.IsSzArray && ((ArrayType)type).ElementType.IsPointer))
{
// Multidimensional arrays and szarrays of pointers don't implement generic interfaces and
// we don't need to do much for them in terms of type building. We can pretty much just take
// the MethodTable for any of those, massage the bits that matter (GCDesc, element type,
// component size,...) to be of the right shape and we're done.
pTemplateEEType = typeof(object[,]).TypeHandle.ToEETypePtr();
}
else
{
Debug.Assert(state.TemplateType != null && !state.TemplateType.RuntimeTypeHandle.IsNull());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public TypeDesc TemplateType
{
if (!_templateComputed)
{
// Multidimensional arrays and szarrays of pointers don't implement generic interfaces and are special cases. They use
// Multidimensional arrays don't implement generic interfaces and are special cases. They use
// typeof(object[,]) as their template.
if (TypeBeingBuilt.IsMdArray || (TypeBeingBuilt.IsSzArray && ((ArrayType)TypeBeingBuilt).ElementType.IsPointer))
if (TypeBeingBuilt.IsMdArray)
{
_templateType = TypeBeingBuilt.Context.ResolveRuntimeTypeHandle(typeof(object[,]).TypeHandle);
_templateTypeLoaderNativeLayout = false;
Expand All @@ -67,6 +67,17 @@ public TypeDesc TemplateType
return _templateType;
}

// Arrays of pointers don't implement generic interfaces and are special cases. They use
// typeof(char*[]) as their template.
if (TypeBeingBuilt.IsSzArray && ((ArrayType)TypeBeingBuilt).ElementType.IsPointer)
{
_templateType = TypeBeingBuilt.Context.ResolveRuntimeTypeHandle(typeof(char*[]).TypeHandle);
_templateTypeLoaderNativeLayout = false;
_nativeLayoutComputed = _nativeLayoutTokenComputed = _templateComputed = true;

return _templateType;
}

// Locate the template type and native layout info
_templateType = TemplateLocator.TryGetTypeTemplate(TypeBeingBuilt, ref _nativeLayoutInfo);
Debug.Assert(_templateType == null || !_templateType.RuntimeTypeHandle.IsNull());
Expand Down