Skip to content

Commit b7251c7

Browse files
author
Meghana Gupta
committed
Fix region asserts for Leaves converted to Br in non exception finally region
Mark Leaves converted to Br in non excpetion finally region with m_leaveConvToBr bit on BranchInstr in DBG builds, so that FlowGraph::Destroy asserts correctly for such branches
1 parent b6a9d9d commit b7251c7

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/Backend/FlowGraph.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ FlowGraph::Build(void)
515515
Assert(currentLabel->GetRegion()->GetMatchingTryRegion()->GetMatchingFinallyRegion(false) == currentLabel->GetRegion());
516516
// Convert Leave to Br because we execute non-excepting Finally in native code
517517
instr->m_opcode = Js::OpCode::Br;
518+
#if DBG
519+
instr->AsBranchInstr()->m_leaveConvToBr = true;
520+
#endif
518521
}
519522
}
520523
else if (instr->m_opcode == Js::OpCode::Finally)
@@ -1724,18 +1727,22 @@ FlowGraph::Destroy(void)
17241727
Assert(region->GetType() == RegionTypeTry || region->GetType() == RegionTypeCatch || region->GetType() == RegionTypeFinally);
17251728
break;
17261729
case Js::OpCode::Br:
1727-
if (region->GetType() == RegionTypeCatch && region != predRegion)
1730+
if (predBlock->GetLastInstr()->AsBranchInstr()->m_leaveConvToBr)
1731+
{
1732+
// Leave converted to Br in finally region
1733+
AssertMsg(region == predRegion->GetParent(), "Bad region prop in finally");
1734+
}
1735+
else if (region->GetType() == RegionTypeCatch && region != predRegion)
17281736
{
17291737
AssertMsg(predRegion->GetType() == RegionTypeTry, "Bad region type for the try");
17301738
}
17311739
else if (region->GetType() == RegionTypeFinally && region != predRegion)
17321740
{
1733-
// When we add edge from finally to early exit, and break block removal moves the edge into finally region, we can end up with an edge between finally and non eh region
1741+
AssertMsg(predRegion->GetType() == RegionTypeTry, "Bad region type for the try");
17341742
}
17351743
else
17361744
{
1737-
// Leave's within non excepting finallys that are not early exit edges are converted to br
1738-
AssertMsg((predRegion->IsNonExceptingFinally() && region == predRegion->GetParent()) || region == predRegion, "Bad region propagation through interior block");
1745+
AssertMsg(region == predRegion, "Bad region propagation through interior block");
17391746
}
17401747
break;
17411748
default:

lib/Backend/IR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ class BranchInstr : public Instr
739739
#if DBG
740740
bool m_isMultiBranch;
741741
bool m_isHelperToNonHelperBranch;
742+
bool m_leaveConvToBr;
742743
#endif
743744

744745
public:
@@ -751,6 +752,7 @@ class BranchInstr : public Instr
751752
{
752753
#if DBG
753754
m_isMultiBranch = false;
755+
m_leaveConvToBr = false;
754756
#endif
755757
}
756758

0 commit comments

Comments
 (0)