fgRemoveEmptyFinally disabled on ARM32
The EH model on ARM requires requires predecessors to have been computed in order to sucessfully leave the bit unset for cases where there are multiple CALLFINALLY / BBJ_ALWAYS pairs that point to the same finally target.
The following example demonstrates the problem.
-------------------------------------------------------------------------------------------------------------------------------------
BBnum descAddr ref try hnd weight [IL range] [jump] [EH region] [flags]
-------------------------------------------------------------------------------------------------------------------------------------
BB01 [06172A40] 1 0 1 [000..00D)-> BB03 ( cond ) T0 try { keep i try label
BB02 [06172AF0] 1 0 1 [00D..00F)-> BB08 (callf ) T0 i
BB11 [06175168] 0 0 1 [???..???)-> BB09 (ALWAYS) T0 i internal KEEP
BB03 [06172BA0] 1 0 1 [00F..016)-> BB07 ( cond ) T0 i
BB04 [06172C50] 1 0 1 [016..022)-> BB07 ( cond ) T0 i
BB05 [06172D00] 1 0 1 [022..02F)-> BB07 ( cond ) T0 i
BB06 [06172DB0] 1 0 1 [02F..035) T0 i
BB07 [06172E60] 4 0 1 [035..037)-> BB08 (callf ) T0 i
BB10 [06173D94] 0 0 1 [???..???)-> BB09 (ALWAYS) T0 } i internal KEEP
BB08 [06172F10] 1 0 1 [037..03E) (finret) H0 finally { } keep i label target
BB09 [06172FC0] 2 1 [03E..03F) (return) i ftarget
-------------------------------------------------------------------------------------------------------------------------------------
*************** Exception Handling table
index eTry, eHnd
0 :: - Try at BB01..BB10 [000..037), Finally at BB08..BB08 [037..03E)
EH#0 has empty finally, removing the region.
fgRemoveBlock BB11
Removing unreachable BB11
fgRemoveBlock BB10
Removing unreachable BB10
EH#0: New last block of try: BB07
/cc: @mskvortsov @YongseopKim
Couple of thoughts on how to fix this:
-
Keep with the current practice of setting the flag in the importer. Have the finally optimizations toggle a flag if they modify any finallys. If the flag is set, run a cleanup phase after they've run to reset the finally target flag appropriately.
-
Stop setting the bit early and bothering to maintain it... instead when we're lowering the callfinally block and setting up to pass the continuation, flag the continuation block so it gets lowered properly too.
Option 2 will require a prepass since there is no guarantee that in block order, a given continuation block comes after all corresponding callfinally/always pairs. So codegen might run across the continuation first. We might as well go with option 1 and just fix the bit there...