Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f5d8d52

Browse files
authored
Port fix for dotnet/runtime#32059 to release/3.1 (#28024)
If we're promoting a long field, make sure `compLongUsed` gets set. Otherwise we may fail to properly decompose a long later on, leading to access violations in the jit. See dotnet/runtime#32059 for the original bug report, and dotnet/runtime#32702 for the fix in 5.0. ## Customer Impact Unexpected and hard to diagnose crash in the jit. No easy workaround. ## Regression? Yes, introduced during the development 3.0 cycle. 2.x behaves correctly. ## Testing Verified the user's test case now passes; no diffs seen in any existing framework or test code. ## Risk **Low**: fix is surgical and enables existing long operand handling in the jit in one case that can be overlooked. Only impacts x86 and arm codegen. Problematic IL patterns may not be reachable from C#.
1 parent aaa1e0e commit f5d8d52

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

src/jit/lclvars.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,6 +2183,13 @@ void Compiler::StructPromotionHelper::PromoteStructVar(unsigned lclNum)
21832183
fieldVarDsc->lvFldOrdinal = pFieldInfo->fldOrdinal;
21842184
fieldVarDsc->lvParentLcl = lclNum;
21852185
fieldVarDsc->lvIsParam = varDsc->lvIsParam;
2186+
2187+
// This new local may be the first time we've seen a long typed local.
2188+
if (fieldVarDsc->lvType == TYP_LONG)
2189+
{
2190+
compiler->compLongUsed = true;
2191+
}
2192+
21862193
#if defined(_TARGET_AMD64_) || defined(_TARGET_ARM64_)
21872194

21882195
// Reset the implicitByRef flag.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
//
5+
6+
.assembly extern System.Runtime {}
7+
.assembly Runtime_32059 {}
8+
9+
.class private auto ansi beforefieldinit Runtime_32059 extends [System.Runtime]System.Object
10+
{
11+
12+
.method public hidebysig static int32 Main(string[] args) cil managed
13+
{
14+
.entrypoint
15+
.locals init (valuetype [System.Runtime]System.DateTime V_0)
16+
.maxstack 12
17+
ldarg.0
18+
ldnull
19+
ldnull
20+
ldnull
21+
ldnull
22+
ldnull
23+
ldnull
24+
ldnull
25+
ldloc.0
26+
ldc.i4.0
27+
ldnull
28+
newobj instance void Runtime_32059::.ctor(string[],
29+
string,
30+
string,
31+
string,
32+
string,
33+
string,
34+
string,
35+
string,
36+
valuetype [System.Runtime]System.DateTime,
37+
int32,
38+
string)
39+
tail.
40+
call instance int32 Runtime_32059::F()
41+
ret
42+
}
43+
44+
.method public specialname rtspecialname instance void .ctor(string[] o,
45+
string h,
46+
string g,
47+
string f,
48+
string e,
49+
string d,
50+
string c,
51+
string b,
52+
valuetype [System.Runtime]System.DateTime a,
53+
int32 pc,
54+
string current) cil managed noinlining
55+
{
56+
ldarg.0
57+
call instance void [System.Runtime]System.Object::.ctor()
58+
ret
59+
}
60+
61+
.method public hidebysig instance int32 F() cil managed noinlining
62+
{
63+
ldc.i4 100
64+
ret
65+
}
66+
}
67+
68+
69+
70+
71+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
8+
<SchemaVersion>2.0</SchemaVersion>
9+
<ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
10+
<OutputType>Exe</OutputType>
11+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
12+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
13+
</PropertyGroup>
14+
<!-- Default configurations to help VS understand the configurations -->
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "></PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "></PropertyGroup>
17+
<ItemGroup>
18+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
19+
<Visible>False</Visible>
20+
</CodeAnalysisDependentAssemblyPaths>
21+
</ItemGroup>
22+
<PropertyGroup>
23+
<DebugType>None</DebugType>
24+
<Optimize>True</Optimize>
25+
</PropertyGroup>
26+
<ItemGroup>
27+
<Compile Include="Runtime_32059.il" />
28+
</ItemGroup>
29+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
30+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup>
31+
</Project>

0 commit comments

Comments
 (0)