fix: handle xor on boolean (#921)

This commit is contained in:
Skylot
2020-09-13 21:58:06 +01:00
parent 60b2353afe
commit 1bbcac2ab3
3 changed files with 105 additions and 9 deletions
@@ -0,0 +1,40 @@
package jadx.tests.integration.types;
import org.junit.jupiter.api.Test;
import jadx.tests.api.SmaliTest;
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
/**
* Issue 921 (second case)
*/
public class TestTypeResolver15 extends SmaliTest {
public static class TestCls {
private void test(boolean z) {
useInt(z ? 0 : 8);
useInt(!z ? 1 : 0); // replaced with xor in smali test
}
private void useInt(int i) {
}
}
@Test
public void test() {
noDebugInfo();
assertThat(getClassNode(TestCls.class))
.code()
// .containsOne("useInt(!z ? 1 : 0);") // TODO: convert to ternary
.containsOne("useInt(z ? 0 : 8);");
}
@Test
public void testSmali() {
assertThat(getClassNodeFromSmali())
.code()
.containsOne("useInt(z ? 0 : 8);")
.containsOne("useInt(!z ? 1 : 0);");
}
}
@@ -0,0 +1,27 @@
.class public Ltypes/TestTypeResolver15;
.super Ljava/lang/Object;
.method private test(Z)V
.locals 2
if-eqz p1, :cond_0
const/4 v1, 0x0
goto :goto_0
:cond_0
const/16 v1, 0x8
:goto_0
invoke-virtual {p0, v1}, Ltypes/TestTypeResolver15;->useInt(I)V
xor-int/lit8 p1, p1, 0x1
invoke-virtual {p0, p1}, Ltypes/TestTypeResolver15;->useInt(I)V
return-void
.end method
.method private useInt(I)V
.registers 2
return-void
.end method