public static boolean maybeSameLocation(Value v1, Value v2) { if (!(v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef) && !(v1 instanceof ArrayRef && v2 instanceof ArrayRef)) { return v1.equivTo(v2); } if (v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef) { InstanceFieldRef ifr1 = (InstanceFieldRef) v1; InstanceFieldRef ifr2 = (InstanceFieldRef) v2; if (!ifr1.getField().getName().equals(ifr2.getField().getName())) return false; Local base1 = (Local) ifr1.getBase(); Local base2 = (Local) ifr2.getBase(); PointsToAnalysis pta = Scene.v().getPointsToAnalysis(); PointsToSet pts1 = pta.reachingObjects(base1); PointsToSet pts2 = pta.reachingObjects(base2); return pts1.hasNonEmptyIntersection(pts2); } else { // v1 instanceof ArrayRef && v2 instanceof ArrayRef ArrayRef ar1 = (ArrayRef) v1; ArrayRef ar2 = (ArrayRef) v2; Local base1 = (Local) ar1.getBase(); Local base2 = (Local) ar2.getBase(); PointsToAnalysis pta = Scene.v().getPointsToAnalysis(); PointsToSet pts1 = pta.reachingObjects(base1); PointsToSet pts2 = pta.reachingObjects(base2); return pts1.hasNonEmptyIntersection(pts2); } }
public boolean arrayRefRedefined(ArrayRef lARef, List<ValueBox> rUseBoxes) { for (ValueBox rUseBox : rUseBoxes) { Value rBoxValue = rUseBox.getValue(); if (rBoxValue instanceof ArrayRef) { ArrayRef rARef = (ArrayRef) rBoxValue; if (twoValueEquals(lARef.getBase(), rARef.getBase()) && twoValueEquals(lARef.getIndex(), rARef.getIndex())) { return true; } } } return false; }
public static Value getForwardsBase(Value val) { if (val instanceof ArrayRef) { ArrayRef arrayRef = (ArrayRef) val; return arrayRef.getBase(); } return val; }
public void caseArrayRef(ArrayRef arg0) { OpenCLArrayType array = new OpenCLArrayType((ArrayType) arg0.getBase().getType()); if (isLhs()) { m_output.append(array.getArrayRefSetter(arg0)); setCheckException(); } else { m_output.append(array.getArrayRefGetter(arg0)); setCheckException(); } }
/** extracts array base values from array refs and values from cast expressions */ public static Value getBackwardsBase(Value val) { if (val instanceof ArrayRef) { ArrayRef arrayRef = (ArrayRef) val; return arrayRef.getBase(); } if (val instanceof CastExpr) { CastExpr castExpr = (CastExpr) val; return castExpr.getOp(); } return val; }
@Override public Set<? extends IAllocNode> getPTSet(Value val, Context context) { // handle case for insensitive run if (k == 0) return getPTSetIns(val); final Set<AllocNode> allocNodes = new LinkedHashSet<AllocNode>(); final Type filteringType = val.getType(); PointsToSetInternal pts = null; try { if (val instanceof InstanceFieldRef) { final InstanceFieldRef ifr = (InstanceFieldRef) val; pts = (PointsToSetInternal) ptsProvider.reachingObjects(context, (Local) ifr.getBase(), ifr.getField()); } else if (val instanceof ArrayRef) { ArrayRef arrayRef = (ArrayRef) val; pts = (PointsToSetInternal) ptsProvider.reachingObjectsOfArrayElement( ptsProvider.reachingObjects(context, (Local) arrayRef.getBase())); } else if (val instanceof Local) { pts = (PointsToSetInternal) ptsProvider.reachingObjects(context, (Local) val); } else if (val instanceof StaticFieldRef) { SootField field = ((StaticFieldRef) val).getField(); pts = (PointsToSetInternal) ptsProvider.reachingObjects(field); } else if (val instanceof NullConstant) { return allocNodes; } else { logger.error("Unknown reference type for insenstive search: {} {}", val, val.getClass()); droidsafe.main.Main.exit(1); } // visit internal points to set and grab all allocnodes pts.forall( new P2SetVisitor() { public void visit(Node n) { if (typeManager.castNeverFails(n.getType(), filteringType)) allocNodes.add((AllocNode) n); } }); } catch (Exception e) { logger.info("Some sort of error getting context insensitive points to set for {}", val, e); // e.printStackTrace(); } return allocNodes; }
/** * A value represents a var if it's a constant, local, field ref (for field itself), or array elem * ref (any element in it). Objects are *not* considered here. */ public static boolean valuesEqual(Value v1, Value v2) { // case 1: both null refs or constants if (v1 == null || v2 == null) return v1 == v2; if (v1 instanceof Constant) { if (v2 instanceof Constant) return v1.equals(v2); return false; } // case 2: locals if (v1 instanceof Local) return v1 == v2; // case 3: field refs (base is ignored) if (v1 instanceof FieldRef) { SootFieldRef sfr1 = ((FieldRef) v1).getFieldRef(); if (!(v2 instanceof FieldRef)) return false; SootFieldRef sfr2 = ((FieldRef) v2).getFieldRef(); return sfr1.declaringClass() == sfr2.declaringClass() && sfr1.name().equals(sfr2.name()); } // case 4: array elems (index compared only if constant) // they are the same if elem types are equal and index values are not definitely // different assert (v1 instanceof ArrayRef); ArrayRef ae1 = (ArrayRef) v1; if (!(v2 instanceof ArrayRef)) return false; ArrayRef ae2 = (ArrayRef) v2; if (!ae1.getBase().getType().equals(ae2.getBase().getType())) return false; // *** FOR NOW, we avoid distinguishing array elems with constant indices as different // variables, // because it leads to too much instrumentation at defs and uses of array elem with unknown // index. // Value vIdx1 = ae1.getIndex(); // Value vIdx2 = ae2.getIndex(); // if (vIdx1 instanceof Constant && vIdx2 instanceof Constant && !vIdx1.equals(vIdx2)) // return false; return true; }
/** * Hash code for Value representing a variable if it's a constant, local, field ref (for field * itself), or array elem ref (for all elements of array of that type). */ public static int valueHashCode(Value v) { // case 1: null or constant if (v == null) return 0; if (v instanceof Constant) return v.hashCode(); // case 2: local if (v instanceof Local) return v.hashCode(); // case 3: field ref (base is ignored) if (v instanceof FieldRef) { SootFieldRef sfr = ((FieldRef) v).getFieldRef(); return sfr.resolve().hashCode(); } // case 4: array elems assert (v instanceof ArrayRef); ArrayRef ae1 = (ArrayRef) v; // *** FOR NOW, we avoid distinguishing array elems with constant indices as different // variables, // because it leads to too much instrumentation at defs and uses of array elem with unknown // index. return ae1.getBase() .getType() .hashCode(); // + ((ae1.getIndex() instanceof Constant)? ae1.getIndex().hashCode() : 0); }