Commit d10efec1 authored by Skylot's avatar Skylot

core: fix type for one time used args

parent 3f08c99f
...@@ -473,7 +473,7 @@ public class InsnDecoder { ...@@ -473,7 +473,7 @@ public class InsnDecoder {
case Opcodes.ARRAY_LENGTH: { case Opcodes.ARRAY_LENGTH: {
InsnNode node = new InsnNode(InsnType.ARRAY_LENGTH, 1); InsnNode node = new InsnNode(InsnType.ARRAY_LENGTH, 1);
node.setResult(InsnArg.reg(insn, 0, ArgType.INT)); node.setResult(InsnArg.reg(insn, 0, ArgType.INT));
node.addArg(InsnArg.reg(insn, 1, ArgType.unknown(PrimitiveType.ARRAY))); node.addArg(InsnArg.reg(insn, 1, ArgType.array(ArgType.UNKNOWN)));
return node; return node;
} }
......
...@@ -54,7 +54,6 @@ public class ConstInlinerVisitor extends AbstractVisitor { ...@@ -54,7 +54,6 @@ public class ConstInlinerVisitor extends AbstractVisitor {
private static boolean replaceConst(MethodNode mth, BlockNode block, InsnNode insn, long literal) { private static boolean replaceConst(MethodNode mth, BlockNode block, InsnNode insn, long literal) {
List<InsnArg> use = insn.getResult().getTypedVar().getUseList(); List<InsnArg> use = insn.getResult().getTypedVar().getUseList();
int replace = 0; int replace = 0;
for (InsnArg arg : use) { for (InsnArg arg : use) {
InsnNode useInsn = arg.getParentInsn(); InsnNode useInsn = arg.getParentInsn();
...@@ -64,9 +63,15 @@ public class ConstInlinerVisitor extends AbstractVisitor { ...@@ -64,9 +63,15 @@ public class ConstInlinerVisitor extends AbstractVisitor {
BlockNode useBlock = BlockUtils.getBlockByInsn(mth, useInsn); BlockNode useBlock = BlockUtils.getBlockByInsn(mth, useInsn);
if (useBlock == block || useBlock.isDominator(block)) { if (useBlock == block || useBlock.isDominator(block)) {
if (arg != insn.getResult() && !registerReassignOnPath(block, useBlock, insn)) { if (arg != insn.getResult() && !registerReassignOnPath(block, useBlock, insn)) {
LiteralArg litArg;
if (use.size() == 2) {
// arg used only in one place
litArg = InsnArg.lit(literal, arg.getType());
} else {
// in most cases type not equal arg.getType() // in most cases type not equal arg.getType()
// just set unknown type and run type fixer // just set unknown type and run type fixer
LiteralArg litArg = InsnArg.lit(literal, ArgType.UNKNOWN); litArg = InsnArg.lit(literal, ArgType.UNKNOWN);
}
if (useInsn.replaceArg(arg, litArg)) { if (useInsn.replaceArg(arg, litArg)) {
fixTypes(mth, useInsn, litArg); fixTypes(mth, useInsn, litArg);
replace++; replace++;
......
package jadx.tests.internal;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
public class TestWrongCode extends InternalJadxTest {
public static class TestCls {
private int f() {
int[] a = null;
return a.length;
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
assertThat(code, not(containsString("return false.length;")));
assertThat(code, containsString("return null.length;"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment