Skip to content

Commit

Permalink
Merge pull request #78 from quentin/fix-issue-77
Browse files Browse the repository at this point in the history
Fix issue 77
  • Loading branch information
Eric Bodden committed Jun 3, 2013
2 parents dbf60c7 + 1f57b25 commit 0c1209e
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 151 deletions.
34 changes: 34 additions & 0 deletions src/soot/coffi/ByteCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -1107,4 +1107,38 @@ private Instruction locateInstr(int index,int mini,int maxi) {
return locateInstr(index,mini,mid-1);
return locateInstr(index,mid+1,maxi);
}

/** Returns true if the bytecode is a local store */
public static boolean isLocalStore(int bc) {
switch(bc) {
case ByteCode.ISTORE:
case ByteCode.FSTORE:
case ByteCode.ASTORE:
case ByteCode.LSTORE:
case ByteCode.DSTORE:
case ByteCode.ISTORE_0:
case ByteCode.ISTORE_1:
case ByteCode.ISTORE_2:
case ByteCode.ISTORE_3:
case ByteCode.FSTORE_0:
case ByteCode.FSTORE_1:
case ByteCode.FSTORE_2:
case ByteCode.FSTORE_3:
case ByteCode.ASTORE_0:
case ByteCode.ASTORE_1:
case ByteCode.ASTORE_2:
case ByteCode.ASTORE_3:
case ByteCode.LSTORE_0:
case ByteCode.LSTORE_1:
case ByteCode.LSTORE_2:
case ByteCode.LSTORE_3:
case ByteCode.DSTORE_0:
case ByteCode.DSTORE_1:
case ByteCode.DSTORE_2:
case ByteCode.DSTORE_3:
return true;
default:
return false;
}
}
}
121 changes: 34 additions & 87 deletions src/soot/coffi/CFG.java
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ public Instruction reconstructInstructions()
public boolean jimplify(cp_info constant_pool[],int this_class, BootstrapMethods_attribute bootstrap_methods_attribute, JimpleBody listBody)
{
this.bootstrap_methods_attribute = bootstrap_methods_attribute;
Util.v().setClassNameToAbbreviation(new HashMap());
Util.v().setClassNameToAbbreviation(new HashMap()); // UNUSED

Chain units = listBody.getUnits();

Expand All @@ -876,10 +876,7 @@ public boolean jimplify(cp_info constant_pool[],int this_class, BootstrapMethods
LocalVariableTable_attribute la = ca.findLocalVariableTable();
LocalVariableTypeTable_attribute lt = ca.findLocalVariableTypeTable();

Util.v().activeVariableTable = la;
Util.v().activeVariableTypeTable = lt;

Util.v().activeConstantPool = constant_pool;
Util.v().bodySetup(la,lt,constant_pool);

Type thisType = RefType.v(jmethod.getDeclaringClass().getName());
boolean isStatic = Modifier.isStatic(jmethod.getModifiers());
Expand All @@ -890,23 +887,9 @@ public boolean jimplify(cp_info constant_pool[],int this_class, BootstrapMethods
{
if(!isStatic)
{
String name;

if(!Util.v().useFaithfulNaming || la == null)
name = "l0";
else
{
name = la.getLocalVariableName(constant_pool, currentLocalIndex);
if (!Util.v().isValidJimpleName(name))
name = "l0";
}

Local local = Jimple.v().newLocal(name, UnknownType.v());

listBody.getLocals().add(local);

Local local = Util.v().getLocalForParameter(listBody, currentLocalIndex);
currentLocalIndex++;

units.add(Jimple.v().newIdentityStmt(local, Jimple.v().newThisRef(jmethod.getDeclaringClass().getType())));
}
}
Expand All @@ -918,21 +901,9 @@ public boolean jimplify(cp_info constant_pool[],int this_class, BootstrapMethods

while(typeIt.hasNext())
{
String name;
Local local = Util.v().getLocalForParameter(listBody, currentLocalIndex);
Type type = (Type) typeIt.next();

if(!Util.v().useFaithfulNaming || la == null)
name = "l" + currentLocalIndex;
else
{
name = la.getLocalVariableName(constant_pool, currentLocalIndex);
if (!Util.v().isValidJimpleName(name))
name = "l" + currentLocalIndex;
}

Local local = Jimple.v().newLocal(name, UnknownType.v());
initialLocals.add(local);
listBody.getLocals().add(local);

units.add(Jimple.v().newIdentityStmt(local, Jimple.v().newParameterRef(type, argCount)));

Expand Down Expand Up @@ -2940,10 +2911,6 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
Stmt stmt = null;

int x = ((ins.code))&0xff;

Util.v().activeOriginalIndex = ins.originalIndex;
Util.v().isLocalStore = false;
Util.v().isWideLocalStore = false;

switch(x)
{
Expand Down Expand Up @@ -3012,7 +2979,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac

case ByteCode.ILOAD:
{
Local local = Util.v().getLocalForIndex(listBody, ((Instruction_bytevar) ins).arg_b);
Local local = Util.v().getLocalForIndex(listBody, ((Instruction_bytevar) ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3021,7 +2988,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac

case ByteCode.FLOAD:
{
Local local = Util.v().getLocalForIndex(listBody, ((Instruction_bytevar)ins).arg_b);
Local local = Util.v().getLocalForIndex(listBody, ((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3031,7 +2998,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.ALOAD:
{
Local local =
Util.v().getLocalForIndex(listBody, ((Instruction_bytevar)ins).arg_b);
Util.v().getLocalForIndex(listBody, ((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3041,7 +3008,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.DLOAD:
{
Local local =
Util.v().getLocalForIndex(listBody, ((Instruction_bytevar)ins).arg_b);
Util.v().getLocalForIndex(listBody, ((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3051,7 +3018,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.LLOAD:
{
Local local =
Util.v().getLocalForIndex(listBody, ((Instruction_bytevar)ins).arg_b);
Util.v().getLocalForIndex(listBody, ((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3064,7 +3031,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.ILOAD_3:
{
Local local =
Util.v().getLocalForIndex(listBody, (x - ByteCode.ILOAD_0));
Util.v().getLocalForIndex(listBody, (x - ByteCode.ILOAD_0), ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3077,7 +3044,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.FLOAD_3:
{
Local local =
Util.v().getLocalForIndex(listBody, (x - ByteCode.FLOAD_0));
Util.v().getLocalForIndex(listBody, (x - ByteCode.FLOAD_0), ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3090,7 +3057,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.ALOAD_3:
{
Local local =
Util.v().getLocalForIndex(listBody, (x - ByteCode.ALOAD_0));
Util.v().getLocalForIndex(listBody, (x - ByteCode.ALOAD_0), ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3103,7 +3070,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.LLOAD_3:
{
Local local =
Util.v().getLocalForIndex(listBody, (x - ByteCode.LLOAD_0));
Util.v().getLocalForIndex(listBody, (x - ByteCode.LLOAD_0), ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
Expand All @@ -3116,73 +3083,58 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.DLOAD_3:
{
Local local =
Util.v().getLocalForIndex(listBody, (x - ByteCode.DLOAD_0));
Util.v().getLocalForIndex(listBody, (x - ByteCode.DLOAD_0), ins);

stmt = Jimple.v().newAssignStmt(Util.v().getLocalForStackOp(listBody, postTypeStack,
postTypeStack.topIndex()), local);
break;
}

case ByteCode.ISTORE:
{
Util.v().isLocalStore = true;
Util.v().isWideLocalStore = true;

{
Local local =
Util.v().getLocalForIndex(listBody,
((Instruction_bytevar)ins).arg_b);
((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
}

case ByteCode.FSTORE:
{
Util.v().isLocalStore = true;
Util.v().isWideLocalStore = true;

{
Local local =
Util.v().getLocalForIndex(listBody,
((Instruction_bytevar)ins).arg_b);
((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
}

case ByteCode.ASTORE:
{
Util.v().isLocalStore = true;
Util.v().isWideLocalStore = true;

{
Local local =
Util.v().getLocalForIndex(listBody,
((Instruction_bytevar)ins).arg_b);
((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
}

case ByteCode.LSTORE:
{
Util.v().isLocalStore = true;
Util.v().isWideLocalStore = true;

{
Local local =
Util.v().getLocalForIndex(listBody,
((Instruction_bytevar)ins).arg_b);
((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
}

case ByteCode.DSTORE:
{
Util.v().isLocalStore = true;
Util.v().isWideLocalStore = true;

{
Local local =
Util.v().getLocalForIndex(listBody,
((Instruction_bytevar)ins).arg_b);
((Instruction_bytevar)ins).arg_b, ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
Expand All @@ -3193,9 +3145,8 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.ISTORE_2:
case ByteCode.ISTORE_3:
{
Util.v().isLocalStore = true;
Local local =
Util.v().getLocalForIndex(listBody, (x - ByteCode.ISTORE_0));
Util.v().getLocalForIndex(listBody, (x - ByteCode.ISTORE_0), ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
Expand All @@ -3206,8 +3157,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.FSTORE_2:
case ByteCode.FSTORE_3:
{
Util.v().isLocalStore = true;
Local local = Util.v().getLocalForIndex(listBody, (x - ByteCode.FSTORE_0));
Local local = Util.v().getLocalForIndex(listBody, (x - ByteCode.FSTORE_0), ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
Expand All @@ -3218,8 +3168,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.ASTORE_2:
case ByteCode.ASTORE_3:
{
Util.v().isLocalStore = true;
Local local = Util.v().getLocalForIndex(listBody, (x - ByteCode.ASTORE_0));
Local local = Util.v().getLocalForIndex(listBody, (x - ByteCode.ASTORE_0), ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
Expand All @@ -3230,9 +3179,8 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.LSTORE_2:
case ByteCode.LSTORE_3:
{
Util.v().isLocalStore = true;
Local local =
Util.v().getLocalForIndex(listBody, (x - ByteCode.LSTORE_0));
Util.v().getLocalForIndex(listBody, (x - ByteCode.LSTORE_0), ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
Expand All @@ -3243,9 +3191,8 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.DSTORE_2:
case ByteCode.DSTORE_3:
{
Util.v().isLocalStore = true;
Local local =
Util.v().getLocalForIndex(listBody, (x - ByteCode.DSTORE_0));
Util.v().getLocalForIndex(listBody, (x - ByteCode.DSTORE_0), ins);

stmt = Jimple.v().newAssignStmt(local, Util.v().getLocalForStackOp(listBody, typeStack, typeStack.topIndex()));
break;
Expand All @@ -3255,7 +3202,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
{
Local local =
Util.v().getLocalForIndex(listBody,
((Instruction_Iinc)ins).arg_b);
((Instruction_Iinc)ins).arg_b, ins);

int amt = (((Instruction_Iinc)ins).arg_c);
rhs = Jimple.v().newAddExpr(local, IntConstant.v(amt));
Expand Down Expand Up @@ -4120,7 +4067,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.RET:
{
Local local =
Util.v().getLocalForIndex(listBody, ((Instruction_Ret)ins).arg_b);
Util.v().getLocalForIndex(listBody, ((Instruction_Ret)ins).arg_b, ins);

stmt = Jimple.v().newRetStmt(local);
break;
Expand All @@ -4129,7 +4076,7 @@ void generateJimple(Instruction ins, TypeStack typeStack, TypeStack postTypeStac
case ByteCode.RET_W:
{
Local local =
Util.v().getLocalForIndex(listBody, ((Instruction_Ret_w)ins).arg_i);
Util.v().getLocalForIndex(listBody, ((Instruction_Ret_w)ins).arg_i, ins);


stmt = Jimple.v().newRetStmt(local);
Expand Down Expand Up @@ -4740,4 +4687,4 @@ class OutFlow
{
this.typeStack = typeStack;
}
}
}

0 comments on commit 0c1209e

Please sign in to comment.