From 841f20c6c7e566c140501c9ad640f6d1797dd082 Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Tue, 3 Dec 2024 13:02:27 -0800 Subject: [PATCH] JIT: Fix ACD updates when a non-enclosing EH region is removed When an EH region is removed, the JIT must make suitable updates to any existing AddCodeDescs (ACDs). We were missing logic for the case where the removed region was not the enclosing region of the ACD. Fixes #110346. We still need to adjust the try/handler index --- src/coreclr/jit/fgehopt.cpp | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/coreclr/jit/fgehopt.cpp b/src/coreclr/jit/fgehopt.cpp index a7dc42d20b2859..ebb6d03a1a1133 100644 --- a/src/coreclr/jit/fgehopt.cpp +++ b/src/coreclr/jit/fgehopt.cpp @@ -297,18 +297,15 @@ void Compiler::fgUpdateACDsBeforeEHTableEntryRemoval(unsigned XTnum) // AddCodeDscKey oldKey(add); - const bool inHnd = add->acdHndIndex > 0; - const bool inTry = add->acdTryIndex > 0; - const bool inThisHnd = - inHnd && ((unsigned)(add->acdHndIndex - 1) == XTnum) && (add->acdKeyDsg == AcdKeyDesignator::KD_HND); - const bool inThisFlt = - inHnd && ((unsigned)(add->acdHndIndex - 1) == XTnum) && (add->acdKeyDsg == AcdKeyDesignator::KD_FLT); - const bool inThisTry = - inTry && ((unsigned)(add->acdTryIndex - 1) == XTnum) && (add->acdKeyDsg == AcdKeyDesignator::KD_TRY); + const bool inHnd = add->acdHndIndex > 0; + const bool inTry = add->acdTryIndex > 0; + const bool inThisHnd = inHnd && ((unsigned)(add->acdHndIndex - 1) == XTnum); + const bool inThisFlt = inHnd && ((unsigned)(add->acdHndIndex - 1) == XTnum); + const bool inThisTry = inTry && ((unsigned)(add->acdTryIndex - 1) == XTnum); // If this ACD is in the filter of this region, it is no longer needed // - if (inThisFlt) + if (inThisFlt && (add->acdKeyDsg == AcdKeyDesignator::KD_FLT)) { bool const removed = map->Remove(oldKey); assert(removed); @@ -326,6 +323,8 @@ void Compiler::fgUpdateACDsBeforeEHTableEntryRemoval(unsigned XTnum) continue; } + bool rekey = false; + // If this ACD is in the handler of this region, update the // enclosing handler index. // @@ -339,6 +338,8 @@ void Compiler::fgUpdateACDsBeforeEHTableEntryRemoval(unsigned XTnum) { add->acdHndIndex = ebd->ebdEnclosingHndIndex + 1; } + + rekey = (add->acdKeyDsg == AcdKeyDesignator::KD_HND); } // If this ACD is in the try of this region, update the @@ -354,6 +355,17 @@ void Compiler::fgUpdateACDsBeforeEHTableEntryRemoval(unsigned XTnum) { add->acdTryIndex = ebd->ebdEnclosingTryIndex + 1; } + rekey = (add->acdKeyDsg == AcdKeyDesignator::KD_TRY); + } + + if (!rekey) + { + // If we didn't change the enclosing region for the ACD, + // the modifications above didn't change the key. + // + JITDUMP("ACD%u non-enclosing region updated; key remains the same\n", add->acdNum); + JITDUMPEXEC(add->Dump()); + continue; } // Update the ACD key designator (note it may change). @@ -388,7 +400,7 @@ void Compiler::fgUpdateACDsBeforeEHTableEntryRemoval(unsigned XTnum) { // If not, re-enter this ACD in the map with the updated key // - JITDUMP("ACD%u updated\n", add->acdNum); + JITDUMP("ACD%u updated with new key\n", add->acdNum); map->Set(newKey, add); JITDUMPEXEC(add->Dump()); }