vineflower
vineflower copied to clipboard
QuiltFlower incorrectly decompiles stack values being reordered
Sorry for the awful title, I couldn't think of a better way to describe the issue. I noticed this when generating JVM bytecode for a project, I'm unsure if the Java compiler would output something like this naturally. This example conditionally changes the order of the current 3 values on the stack, swapping the first and last values. Here's a Jasmin example demonstrating this:
.class public com/example/Bug
.super java/lang/Object
.method private <init>()V
aload_0
invokespecial java/lang/Object/<init>()V
return
.end method
.method public static bugDemo(IIIZ)I
.limit stack 4
.limit locals 4
iload_0
iconst_2
imul
iload_1
iconst_2
imul
iload_2
iconst_2
imul
; Swap order of values on stack conditionally
iload_3
ifne Target
; Order is changed from 0, 1, 2 to 2, 1, 0
dup_x2
pop
swap
Target:
ineg
iadd
iadd
ireturn
.end method
...and the compiled .class file. And here's the decompiled output:
package com.example;
public class Bug {
private Bug() {
}
public static int bugDemo(int var0, int var1, int var2, boolean var3) {
int var10000 = var0 * 2;
int var10001 = var1 * 2;
int var10002 = var2 * 2;
if (!var3) {
var10001 = var10000;
var10000 = var10002;
var10002 = var10001;
}
return var10000 + var10001 + -var10002;
}
}
In the decompiled output when var3 is false, var10001 is incorrectly overwritten with the value of var10000. It should remain the same as it was before var10000 and var10002 are swapped.