[Soot-list] jump targets and weird label placement

Lonnie Princehouse lonnie.princehouse at gmail.com
Thu Aug 5 13:17:03 EDT 2010


I've encountered some strange behavior with JTableSwitchStmt, where Soot
seemingly generates a label in the wrong place.
This happens when a JTableSwitchStmt is created with a jump target
immediately following where the JTableSwitchStmt will be inserted.

Unit target1, target2, target3 = ...;

Unit switchStmt = new JTableSwitchStmt(foo, 0, 1,
               Arrays.<Unit>asList(target1, target2), target3); // default

body.getUnits().insertBefore(switchStmt, target3);

This results in jimple code like this:

label3:
  tableswitch($foo)
        {
            case 0: goto label1;
            case 1: goto label2
            default: goto label3;
        };

The default case now causes an infinite loop. Really, we want label3 to come
after the tableswitch statement.
This workaround seems to solve the problem, although I have no idea why:

// instead of inserting before target3, insert after predecessor of target3
body.getUnits().insertAfter(switchStmt, body.getUnits().getPredOf(target3));


As I said, the workaround fixes it, but I thought I'd put it out there as an
FYI that there may be something weird with label generation.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20100805/60b32c6c/attachment.html 


More information about the Soot-list mailing list