Skip to content
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

[mono] When creating an array type, don't do full initialization of the element type #85828

Merged
merged 4 commits into from
May 22, 2023
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
6 changes: 4 additions & 2 deletions src/mono/mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,8 +1183,10 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound

mono_class_setup_supertypes (klass);

if (mono_class_is_ginst (eclass))
mono_class_init_internal (eclass);
// NOTE: this is probably too aggressive if eclass is not a valuetype. It looks like we
// only need the size info in order to set MonoClass:has_references for this array type -
// and for that we only need to setup the fields of the element type if it's not a reference
// type.
if (!eclass->size_inited)
mono_class_setup_fields (eclass);
mono_class_set_type_load_failure_causedby_class (klass, eclass, "Could not load array element type");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Compile Include="repro.cs" />
</ItemGroup>
</Project>
53 changes: 53 additions & 0 deletions src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;

/* Regression test for https://github.com/dotnet/runtime/issues/85821
* ensure that self-referencing generic instances are initialized correctly and don't TLE
*/

public class Program
{
public static int Main()
{
var test = typeof(Node<double>);
var fit = test.GetField("Children").FieldType;
if (fit == null)
return 101;

var test2 = typeof(Node2<int>);
var fit2 = test2.GetField("Children").FieldType;
if (fit2 == null)
return 102;

var test3 = typeof(NodeVT<double>);
var fit3 = test3.GetField("Children").FieldType;
if (fit3 == null)
return 103;

var test4 = typeof(NodeVT2<int>);
var fit4 = test4.GetField("Children").FieldType;
if (fit4 == null)
return 104;

return 100;
}
}

public class Node<T>
{
public Node<T>[] Children;
}

public class Node2<T>
{
public Node2<T>[][] Children;
}

public struct NodeVT<T>
{
public NodeVT<T>[] Children;
}

public struct NodeVT2<T>
{
public NodeVT2<T>[][] Children;
}