Search in sources :

Example 1 with PhiExpr

use of soot.shimple.PhiExpr in project soot by Sable.

the class MethodNodeFactory method casePhiExpr.

@Override
public final void casePhiExpr(PhiExpr e) {
    Pair<Expr, String> phiPair = new Pair<Expr, String>(e, PointsToAnalysis.PHI_NODE);
    Node phiNode = pag.makeLocalVarNode(phiPair, e.getType(), method);
    for (Value op : e.getValues()) {
        op.apply(MethodNodeFactory.this);
        Node opNode = getNode();
        mpag.addInternalEdge(opNode, phiNode);
    }
    setResult(phiNode);
}
Also used : NewArrayExpr(soot.jimple.NewArrayExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) PhiExpr(soot.shimple.PhiExpr) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) CastExpr(soot.jimple.CastExpr) InvokeExpr(soot.jimple.InvokeExpr) NewExpr(soot.jimple.NewExpr) Expr(soot.jimple.Expr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) NewInstanceNode(soot.jimple.spark.pag.NewInstanceNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) Value(soot.Value) Pair(soot.toolkits.scalar.Pair)

Example 2 with PhiExpr

use of soot.shimple.PhiExpr in project soot by Sable.

the class NullnessAnalysis method handleRefTypeAssignment.

private void handleRefTypeAssignment(DefinitionStmt assignStmt, AnalysisInfo out) {
    Value left = assignStmt.getLeftOp();
    Value right = assignStmt.getRightOp();
    // unbox casted value
    if (right instanceof JCastExpr) {
        JCastExpr castExpr = (JCastExpr) right;
        right = castExpr.getOp();
    }
    // if we have a definition (assignment) statement to a ref-like type, handle it,
    if (isAlwaysNonNull(right) || right instanceof NewExpr || right instanceof NewArrayExpr || right instanceof NewMultiArrayExpr || right instanceof ThisRef || right instanceof StringConstant || right instanceof ClassConstant || right instanceof CaughtExceptionRef) {
        // if we assign new... or @this, the result is non-null
        out.put(left, NON_NULL);
    } else if (right == NullConstant.v()) {
        // if we assign null, well, it's null
        out.put(left, NULL);
    } else if (left instanceof Local && right instanceof Local) {
        out.put(left, out.get(right));
    } else if (left instanceof Local && right instanceof PhiExpr) {
        handlePhiExpr(out, left, (PhiExpr) right);
    } else {
        out.put(left, TOP);
    }
}
Also used : CaughtExceptionRef(soot.jimple.CaughtExceptionRef) NewArrayExpr(soot.jimple.NewArrayExpr) ThisRef(soot.jimple.ThisRef) PhiExpr(soot.shimple.PhiExpr) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) Value(soot.Value) NewExpr(soot.jimple.NewExpr) Local(soot.Local) JCastExpr(soot.jimple.internal.JCastExpr) StringConstant(soot.jimple.StringConstant) ClassConstant(soot.jimple.ClassConstant)

Example 3 with PhiExpr

use of soot.shimple.PhiExpr in project soot by Sable.

the class ConstantArrayAnalysis method flowThrough.

@Override
protected void flowThrough(ArrayState in, Unit d, ArrayState out) {
    out.active.clear();
    out.active.or(in.active);
    out.state = Arrays.copyOf(in.state, in.state.length);
    if (d instanceof DefinitionStmt) {
        DefinitionStmt ds = (DefinitionStmt) d;
        Value rhs = ds.getRightOp();
        Value lhs = ds.getLeftOp();
        if (rhs instanceof NewArrayExpr) {
            Local l = (Local) lhs;
            int varRef = localToInt.get(l);
            NewArrayExpr nae = (NewArrayExpr) rhs;
            out.active.set(varRef);
            if (!(nae.getSize() instanceof IntConstant)) {
                out.state[varRef] = null;
            } else {
                int arraySize = ((IntConstant) nae.getSize()).value;
                out.state[varRef] = new ArrayTypesInternal();
                out.state[varRef].sizeState.set(sizeToInt.get(arraySize));
                out.state[varRef].typeState = new BitSet[arraySize];
                out.state[varRef].mustAssign = new BitSet(arraySize);
                for (int i = 0; i < arraySize; i++) {
                    out.state[varRef].typeState[i] = new BitSet(typeSize);
                }
            }
        } else if (lhs instanceof Local && lhs.getType() instanceof ArrayType && rhs instanceof NullConstant) {
            int varRef = localToInt.get(lhs);
            out.active.clear(varRef);
            out.state[varRef] = null;
        } else if (lhs instanceof Local && rhs instanceof Local && in.state[localToInt.get(rhs)] != null && in.active.get(localToInt.get(rhs))) {
            int lhsRef = localToInt.get(lhs);
            int rhsRef = localToInt.get(rhs);
            out.active.set(lhsRef);
            out.state[lhsRef] = in.state[rhsRef];
            out.state[rhsRef] = null;
        } else if (lhs instanceof Local && rhs instanceof PhiExpr) {
            PhiExpr rPhi = (PhiExpr) rhs;
            int lhsRef = localToInt.get(lhs);
            out.state[lhsRef] = null;
            int i = 0;
            List<Value> phiValues = rPhi.getValues();
            for (; i < phiValues.size(); i++) {
                Value v = phiValues.get(i);
                int argRef = localToInt.get(v);
                if (!in.active.get(argRef)) {
                    continue;
                }
                out.active.set(lhsRef);
                // one bottom -> all bottom
                if (in.state[argRef] == null) {
                    out.state[lhsRef] = null;
                    break;
                }
                if (out.state[lhsRef] == null) {
                    out.state[lhsRef] = in.state[argRef];
                } else {
                    out.state[lhsRef] = mergeTypeStates(in.state[argRef], out.state[lhsRef]);
                }
                out.state[argRef] = null;
            }
            for (; i < phiValues.size(); i++) {
                int argRef = localToInt.get(phiValues.get(i));
                out.state[argRef] = null;
            }
        } else if (lhs instanceof ArrayRef) {
            ArrayRef ar = (ArrayRef) lhs;
            Value indexVal = ar.getIndex();
            int localRef = localToInt.get(ar.getBase());
            if (!(indexVal instanceof IntConstant)) {
                out.state[localRef] = null;
                out.active.set(localRef);
            } else if (out.state[localRef] != null) {
                Type assignType = rhs.getType();
                int index = ((IntConstant) indexVal).value;
                assert index < out.state[localRef].typeState.length;
                out.deepCloneLocalValueSlot(localRef, index);
                assert out.state[localRef].typeState[index] != null : d;
                out.state[localRef].typeState[index].set(typeToInt.get(assignType));
                out.state[localRef].mustAssign.set(index);
            }
        } else {
            Value leftOp = lhs;
            if (leftOp instanceof Local) {
                Local defLocal = (Local) leftOp;
                int varRef = localToInt.get(defLocal);
                out.active.set(varRef);
                out.state[varRef] = null;
            }
        }
        for (ValueBox b : rhs.getUseBoxes()) {
            if (localToInt.containsKey(b.getValue())) {
                int localRef = localToInt.get(b.getValue());
                out.state[localRef] = null;
                out.active.set(localRef);
            }
        }
        if (localToInt.containsKey(rhs)) {
            int localRef = localToInt.get(rhs);
            out.state[localRef] = null;
            out.active.set(localRef);
        }
    } else {
        for (ValueBox b : d.getUseBoxes()) {
            if (localToInt.containsKey(b.getValue())) {
                int localRef = localToInt.get(b.getValue());
                out.state[localRef] = null;
                out.active.set(localRef);
            }
        }
    }
}
Also used : BitSet(java.util.BitSet) Local(soot.Local) NullConstant(soot.jimple.NullConstant) ArrayType(soot.ArrayType) ArrayRef(soot.jimple.ArrayRef) ArrayType(soot.ArrayType) Type(soot.Type) NullType(soot.NullType) NewArrayExpr(soot.jimple.NewArrayExpr) PhiExpr(soot.shimple.PhiExpr) ValueBox(soot.ValueBox) Value(soot.Value) IntConstant(soot.jimple.IntConstant) List(java.util.List) DefinitionStmt(soot.jimple.DefinitionStmt)

Aggregations

Value (soot.Value)3 NewArrayExpr (soot.jimple.NewArrayExpr)3 PhiExpr (soot.shimple.PhiExpr)3 Local (soot.Local)2 NewExpr (soot.jimple.NewExpr)2 NewMultiArrayExpr (soot.jimple.NewMultiArrayExpr)2 BitSet (java.util.BitSet)1 List (java.util.List)1 ArrayType (soot.ArrayType)1 NullType (soot.NullType)1 Type (soot.Type)1 ValueBox (soot.ValueBox)1 ArrayRef (soot.jimple.ArrayRef)1 CastExpr (soot.jimple.CastExpr)1 CaughtExceptionRef (soot.jimple.CaughtExceptionRef)1 ClassConstant (soot.jimple.ClassConstant)1 DefinitionStmt (soot.jimple.DefinitionStmt)1 Expr (soot.jimple.Expr)1 IntConstant (soot.jimple.IntConstant)1 InvokeExpr (soot.jimple.InvokeExpr)1