diff --git a/src/coreclr/jit/utils.cpp b/src/coreclr/jit/utils.cpp index ac7674d70ca7d9..98e11c71ff371b 100644 --- a/src/coreclr/jit/utils.cpp +++ b/src/coreclr/jit/utils.cpp @@ -1727,7 +1727,7 @@ void HelperCallProperties::init() case CORINFO_HELP_INITCLASS: case CORINFO_HELP_INITINSTCLASS: - isPure = true; + mutatesHeap = true; mayRunCctor = true; break; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_121066/Runtime_121066.cs b/src/tests/JIT/Regression/JitBlue/Runtime_121066/Runtime_121066.cs new file mode 100644 index 00000000000000..5b8426c2e0ea80 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_121066/Runtime_121066.cs @@ -0,0 +1,100 @@ +// 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; +using Xunit; + +public class Runtime_121066 +{ + public static int preciseInitCctorsRun = 0; + + class MyPreciseInitClass + { + static MyPreciseInitClass() + { + preciseInitCctorsRun++; + } + + public static void TriggerCctorClass() + { + } + + public static void TriggerCctorMethod() + { } + } + + class MyClass + { + static Type staticVarType = typeof(MyClass); + public Type GetTypeOf() + { + return typeof(MyClass); + } + public static Type GetTypeOfStatic() + { + return typeof(MyClass); + } + + public static Type GetTypeThroughStaticVar() + { + return staticVarType; + } + } + + [Fact] + public static void TestEntryPoint() + { + Assert.True(TestPreciseInitCctors()); + } + + public static bool TestPreciseInitCctors() + { + if (preciseInitCctorsRun != 0) + { + Console.WriteLine("preciseInitCctorsRun should be 0, but is {0}", preciseInitCctorsRun); + return false; + } + MyPreciseInitClass.TriggerCctorClass(); + if (preciseInitCctorsRun != 1) + { + Console.WriteLine("preciseInitCctorsRun should be 1, but is {0}", preciseInitCctorsRun); + return false; + } + MyPreciseInitClass.TriggerCctorMethod(); + if (preciseInitCctorsRun != 2) + { + Console.WriteLine("TriggerCctorClass should return 2, but is {0}", preciseInitCctorsRun); + return false; + } + + object o = new MyPreciseInitClass(); + if (preciseInitCctorsRun != 3) + { + Console.WriteLine("TriggerCctorClass should return 3, but is {0}", preciseInitCctorsRun); + return false; + } + + MyPreciseInitClass.TriggerCctorClass(); + if (preciseInitCctorsRun != 4) + { + Console.WriteLine("preciseInitCctorsRun should be 4 but is {0}", preciseInitCctorsRun); + return false; + } + MyPreciseInitClass.TriggerCctorMethod(); + if (preciseInitCctorsRun != 5) + { + Console.WriteLine("TriggerCctorClass should return 5, but is {0}", preciseInitCctorsRun); + return false; + } + + o = new MyPreciseInitClass(); + if (preciseInitCctorsRun != 6) + { + Console.WriteLine("TriggerCctorClass should return 6, but is {0}", preciseInitCctorsRun); + return false; + } + + return true; + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_121066/Runtime_121066.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_121066/Runtime_121066.csproj new file mode 100644 index 00000000000000..7488f34a9b11ac --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_121066/Runtime_121066.csproj @@ -0,0 +1,12 @@ + + + None + True + + true + + + + + +