Skip to content

Commit 5ce4140

Browse files
authored
JIT: fix issue with assertion prop on isinst helpers (dotnet#23056)
For calls to isinst helpers, morph may rearrange the order of args on the late arg list, so examine the operands to ensure the right ones are passed into the assertion creation code. Added simplified test case. Closes #23039.
1 parent b792272 commit 5ce4140

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

src/jit/assertionprop.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1989,11 +1989,23 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
19891989
op2 = op1->gtCall.gtCallLateArgs->gtOp.gtOp2;
19901990
op1 = op1->gtCall.gtCallLateArgs;
19911991

1992+
// For the assertion, ensure op1 is the object being tested.
1993+
// Morph may have swizzled the operand order.
1994+
GenTree* op1op = op1->gtOp.gtOp1;
1995+
1996+
if (op1op->TypeGet() == TYP_I_IMPL)
1997+
{
1998+
jitstd::swap(op1, op2);
1999+
op1op = op1->gtOp.gtOp1;
2000+
}
2001+
2002+
assert(op1op->TypeGet() == TYP_REF);
2003+
19922004
// Reverse the assertion
19932005
assert(assertionKind == OAK_EQUAL || assertionKind == OAK_NOT_EQUAL);
19942006
assertionKind = (assertionKind == OAK_EQUAL) ? OAK_NOT_EQUAL : OAK_EQUAL;
19952007

1996-
if (op1->gtOp.gtOp1->gtOper == GT_LCL_VAR)
2008+
if (op1op->OperIs(GT_LCL_VAR))
19972009
{
19982010
return optCreateJtrueAssertions(op1, op2, assertionKind);
19992011
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
.assembly extern mscorlib
6+
{
7+
}
8+
9+
.assembly GitHub_23039
10+
{
11+
}
12+
13+
// Bug where assertion prop was tripped up because morph swapped arg
14+
// order on an isinst helper call that fed into a conditional jump,
15+
// and the object being queried was null.
16+
17+
.class public auto ansi beforefieldinit X`1<T> extends [mscorlib]System.Object
18+
{
19+
.method public static hidebysig int32 F() cil managed noinlining
20+
{
21+
.locals init ([0] object)
22+
ldloc.0
23+
isinst class X`1<!T>
24+
brtrue IS
25+
ldc.i4 100
26+
ret
27+
IS: ldc.i4 -1
28+
ret
29+
}
30+
}
31+
32+
.class public auto ansi beforefieldinit Y extends [mscorlib]System.Object
33+
{
34+
.method public static hidebysig int32 Main() cil managed
35+
{
36+
.entrypoint
37+
call int32 class X`1<object>::F()
38+
ret
39+
}
40+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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' ">
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
18+
</PropertyGroup>
19+
<ItemGroup>
20+
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
21+
<Visible>False</Visible>
22+
</CodeAnalysisDependentAssemblyPaths>
23+
</ItemGroup>
24+
<PropertyGroup>
25+
<DebugType>None</DebugType>
26+
<Optimize>True</Optimize>
27+
</PropertyGroup>
28+
<ItemGroup>
29+
<Compile Include="GitHub_23039.il" />
30+
</ItemGroup>
31+
<ItemGroup>
32+
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
33+
</ItemGroup>
34+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
35+
<PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
36+
</PropertyGroup>
37+
</Project>

0 commit comments

Comments
 (0)