vineflower icon indicating copy to clipboard operation
vineflower copied to clipboard

Decompiler straight up deletes a large portion of code

Open jaskarth opened this issue 2 years ago • 2 comments

This: https://gist.github.com/jaskarth/d6b169d2aa7c0304b14c2b5e98ac0b08 Outputs this:

public class TestTemp {
   public void test() {
      float vvv1 = 124.01F;// 7
      Object var10000 = new Object();
      Objects.requireNonNull(var10000);// 8
      int[][][] var2 = (int[][][])var10000;
   }// 20 29 57
}

It's literally just gone. I don't know how or why.

jaskarth avatar Jun 08 '22 10:06 jaskarth

Doing a mini post mortem on this, mainly because it's such a gruesome bug caused by a completely unrelated piece of code. So, dear viewer, you may be asking, how on earth did this happen? Essentially, switch statements have a list internally of all of the case statements. This is important for tracking which case blocks correspond to which case bodies, as each body can have multiple case blocks. Notably, when a switch is empty, it'll have an empty case statement list. However, it'll still internally contain a break- even though this is simplified out by the end, it's still there internally as an important part of the statement graph. This is where the inline single blocks comes in- it helps inline breaks, as many breaks created by the control flow graph structurizer are nonsensical and don't really happen in regular java code. So, it saw that this empty switch had a break to an if statement, so it ended up trying to trying to inline that break, which was catastrophic as the switch statement had no case statements, so the inlined if statement couldn't actually go anywhere, and as a result dropped off the face of the earth. A rather interesting case of how multiple systems that don't usually relate to each other can sometimes interact to produce an explosive result, and why working on a decompiler can be difficult at times 😄

This bug was fixed by making sure that statements wouldn't try to inline into empty switches, in 81049f61.

jaskarth avatar Jun 25 '22 16:06 jaskarth

Found another one: https://gist.github.com/jaskarth/c495702fa9b59ba49be70368a0fadd24

jaskarth avatar Jul 31 '22 16:07 jaskarth