/// <summary> /// Join that performs trickery to keep bounds on pointers if one side is null /// </summary> /// <param name="pc">PC of join point</param> public StripeWithIntervalsForUnsafeCode Join(StripeWithIntervalsForUnsafeCode prevState, APC pc) { IntervalsForUnsafeCode thisInterval = (IntervalsForUnsafeCode)this.Left.Clone(); IntervalsForUnsafeCode prevInterval = (IntervalsForUnsafeCode)prevState.Left.Clone(); IntervalsForUnsafeCode joinLeftPart = (IntervalsForUnsafeCode)((IntervalsForUnsafeCode)this.Left).Join(prevState.Left, this.nullPointers.Union(prevState.nullPointers), pc); // Pietro's // if (!light) if (true) { //Before permorming the join, it refines the information contained in the domain StripeForUnsafeCode thisRightRefined = (StripeForUnsafeCode)((StripeForUnsafeCode)this.Right).RefineInternally(); StripeForUnsafeCode prevRightRefined = (StripeForUnsafeCode)((StripeForUnsafeCode)prevState.Right).RefineInternally(); StripeForUnsafeCode joinRightPart = (StripeForUnsafeCode)thisRightRefined.Join(prevRightRefined, this.nullPointers.Union(prevState.nullPointers), thisInterval, prevInterval, pc); //It resets the set of the bottom pointers nullPointers = new Set <BoxedExpression>(); return((StripeWithIntervalsForUnsafeCode)prevState.Reduce(joinLeftPart, joinRightPart)); } //else //{ // StripeForUnsafeCode joinRightPart = (StripeForUnsafeCode)this.Right.Join(prevState.Right, this.nullPointers.Union(prevState.nullPointers)); // nullPointers = new Set<BoxedExpression>(); // return (StripeWithIntervalsForUnsafeCode)prevState.Reduce(joinLeftPart, joinRightPart); //} }
/// <summary> /// Assume the property <code>exp >= 0</code> /// </summary> protected override INumericalAbstractDomain <BoxedExpression> AssumeGreaterEqualThanZero(BoxedExpression exp, INumericalAbstractDomain <BoxedExpression> data) { var cast = (StripeWithIntervalsForUnsafeCode)data; IntervalsForUnsafeCode newLeft = (IntervalsForUnsafeCode)cast.Left.TestTrueGeqZero(exp); StripeForUnsafeCode newRight = (StripeForUnsafeCode)cast.Right; // We abstract them away return(new StripeWithIntervalsForUnsafeCode(newLeft, newRight, this.Decoder, this.Context, this.DecoderForMetaData)); }
public StripeWithIntervalsForUnsafeCode( IntervalsForUnsafeCode /*!*/ left, StripeForUnsafeCode /*!*/ right, IExpressionDecoder <BoxedExpression> decoder, IExpressionContext <APC, Local, Parameter, Method, Field, Type, ExternalExpression, Variable> context, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> mdDecoder ) : base(left, right, decoder) { this.context = context; this.mdDecoder = mdDecoder; }
/// <summary> /// Given the previous state of the domain and the result of a join operations, add to the third parameter all the constraints that have been dropped /// during the join /// </summary> /// <param name="thiscloned">The old state</param> /// <param name="result">The result of the join</param> /// <param name="dropped">The variable on which the constraints must be added</param> private static void ExtractDroppedConstraints(StripeForUnsafeCode thiscloned, StripeForUnsafeCode result, StripeForUnsafeCode dropped) { foreach (BoxedExpression key in thiscloned.Keys) { foreach (AtMostTwoExpressions <BoxedExpression> constr in thiscloned[key].EmbeddedValues_Unsafe) { if (result.ContainsKey(key) == false || result[key].Contains(constr) == false) { dropped.AddConstraint(key, constr); } } } }
/// <summary> /// The version of the join operator refined with the information about null pointers /// </summary> /// <param name="pc">PC at join point</param> public IAbstractDomain Join(IAbstractDomain a, Set <BoxedExpression> bottomPointers, IntervalsForUnsafeCode intervalsThis, IntervalsForUnsafeCode intervalsPrev, APC pc) { StripeForUnsafeCode thiscloned = (StripeForUnsafeCode)this.Clone(); StripeForUnsafeCode othercloned = (StripeForUnsafeCode)a.Clone(); StripeForUnsafeCode joined = (StripeForUnsafeCode)((IAbstractDomain)this.Clone()).Join((IAbstractDomain)a.Clone()); StripeForUnsafeCode prev = new StripeForUnsafeCode((Stripe <BoxedExpression, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> >)a, this.context); StripeForUnsafeCode result = joined; //For each pointer such that in a branch it is null and in the other is assigned to an allocated area of memory, we trace information only from //this branch, ignoring the other one foreach (BoxedExpression ptr in bottomPointers) { BoxedExpression tempExp; if (ptr.TryGetAssociatedInfo(pc, AssociatedInfo.WritableBytes, out tempExp) || ptr.TryGetAssociatedInfo(pc, AssociatedInfo.ArrayLength, out tempExp)) // TODO: if this doesn't work, we need to pass in the PC to the getassociated info method to refine it at a particular place { Stripe <BoxedExpression, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> > thisConstr = this.GetConstraintsOfAVariable(tempExp); Stripe <BoxedExpression, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> > prevConstr = prev.GetConstraintsOfAVariable(tempExp); if (thisConstr.IsTop && !prevConstr.IsTop) { result = new StripeForUnsafeCode((Stripe <BoxedExpression, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> >)result.Meet(prevConstr), this.context); } if (prevConstr.IsTop && !thisConstr.IsTop) { result = new StripeForUnsafeCode((Stripe <BoxedExpression, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> >)result.Meet(thisConstr), this.context); } } } //It checks for each dropped constraints if it can be validated by the intervals domain state addConstraints(intervalsPrev, thiscloned, result); addConstraints(intervalsThis, othercloned, result); return(result); }
/// <summary> /// It checks for each dropped constraints if it can be validated by the intervals domain state /// </summary> private void addConstraints(IntervalsForUnsafeCode intervalsPrev, StripeForUnsafeCode thiscloned, StripeForUnsafeCode result) { StripeForUnsafeCode dropped = (StripeForUnsafeCode)this.Factory(); ExtractDroppedConstraints(thiscloned, result, dropped); foreach (BoxedExpression key in dropped.Keys) { foreach (AtMostTwoExpressions <BoxedExpression> constr in dropped[key].EmbeddedValues_Unsafe) { if (!constr.IsTop && !constr.IsBottom) { BoxedExpression toBeChecked = StripeWithIntervalsForUnsafeCode.MakeCondition(key, constr, this.mdDecoder); FlatAbstractDomain <bool> test = intervalsPrev.CheckIfHolds(toBeChecked); if (!test.IsBottom && !test.IsTop && test.BoxedElement == true) { result.AddConstraint(key, constr); } } } } }
private IAbstractDomainForEnvironments <BoxedExpression> RefineTest(StripeWithIntervalsForUnsafeCode result) { //For each variable whose value has been modified we check if it is possible to refine the state of the intervals with the relational domain Set <BoxedExpression> modified = ((IntervalsForUnsafeCode)result.Left).NewValues; IntervalsForUnsafeCode intres = (IntervalsForUnsafeCode)result.Left; foreach (BoxedExpression val in modified) { StripeForUnsafeCode left = (StripeForUnsafeCode) new StripeForUnsafeCode(((StripeForUnsafeCode)result.Right).GetConstraintsOfAVariable(val), this.context); foreach (BoxedExpression key in left.Keys) { foreach (AtMostTwoExpressions <BoxedExpression> constr in left[key].EmbeddedValues_Unsafe) { intres = RefineIntervalsWithConstraint(intres, key, constr, this.mdDecoder); } } } //We reset the modified values ((IntervalsForUnsafeCode)this.Left).NewValues = new Set <BoxedExpression>(); return((IAbstractDomainForEnvironments <BoxedExpression>) this.Factory(intres, result.Right)); }
public StripeWithIntervalsForUnsafeCode Widening(StripeWithIntervalsForUnsafeCode prevState, APC pc) { IntervalsForUnsafeCode thisInterval = (IntervalsForUnsafeCode)this.Left.Clone(); IntervalsForUnsafeCode prevInterval = (IntervalsForUnsafeCode)prevState.Left.Clone(); if (this.IsBottom) { return(prevState); } if (prevState.IsBottom) { return(this); } IntervalsForUnsafeCode joinLeftPart = (IntervalsForUnsafeCode)((IntervalsForUnsafeCode)this.Left).Widening(prevState.Left); // Pietro's //if (!light) if (true) { //Since our domain is of finite height, we can use the version of join operator improved with the information abount null pointers StripeForUnsafeCode thisRightRefined = (StripeForUnsafeCode)((StripeForUnsafeCode)this.Right).RefineInternally(); StripeForUnsafeCode prevRightRefined = (StripeForUnsafeCode)((StripeForUnsafeCode)prevState.Right).RefineInternally(); StripeForUnsafeCode joinRightPart = (StripeForUnsafeCode)thisRightRefined.Join(prevRightRefined, this.nullPointers.Union(prevState.nullPointers), thisInterval, prevInterval, pc); //It resets the set of the bottom pointers nullPointers = new Set <BoxedExpression>(); return((StripeWithIntervalsForUnsafeCode)prevState.Reduce(joinLeftPart, joinRightPart)); } //else //{ // StripeForUnsafeCode joinRightPart = (StripeForUnsafeCode)this.Right.Join(prevState.Right, this.nullPointers.Union(prevState.nullPointers)); // nullPointers = new Set<BoxedExpression>(); // return (StripeWithIntervalsForUnsafeCode)prevState.Reduce(joinLeftPart, joinRightPart); //} }
public StripeForUnsafeCode(StripeForUnsafeCode original, IExpressionContext <APC, Local, Parameter, Method, Field, Type, ExternalExpression, Variable> context) : base(original) { this.context = context; this.decoder = original.decoder; }
public override object Clone() { StripeForUnsafeCode result = new StripeForUnsafeCode((Stripe <BoxedExpression, IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> >)base.Clone(), this.context); return(result); }