Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 0 additions & 5 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4196,11 +4196,6 @@ mini_field_access_needs_cctor_run (MonoCompile *cfg, MonoMethod *method, MonoCla
return FALSE;
}

if (mono_class_is_before_field_init (klass)) {
if (cfg->method == method)
return FALSE;
}

if (!mono_class_needs_cctor_run (klass, method))
return FALSE;

Expand Down
42 changes: 42 additions & 0 deletions src/tests/JIT/Methodical/beforefieldinit/StaticFieldInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;

static class C
{
public static int retVal = 100;
[MethodImpl(MethodImplOptions.NoInlining)]
public static int TestMethod(bool cond)
{
if (cond)
{
// never invoked in this program
return ClassB.X;
}
// always taken
return 0;
}
}

public class ClassB
{
public static readonly int X = GetX();

static int GetX()
{
Console.WriteLine("GetX call!..."); // not expected to be invoked in this program
C.retVal = 42;
return 42;
}
}

public class StaticFieldInit
{
public static int Main () {
C.TestMethod(false);

return C.retVal;
}
}
13 changes: 13 additions & 0 deletions src/tests/JIT/Methodical/beforefieldinit/StaticFieldInit.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<PropertyGroup>
<DebugType>PdbOnly</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="StaticFieldInit.cs" />
</ItemGroup>
</Project>