Skip to content

Commit 032e8db

Browse files
authored
JIT: make sure to set compLongUsed during struct promotion (#32702)
If we're promoting a long field, make sure `compLongUsed` gets set. Otherwise we may fail to properly decompose a long later on. Fixes #32059.
1 parent 1905bde commit 032e8db

File tree

3 files changed

+96
-4
lines changed

3 files changed

+96
-4
lines changed

src/coreclr/src/jit/lclvars.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,7 @@ bool Compiler::StructPromotionHelper::TryPromoteStructField(lvaStructFieldInfo&
21032103
//
21042104
void Compiler::StructPromotionHelper::PromoteStructVar(unsigned lclNum)
21052105
{
2106-
LclVarDsc* varDsc = &compiler->lvaTable[lclNum];
2106+
LclVarDsc* varDsc = compiler->lvaGetDesc(lclNum);
21072107

21082108
// We should never see a reg-sized non-field-addressed struct here.
21092109
assert(!varDsc->lvRegStruct);
@@ -2167,11 +2167,13 @@ void Compiler::StructPromotionHelper::PromoteStructVar(unsigned lclNum)
21672167
#endif
21682168

21692169
// Lifetime of field locals might span multiple BBs, so they must be long lifetime temps.
2170-
unsigned varNum = compiler->lvaGrabTemp(false DEBUGARG(bufp));
2170+
const unsigned varNum = compiler->lvaGrabTemp(false DEBUGARG(bufp));
21712171

2172-
varDsc = &compiler->lvaTable[lclNum]; // lvaGrabTemp can reallocate the lvaTable
2172+
// lvaGrabTemp can reallocate the lvaTable, so
2173+
// refresh the cached varDsc for lclNum.
2174+
varDsc = compiler->lvaGetDesc(lclNum);
21732175

2174-
LclVarDsc* fieldVarDsc = &compiler->lvaTable[varNum];
2176+
LclVarDsc* fieldVarDsc = compiler->lvaGetDesc(varNum);
21752177
fieldVarDsc->lvType = pFieldInfo->fldType;
21762178
fieldVarDsc->lvExactSize = pFieldInfo->fldSize;
21772179
fieldVarDsc->lvIsStructField = true;
@@ -2180,6 +2182,13 @@ void Compiler::StructPromotionHelper::PromoteStructVar(unsigned lclNum)
21802182
fieldVarDsc->lvFldOrdinal = pFieldInfo->fldOrdinal;
21812183
fieldVarDsc->lvParentLcl = lclNum;
21822184
fieldVarDsc->lvIsParam = varDsc->lvIsParam;
2185+
2186+
// This new local may be the first time we've seen a long typed local.
2187+
if (fieldVarDsc->lvType == TYP_LONG)
2188+
{
2189+
compiler->compLongUsed = true;
2190+
}
2191+
21832192
#if defined(TARGET_AMD64) || defined(TARGET_ARM64)
21842193

21852194
// 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk.IL">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
</PropertyGroup>
5+
<PropertyGroup>
6+
<DebugType>None</DebugType>
7+
<Optimize>True</Optimize>
8+
</PropertyGroup>
9+
<ItemGroup>
10+
<Compile Include="$(MSBuildProjectName).il" />
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)