-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix spill check for struct lclVars #23570
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10624,11 +10624,22 @@ void Compiler::impImportBlockCode(BasicBlock* block) | |
SPILL_APPEND: | ||
|
||
// We need to call impSpillLclRefs() for a struct type lclVar. | ||
// This is done for non-block assignments in the handling of stloc. | ||
if ((op1->OperGet() == GT_ASG) && varTypeIsStruct(op1->gtOp.gtOp1) && | ||
(op1->gtOp.gtOp1->gtOper == GT_LCL_VAR)) | ||
if ((op1->OperGet() == GT_ASG) && varTypeIsStruct(op1->gtGetOp1())) | ||
{ | ||
impSpillLclRefs(op1->gtOp.gtOp1->AsLclVarCommon()->gtLclNum); | ||
GenTree* lhs = op1->gtGetOp1(); | ||
GenTreeLclVarCommon* lclVar = nullptr; | ||
if (lhs->gtOper == GT_LCL_VAR) | ||
{ | ||
lclVar = lhs->AsLclVarCommon(); | ||
} | ||
else if (lhs->OperIsBlk()) | ||
{ | ||
lclVar = lhs->AsBlk()->Addr()->IsLocalAddrExpr(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think you're right. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having spent some time on this, I'm fairly certain that this only needs to handle full assignments. The I gave some thought to whether an assert could be added, but I was unable to do so. So, I'm actually going to simplify this check. |
||
} | ||
if (lclVar != nullptr) | ||
{ | ||
impSpillLclRefs(lclVar->gtLclNum); | ||
} | ||
} | ||
|
||
/* Append 'op1' to the list of statements */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GitHub_23545 | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
public struct TestStruct | ||
{ | ||
public int value1; | ||
|
||
public override string ToString() | ||
{ | ||
return this.value1.ToString(); | ||
} | ||
} | ||
|
||
class Test | ||
{ | ||
public static Dictionary<TestStruct, TestStruct> StructKeyValue | ||
{ | ||
get | ||
{ | ||
return new Dictionary<TestStruct, TestStruct>() | ||
{ | ||
{ | ||
new TestStruct(){value1 = 12}, new TestStruct(){value1 = 15} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
static int Main() | ||
{ | ||
int value = 0; | ||
foreach (var e in StructKeyValue) | ||
{ | ||
value += e.Key.value1 + e.Value.value1; | ||
Console.WriteLine(e.Key.ToString() + " " + e.Value.ToString()); | ||
} | ||
if (value != 27) | ||
{ | ||
return -1; | ||
} | ||
return 100; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Release</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<AssemblyName>$(MSBuildProjectName)</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<DebugType></DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> | ||
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "></PropertyGroup> | ||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to also describe why we need to spill in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, will do.