Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] JIT: Fix segfault for modulo computations involving address-of expressions #76171

Merged
merged 3 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13494,8 +13494,8 @@ GenTree* Compiler::fgMorphModToSubMulDiv(GenTreeOp* tree)
GenTree* dividend = div->IsReverseOp() ? opB : opA;
GenTree* divisor = div->IsReverseOp() ? opA : opB;

div->gtOp1 = gtClone(dividend);
div->gtOp2 = gtClone(divisor);
div->gtOp1 = gtCloneExpr(dividend);
div->gtOp2 = gtCloneExpr(divisor);

var_types type = div->gtType;
GenTree* const mul = gtNewOperNode(GT_MUL, type, div, divisor);
Expand Down
19 changes: 19 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_76051/Runtime_76051.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;

public class Runtime_76051
{
public static int Main(string[] args)
{
GetIndex(1);
return 100;
}

// This tests an assertion failure (debug)/segfault (release) in
// fgMorphModToSubMulDiv due to the use of gtClone that fails for the
// complex tree seen for the address-of expression.
[MethodImpl(MethodImplOptions.NoInlining)]
static unsafe int GetIndex(uint cellCount) => (int)((ulong)&cellCount % cellCount);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>