diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index ed49402b9db54a..260cc7d918249c 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -11160,10 +11160,19 @@ GenTree* Compiler::fgPropagateCommaThrow(GenTree* parent, GenTreeOp* commaThrow, } // Fix up the COMMA's type if needed. - if (genActualType(parent) != genActualType(commaThrow)) + var_types parentType = genActualType(parent); + if (parentType != genActualType(commaThrow)) { - commaThrow->gtGetOp2()->BashToZeroConst(genActualType(parent)); - commaThrow->ChangeType(genActualType(parent)); + if (parentType == TYP_STRUCT) + { + return nullptr; + } + + GenTree* zero = gtNewZeroConNode(parentType); + zero->SetMorphed(this); + + commaThrow->gtOp2 = zero; + commaThrow->ChangeType(parentType); } return commaThrow; diff --git a/src/tests/JIT/Regression_o_2/Runtime_133862.cs b/src/tests/JIT/Regression_o_2/Runtime_133862.cs new file mode 100644 index 00000000000000..1b267778a55007 --- /dev/null +++ b/src/tests/JIT/Regression_o_2/Runtime_133862.cs @@ -0,0 +1,29 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.CompilerServices; +using Xunit; + +public class Runtime_133862 +{ + private struct S + { + public int A; + public int B; + public int C; + public int D; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static int Index(long value) => checked((int)value); + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static S Load(S[] values) => values[Index(long.MaxValue)]; + + [Fact] + public static void TestEntryPoint() + { + Assert.Throws(() => Load(new S[4])); + } +}