Skip to content

Commit

Permalink
Allow conversion in dex for float <-> int and double <-> long
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcMil committed Oct 18, 2024
1 parent bb2f5ad commit c0ba420
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/main/java/soot/dexpler/DexBody.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import soot.DoubleType;
import soot.FloatType;
import soot.IntType;
import soot.IntegerType;
import soot.Local;
import soot.LongType;
import soot.Modifier;
Expand Down Expand Up @@ -141,6 +142,7 @@
import soot.jimple.toolkits.scalar.UnreachableCodeEliminator;
import soot.jimple.toolkits.typing.fast.DefaultTypingStrategy;
import soot.jimple.toolkits.typing.fast.ITypingStrategy;
import soot.jimple.toolkits.typing.fast.TypePromotionUseVisitor;
import soot.options.JBOptions;
import soot.options.Options;
import soot.tagkit.LineNumberTag;
Expand Down Expand Up @@ -819,6 +821,24 @@ public Body jimplify(Body b, SootMethod m) {

new soot.jimple.toolkits.typing.fast.TypeResolver(jBody) {

protected soot.jimple.toolkits.typing.fast.TypePromotionUseVisitor createTypePromotionUseVisitor(JimpleBody jb,
soot.jimple.toolkits.typing.fast.Typing tg) {
return new TypePromotionUseVisitor(jb, tg) {
protected boolean allowConversion(Type ancestor, Type child) {
if ((ancestor instanceof IntegerType || ancestor instanceof FloatType)
&& (child instanceof IntegerType || child instanceof FloatType)) {
return true;
}
if ((ancestor instanceof LongType || ancestor instanceof DoubleType)
&& (child instanceof LongType || child instanceof DoubleType)) {
return true;
}
return super.allowConversion(ancestor, child);
}
};

}

@Override
protected Collection<Type> reduceToAllowedTypesForLocal(Collection<Type> lcas, Local v) {
Collection<Type> t = definiteConstraints.get(v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Value visit(Value op, Type useType, Stmt stmt, boolean checkOnly) {

Type t = AugEvalFunction.eval_(this.tg, op, stmt, this.jb);

if (!AugHierarchy.ancestor_(useType, t)) {
if (!allowConversion(useType, t)) {
logger.error(String.format("Failed Typing in %s at statement %s: Is not cast compatible: %s <-- %s",
jb.getMethod().getSignature(), stmt, useType, t));
this.fail = true;
Expand All @@ -118,6 +118,10 @@ public Value visit(Value op, Type useType, Stmt stmt, boolean checkOnly) {
return op;
}

protected boolean allowConversion(Type ancestor, Type child) {
return AugHierarchy.ancestor_(ancestor, child);
}

@Override
public boolean finish() {
return this.typingChanged || this.fail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private Typing typePromotion(Typing tg) {
AugEvalFunction ef = new AugEvalFunction(this.jb);
AugHierarchy h = new AugHierarchy();
UseChecker uc = new UseChecker(this.jb);
TypePromotionUseVisitor uv = new TypePromotionUseVisitor(jb, tg);
TypePromotionUseVisitor uv = createTypePromotionUseVisitor(jb, tg);
do {
Collection<Typing> sigma = this.applyAssignmentConstraints(tg, ef, h);
if (sigma.isEmpty()) {
Expand Down Expand Up @@ -351,6 +351,10 @@ private Typing typePromotion(Typing tg) {
return tg;
}

protected TypePromotionUseVisitor createTypePromotionUseVisitor(JimpleBody jb, Typing tg) {
return new TypePromotionUseVisitor(jb, tg);
}

protected Type convert(Type t) {
if (t instanceof Integer1Type) {
return booleanType;
Expand Down

0 comments on commit c0ba420

Please sign in to comment.