diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index dcf1fd4c619ad5..31fe8c0b4ac186 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -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); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_76051/Runtime_76051.cs b/src/tests/JIT/Regression/JitBlue/Runtime_76051/Runtime_76051.cs new file mode 100644 index 00000000000000..c95666b0f834c4 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_76051/Runtime_76051.cs @@ -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); +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_76051/Runtime_76051.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_76051/Runtime_76051.csproj new file mode 100644 index 00000000000000..0f9eec3d705fb2 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_76051/Runtime_76051.csproj @@ -0,0 +1,10 @@ + + + Exe + True + True + + + + + \ No newline at end of file