@@ -799,14 +799,24 @@ unsigned Compiler::ehGetMostNestedRegionIndex(BasicBlock* block, bool* inTryRegi
799
799
return mostNestedRegion;
800
800
}
801
801
802
- /*****************************************************************************
803
- * Returns the try index of the enclosing try, skipping all EH regions with the
804
- * same try region (that is, all 'mutual protect' regions). If there is no such
805
- * enclosing try, returns EHblkDsc::NO_ENCLOSING_INDEX.
806
- */
802
+ //-------------------------------------------------------------
803
+ // ehTrueEnclosingTryIndexIL: find the outermost enclosing try
804
+ // region that is not a mutual-protect try
805
+ //
806
+ // Arguments:
807
+ // regionIndex - index of interest
808
+ //
809
+ // Returns:
810
+ // Index of enclosng non-mutual protect try region, or EHblkDsc::NO_ENCLOSING_INDEX.
811
+ //
812
+ // Notes:
813
+ // Only safe to use during importation, before we have normalize the
814
+ // EH in the flow graph. Post importation use, the non-IL version.
815
+ //
807
816
unsigned Compiler::ehTrueEnclosingTryIndexIL(unsigned regionIndex)
808
817
{
809
818
assert(regionIndex != EHblkDsc::NO_ENCLOSING_INDEX);
819
+ assert(!fgImportDone);
810
820
811
821
EHblkDsc* ehDscRoot = ehGetDsc(regionIndex);
812
822
EHblkDsc* HBtab = ehDscRoot;
@@ -832,6 +842,49 @@ unsigned Compiler::ehTrueEnclosingTryIndexIL(unsigned regionIndex)
832
842
return regionIndex;
833
843
}
834
844
845
+ //-------------------------------------------------------------
846
+ // ehTrueEnclosingTryIndex: find the closest enclosing try
847
+ // region that is not a mutual-protect try
848
+ //
849
+ // Arguments:
850
+ // regionIndex - index of interest
851
+ //
852
+ // Returns:
853
+ // Index of enclosng non-mutual protect try region, or EHblkDsc::NO_ENCLOSING_INDEX.
854
+ //
855
+ // Notes:
856
+ // Only safe to use after importation, once we have normalized the
857
+ // EH in the flow graph. For importation, use the IL version.
858
+ //
859
+ unsigned Compiler::ehTrueEnclosingTryIndex(unsigned regionIndex)
860
+ {
861
+ assert(regionIndex != EHblkDsc::NO_ENCLOSING_INDEX);
862
+ assert(fgImportDone);
863
+
864
+ EHblkDsc* ehDscRoot = ehGetDsc(regionIndex);
865
+ EHblkDsc* HBtab = ehDscRoot;
866
+
867
+ for (;;)
868
+ {
869
+ regionIndex = HBtab->ebdEnclosingTryIndex;
870
+ if (regionIndex == EHblkDsc::NO_ENCLOSING_INDEX)
871
+ {
872
+ // No enclosing 'try'; we're done
873
+ break;
874
+ }
875
+
876
+ HBtab = ehGetDsc(regionIndex);
877
+ if (!EHblkDsc::ebdIsSameTry(ehDscRoot, HBtab))
878
+ {
879
+ // Found an enclosing 'try' that has a different 'try' region (is not mutually-protect with the
880
+ // original region). Return it.
881
+ break;
882
+ }
883
+ }
884
+
885
+ return regionIndex;
886
+ }
887
+
835
888
unsigned Compiler::ehGetEnclosingRegionIndex(unsigned regionIndex, bool* inTryRegion)
836
889
{
837
890
assert(regionIndex != EHblkDsc::NO_ENCLOSING_INDEX);
@@ -3614,8 +3667,8 @@ void Compiler::fgVerifyHandlerTab()
3614
3667
// on the block.
3615
3668
for (XTnum = 0, HBtab = compHndBBtab; XTnum < compHndBBtabCount; XTnum++, HBtab++)
3616
3669
{
3617
- unsigned enclosingTryIndex = ehTrueEnclosingTryIndexIL (XTnum); // find the true enclosing try index,
3618
- // ignoring 'mutual protect' trys
3670
+ unsigned enclosingTryIndex = ehTrueEnclosingTryIndex (XTnum); // find the true enclosing try index,
3671
+ // ignoring 'mutual protect' trys
3619
3672
if (enclosingTryIndex != EHblkDsc::NO_ENCLOSING_INDEX)
3620
3673
{
3621
3674
// The handler funclet for 'XTnum' has a try index of 'enclosingTryIndex' (at least, the parts of the
0 commit comments