Skip to content

Commit

Permalink
JIT: Fix ACD updates when a non-enclosing EH region is removed (dotne…
Browse files Browse the repository at this point in the history
…t#110374)

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 dotnet#110346.
  • Loading branch information
AndyAyersMS authored and mikelle-rogers committed Dec 4, 2024
1 parent 8a325ee commit 84cf224
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/coreclr/jit/fgehopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
//
Expand All @@ -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
Expand All @@ -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).
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 84cf224

Please sign in to comment.