Commit 33c5e082 authored by Skylot's avatar Skylot

core: always check arguments before inline

parent cbd36aeb
......@@ -87,7 +87,8 @@ public class CodeShrinker extends AbstractVisitor {
}
public WrapInfo checkInline(int assignPos, RegisterArg arg) {
if (assignPos >= inlineBorder || !canMove(assignPos, inlineBorder)) {
if (!arg.isThis()
&& (assignPos >= inlineBorder || !canMove(assignPos, inlineBorder))) {
return null;
}
inlineBorder = assignPos;
......@@ -205,13 +206,9 @@ public class CodeShrinker extends AbstractVisitor {
}
int assignPos = insnList.getIndex(assignInsn);
if (assignPos != -1) {
if (assignInsn.canReorder()) {
wrapList.add(argsInfo.inline(assignPos, arg));
} else {
WrapInfo wrapInfo = argsInfo.checkInline(assignPos, arg);
if (wrapInfo != null) {
wrapList.add(wrapInfo);
}
WrapInfo wrapInfo = argsInfo.checkInline(assignPos, arg);
if (wrapInfo != null) {
wrapList.add(wrapInfo);
}
} else {
// another block
......
package jadx.tests.internal.inline;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static jadx.tests.utils.JadxMatchers.countString;
import static org.junit.Assert.assertThat;
public class TestInlineInLoop extends InternalJadxTest {
public static class TestCls {
public static void main(String[] args) throws Exception {
int a = 0;
int b = 4;
int c = 0;
while (a < 12) {
if (b + a < 9 && b < 8) {
if (b >= 2 && a > -1 && b < 6) {
System.out.println("OK");
c = b + 1;
}
c = b;
}
c = b;
b++;
b = c;
a++;
}
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsOne("int c"));
assertThat(code, containsOne("c = b + 1"));
assertThat(code, countString(2, "c = b;"));
assertThat(code, containsOne("b++;"));
assertThat(code, containsOne("b = c"));
assertThat(code, containsOne("a++;"));
}
}
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