未验证 提交 96f90e18 编写于 作者: S Skylot

fix: improve exception handlers attach

上级 8ff18e63
......@@ -390,15 +390,23 @@ public class BlockExceptionHandler {
private static BlockNode searchTopBlock(MethodNode mth, List<BlockNode> blocks) {
BlockNode top = BlockUtils.getTopBlock(blocks);
if (top != null) {
return top;
return adjustTopBlock(top);
}
BlockNode topDom = BlockUtils.getCommonDominator(mth, blocks);
if (topDom != null) {
return topDom;
return adjustTopBlock(topDom);
}
throw new JadxRuntimeException("Failed to find top block for try-catch from: " + blocks);
}
private static BlockNode adjustTopBlock(BlockNode topBlock) {
if (topBlock.getSuccessors().size() == 1 && !topBlock.contains(AType.EXC_CATCH)) {
// top block can be lifted by other exception handlers included in blocks list, trying to undo that
return topBlock.getSuccessors().get(0);
}
return topBlock;
}
@Nullable
private static BlockNode searchBottomBlock(MethodNode mth, List<BlockNode> blocks) {
// search common post-dominator block inside input set
......
......@@ -140,7 +140,7 @@ public class SSATransform extends AbstractVisitor {
stack.push(initState);
while (!stack.isEmpty()) {
RenameState state = stack.pop();
renameVarsInBlock(state);
renameVarsInBlock(mth, state);
for (BlockNode dominated : state.getBlock().getDominatesOn()) {
stack.push(RenameState.copyFrom(state, dominated));
}
......@@ -156,7 +156,7 @@ public class SSATransform extends AbstractVisitor {
}
}
private static void renameVarsInBlock(RenameState state) {
private static void renameVarsInBlock(MethodNode mth, RenameState state) {
BlockNode block = state.getBlock();
for (InsnNode insn : block.getInstructions()) {
if (insn.getType() != InsnType.PHI) {
......@@ -168,8 +168,9 @@ public class SSATransform extends AbstractVisitor {
int regNum = reg.getRegNum();
SSAVar var = state.getVar(regNum);
if (var == null) {
throw new JadxRuntimeException("Not initialized variable reg: " + regNum
+ ", insn: " + insn + ", block:" + block);
// TODO: in most cases issue in incorrectly attached exception handlers
mth.addWarnComment("Not initialized variable reg: " + regNum + ", insn: " + insn + ", block:" + block);
var = state.startVar(reg);
}
var.use(reg);
}
......
......@@ -55,7 +55,6 @@ public class TestTryCatchFinally8 extends IntegrationTest {
}
@Test
@NotYetImplemented
public void test2() {
disableCompilation();
ClassNode cls = getClassNode(TestCls.class);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册