soot-oss / SootUp

A new version of Soot with a completely overhauled architecture
https://soot-oss.github.io/SootUp/
GNU Lesser General Public License v2.1
546 stars 66 forks source link

Source code frontend invokes constructor of non-static inner class improperly #108

Open cbruegg opened 5 years ago

cbruegg commented 5 years ago

The following method:

public void doAllThis() {
  InnerClassAA a = this;
  AA aa = new AA();
  aa = a.new AA();
  AB ab = aa.makeAB();
  a.a_x = 5;
  // tests
  int myx = ab.getA_X_from_AB();
  System.out.println(myx); // 5
  int myx2 = ab.getA_X_thru_AB();
  System.out.println(myx2); // 5
  aa.doSomeCrazyStuff();
}

is converted to the following Jimple code:

r0 := @this: alreadywalaunittests.InnerClassAA
r0 = r0 // <- This statement is odd
$r1 = new alreadywalaunittests.InnerClassAA$AA
specialinvoke $r1.<alreadywalaunittests.InnerClassAA$AA: void <init>()>() // <- Incorrect: non-static inner class has implicit constructor parameter taking an instance of the outer class
$r2 = new alreadywalaunittests.InnerClassAA$AA
specialinvoke $r2.<alreadywalaunittests.InnerClassAA$AA: void <init>()>() // <- Same here
$r1 = $r2
$r3 = virtualinvoke $r1.<alreadywalaunittests.InnerClassAA$AA: alreadywalaunittests.InnerClassAA$AB makeAB()>()
r0.<alreadywalaunittests.InnerClassAA: int a_x> = 5
$i0 = virtualinvoke $r3.<alreadywalaunittests.InnerClassAA$AB: int getA_X_from_AB()>()
$r4 = <java.lang.System: java.io.PrintStream out>
virtualinvoke $r4.<java.io.PrintStream: void println(int)>($i0)
$i1 = virtualinvoke $r3.<alreadywalaunittests.InnerClassAA$AB: int getA_X_thru_AB()>()
$r5 = <java.lang.System: java.io.PrintStream out>
virtualinvoke $r5.<java.io.PrintStream: void println(int)>($i1)
virtualinvoke $r1.<alreadywalaunittests.InnerClassAA$AA: void doSomeCrazyStuff()>()
return

This fails the test de.upb.soot.frontends.java.SelectedInstructionConversionTest#test3.

linghuiluo commented 5 years ago

@juliandolby from soot byte code front end non-static constructor takes an instance of the outerclass as parameter like this

specialinvoke $r3.<alreadywalaunittests.InnerClassAA$AA: void <init>(alreadywalaunittests.InnerClassAA)>(r0);

Is there a way to get this information from the wala source code front end? The only parameter availabe in the instruction was the this parameter.

juliandolby commented 5 years ago

Since WALA supports lexical scoping, we do not generate the various implicit parameters that Java bytecode uses to implement things like nested classes. We will need to decide how, in general, we want to handle lexical scoping in the new Soot. We need to keep in mind that languages like JavaScript require more complete support than does Java.