From 3c0802e3335f03bd84d172015687c77716fab780 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Mon, 6 Jan 2025 10:56:31 -0800 Subject: [PATCH 1/2] JIT: handle nested try case in empty try removal When we remove a try region, the try entry block may still be a try entry for enclosing try regions, so we can't unconditionally drop the DONT_REMOVE flag. Fixes #110958 --- src/coreclr/jit/fgehopt.cpp | 8 +- .../JitBlue/Runtime_110958/Runtime_110985.cs | 80 +++++++++++++++++++ .../Runtime_110958/Runtime_110985.csproj | 12 +++ 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj diff --git a/src/coreclr/jit/fgehopt.cpp b/src/coreclr/jit/fgehopt.cpp index dce67ac1cf2e27..58ce06faf2c4e8 100644 --- a/src/coreclr/jit/fgehopt.cpp +++ b/src/coreclr/jit/fgehopt.cpp @@ -1037,9 +1037,13 @@ PhaseStatus Compiler::fgRemoveEmptyTryCatchOrTryFault() // fgRemoveEHTableEntry(XTnum); - // (6) The old try entry no longer needs special protection. + // (6) The old try entry may no longer needs special protection. + // (it may still be an entry of an enclosing try) // - firstTryBlock->RemoveFlags(BBF_DONT_REMOVE); + if (!bbIsTryBeg(firstTryBlock)) + { + firstTryBlock->RemoveFlags(BBF_DONT_REMOVE); + } // Another one bites the dust... emptyCount++; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.cs b/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.cs new file mode 100644 index 00000000000000..794b624e8194a0 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.cs @@ -0,0 +1,80 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Found by Antigen +// Reduced from 17.57 KB to 2.06 KB. + +using System.Collections.Generic; +using System.Runtime.Intrinsics.Arm; +using Xunit; + +public class Runtime_110958 +{ + long long_30 = 5; + ulong ulong_36 = 0; + SveMaskPattern SveMaskPattern_37 = SveMaskPattern.VectorCount1; + private static List toPrint = new List(); + private void Method0() + { + unchecked + { + ulong ulong_77 = 2; + SveMaskPattern SveMaskPattern_78 = SveMaskPattern_37; + try + { + try + { + ulong_36 -= ulong_77; + } + catch (System.FieldAccessException) + { } + catch (System.ExecutionEngineException) + { } + } + catch (System.RankException) + { + } + catch (System.MemberAccessException) + { + do + { + try + { + switch ((15 << 4) * long_30) + { + case -1: + { + break; + } + default: + { + break; + } + } + } + catch (System.InvalidProgramException) + { + } + catch (System.InvalidCastException) + { + } + } + while (15 < 4); + } + catch (System.AggregateException) + { + } + finally + { + } + return; + } + } + + [Fact] + public static void Problem0() + { + new Runtime_110958().Method0(); + } +} + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj new file mode 100644 index 00000000000000..3d380ffd215152 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj @@ -0,0 +1,12 @@ + + + True + + + + + + + + + From eb0792a9346c60723088210f8c6a3fcb65812e68 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Mon, 6 Jan 2025 13:02:09 -0800 Subject: [PATCH 2/2] review feedback --- src/coreclr/jit/fgehopt.cpp | 2 +- .../JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/fgehopt.cpp b/src/coreclr/jit/fgehopt.cpp index 58ce06faf2c4e8..54c0adcbdeb3ab 100644 --- a/src/coreclr/jit/fgehopt.cpp +++ b/src/coreclr/jit/fgehopt.cpp @@ -1037,7 +1037,7 @@ PhaseStatus Compiler::fgRemoveEmptyTryCatchOrTryFault() // fgRemoveEHTableEntry(XTnum); - // (6) The old try entry may no longer needs special protection. + // (6) The old try entry may no longer need special protection. // (it may still be an entry of an enclosing try) // if (!bbIsTryBeg(firstTryBlock)) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj index 3d380ffd215152..5ef196a0406c05 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj +++ b/src/tests/JIT/Regression/JitBlue/Runtime_110958/Runtime_110985.csproj @@ -1,6 +1,8 @@ True + + true