diff --git a/src/coreclr/jit/fgehopt.cpp b/src/coreclr/jit/fgehopt.cpp index 3c9d99d8609bf6..423579f0ad17de 100644 --- a/src/coreclr/jit/fgehopt.cpp +++ b/src/coreclr/jit/fgehopt.cpp @@ -930,8 +930,8 @@ PhaseStatus Compiler::fgRemoveEmptyTryCatchOrTryFault() if (HBtab->HasFilter()) { BasicBlock* const firstFltBlock = HBtab->ebdFilter; - assert(firstFltBlock->bbRefs == 1); - firstFltBlock->bbRefs = 0; + assert(firstFltBlock->bbRefs >= 1); + firstFltBlock->bbRefs -= 1; BasicBlock* const afterLastFltBlock = HBtab->BBFilterLast()->Next(); // Must do this in two passes to handle loops or lexically @@ -955,8 +955,8 @@ PhaseStatus Compiler::fgRemoveEmptyTryCatchOrTryFault() // (3) Remove any handler blocks. // The first handler block has an artificial ref count // - assert(firstHndBlock->bbRefs == 1); - firstHndBlock->bbRefs = 0; + assert(firstHndBlock->bbRefs >= 1); + firstHndBlock->bbRefs -= 1; BasicBlock* const afterLastHndBlock = lastHndBlock->Next(); // Must do this in two passes to handle loops or lexically diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_133101/Runtime_133101.cs b/src/tests/JIT/Regression/JitBlue/Runtime_133101/Runtime_133101.cs new file mode 100644 index 00000000000000..49831f35bed59f --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_133101/Runtime_133101.cs @@ -0,0 +1,42 @@ +// 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; +using Xunit; + +namespace Runtime_133101; + +public class Runtime_133101 +{ + [Fact] + public static void TestEntryPoint() + { + Assert.Equal(4, LoopInTryAndFinally(3)); + } + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static long LoopInTryAndFinally(long a) + { + long x = a; + try + { + L1: + if ((x & 8) != 0) + { + x += 4; + goto L1; + } + } + finally + { + L2: + if ((x & 1) != 0) + { + x += 1; + goto L2; + } + } + + return x; + } +} diff --git a/src/tests/JIT/Regression/Regression_ro_2.csproj b/src/tests/JIT/Regression/Regression_ro_2.csproj index a6bdb64234975f..fc4053062f98d9 100644 --- a/src/tests/JIT/Regression/Regression_ro_2.csproj +++ b/src/tests/JIT/Regression/Regression_ro_2.csproj @@ -136,6 +136,7 @@ +