Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soot generates redundant statements #2045

Open
Momo-Not-Emo opened this issue Feb 4, 2024 · 1 comment
Open

Soot generates redundant statements #2045

Momo-Not-Emo opened this issue Feb 4, 2024 · 1 comment

Comments

@Momo-Not-Emo
Copy link
Contributor

Momo-Not-Emo commented Feb 4, 2024

Describe the bug
Soot generates redundant Jimple statements while SootUp does not

Input file
https://github.com/soot-oss/SootUp/blob/develop/shared-test-resources/miniTestSuite/java6/binary/Reflection.class
https://github.com/soot-oss/SootUp/blob/develop/shared-test-resources/miniTestSuite/java6/source/Reflection.java

To reproduce
soot version (commit id): 0e7e27d457e036ade112d91e1d97cf6a764eb0a9

Copy the input file to test resource directory, and run the following code

    public void loadClasses(String first, String... more) {
        G.reset();
        Path cp = Paths.get(first, more);
        G.reset();
        Options.v().set_prepend_classpath(true);
        Options.v().set_process_dir(Collections.singletonList(cp.toFile().getAbsolutePath()));
        Options.v().set_src_prec(Options.src_prec_class);
        Options.v().set_output_format(Options.output_format_jimple);
        Options.v().set_allow_phantom_refs(true);
        Options.v().set_ignore_resolving_levels(true);
        Scene.v().loadNecessaryClasses();
    }

    public static void main(String[] args) {
        loadClasses(RESOURCE_PATH);
        SootMethod method = Scene.v().getMethod("<Autoboxing: void autoboxing()>");
        Body body = method.retrieveActiveBody();
        List<String> actualStmts = bodyStmtsAsStrings(body);

        for (String item : actualStmts) {
            System.out.println(item);
        }
        System.out.println();
}

Its output is as below, where the assignments of r1, r11, r10 are redundant (only one assignment is generated in SootUp)

r9 := @this: Reflection
$r0 = new Reflection
specialinvoke $r0.<Reflection: void <init>()>()
r1 = class "LReflection;"
r11 = class "LReflection;"
r10 = class "LReflection;"
$r2 = <java.lang.System: java.io.PrintStream out>
virtualinvoke $r2.<java.io.PrintStream: void println(java.lang.Object)>(class "LReflection;")
$r3 = newarray (java.lang.Class)[0]
$r4 = virtualinvoke r10.<java.lang.Class: java.lang.reflect.Constructor getConstructor(java.lang.Class[])>($r3)
$r5 = <java.lang.System: java.io.PrintStream out>
$r6 = virtualinvoke $r4.<java.lang.reflect.Constructor: java.lang.String getName()>()
virtualinvoke $r5.<java.io.PrintStream: void println(java.lang.String)>($r6)
$r7 = <java.lang.System: java.io.PrintStream out>
$r8 = virtualinvoke r11.<java.lang.Class: java.lang.reflect.Method[] getMethods()>()
$i0 = lengthof $r8
virtualinvoke $r7.<java.io.PrintStream: void println(int)>($i0)
return

Expected behavior

Remove the redundant statements of class "LReflection;".

The expected output should be like:

r9 := @this: Reflection
$r0 = new Reflection
specialinvoke $r0.<Reflection: void <init>()>()
r1 = class "LReflection;"
$r2 = <java.lang.System: java.io.PrintStream out>
virtualinvoke $r2.<java.io.PrintStream: void println(java.lang.Object)>(r1)
$r3 = newarray (java.lang.Class)[0]
$r4 = virtualinvoke r1.<java.lang.Class: java.lang.reflect.Constructor getConstructor(java.lang.Class[])>($r3)
$r5 = <java.lang.System: java.io.PrintStream out>
$r6 = virtualinvoke $r4.<java.lang.reflect.Constructor: java.lang.String getName()>()
virtualinvoke $r5.<java.io.PrintStream: void println(java.lang.String)>($r6)
$r7 = <java.lang.System: java.io.PrintStream out>
$r8 = virtualinvoke r1.<java.lang.Class: java.lang.reflect.Method[] getMethods()>()
$i0 = lengthof $r8
virtualinvoke $r7.<java.io.PrintStream: void println(int)>($i0)
return
@Momo-Not-Emo
Copy link
Contributor Author

Related discussion soot-oss/SootUp#472 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant