leibnitz27 / cfr

This is the public repository for the CFR Java decompiler
https://www.benf.org/other/cfr
MIT License
2.01k stars 258 forks source link

Decompiling while-true loop fails #220

Closed nitram84 closed 3 years ago

nitram84 commented 3 years ago

CFR version

CFR 0.151-SNAPSHOT (bc71426) and CFR 0.150, so this is not a regression of recent changes

Compiler

openjdk8, openjdk11

Description

Decompiling the following loop fails:

Example

public class CfrTest1 {
  private int i;

  public int doSomething() {
    while (true) {
      if (i <= 1) {
        doSomething2();
        if (i == 0) {
          break;
        }
      }

      if (i >= 41) {
        doSomething2();
        if (i == 42) {
          return 1;
        }
      }
    }
    return 0;
  }

  private void doSomething2() {
  }
}

This example can be used for the cfr test suite.

leibnitz27 commented 3 years ago

Thanks. Annoyingly (or amusingly, natch), it's possible to get this right without lifting returns to the jump site, so the default decompilation looks a little weird with the labelled block.

Might consider lifting jumps always if they only have one source....