Skip to content

Commit 1a9f573

Browse files
authored
JIT: Use gtCloneExpr in fgMorphModToSubMulDiv for potentially complex trees (#76061)
We may get here for any invariant dividend/divisor but these can be 'complex' address-of trees that gtClone does not handle. Fix #76051
1 parent 4b11a2e commit 1a9f573

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/coreclr/jit/morph.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13598,8 +13598,8 @@ GenTree* Compiler::fgMorphModToSubMulDiv(GenTreeOp* tree)
1359813598
GenTree* dividend = div->IsReverseOp() ? opB : opA;
1359913599
GenTree* divisor = div->IsReverseOp() ? opA : opB;
1360013600

13601-
div->gtOp1 = gtClone(dividend);
13602-
div->gtOp2 = gtClone(divisor);
13601+
div->gtOp1 = gtCloneExpr(dividend);
13602+
div->gtOp2 = gtCloneExpr(divisor);
1360313603

1360413604
var_types type = div->gtType;
1360513605
GenTree* const mul = gtNewOperNode(GT_MUL, type, div, divisor);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
4+
using System.Runtime.CompilerServices;
5+
6+
public class Runtime_76051
7+
{
8+
public static int Main(string[] args)
9+
{
10+
GetIndex(1);
11+
return 100;
12+
}
13+
14+
// This tests an assertion failure (debug)/segfault (release) in
15+
// fgMorphModToSubMulDiv due to the use of gtClone that fails for the
16+
// complex tree seen for the address-of expression.
17+
[MethodImpl(MethodImplOptions.NoInlining)]
18+
static unsafe int GetIndex(uint cellCount) => (int)((ulong)&cellCount % cellCount);
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<Optimize>True</Optimize>
5+
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="$(MSBuildProjectName).cs" />
9+
</ItemGroup>
10+
</Project>

0 commit comments

Comments
 (0)