-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: Fix ordering of type initialization and stsfld (#80485)
Insertion of the type initializer before the tree for a stsfld could reorder them inappropriately. This includes those computation in the spill check. Fixes #72354.
- Loading branch information
Showing
3 changed files
with
84 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/tests/Loader/classloader/TypeInitialization/CctorsWithSideEffects/CctorForWrite.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Showed a JIT importer bug where a tree would be constructed for | ||
// call / stsfld and then the type initialization call inserted before | ||
// the entire tree. The call needs to happen before type initialization. | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
|
||
public class CorrectException : Exception | ||
{ | ||
} | ||
|
||
public class CCC | ||
{ | ||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static int Call() => throw new CorrectException(); | ||
|
||
public static int Main() | ||
{ | ||
try | ||
{ | ||
ClassWithCctor.StaticField = Call(); | ||
} | ||
catch (CorrectException) | ||
{ | ||
return 100; | ||
} | ||
catch | ||
{ | ||
} | ||
return 1; | ||
} | ||
} | ||
|
||
class ClassWithCctor | ||
{ | ||
public static int StaticField; | ||
static ClassWithCctor() => throw new Exception(); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/tests/Loader/classloader/TypeInitialization/CctorsWithSideEffects/CctorForWrite.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
</Project> |