/// <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);
                    //}
                }
Beispiel #2
0
                /// <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;
 }
                private static IntervalsForUnsafeCode RefineIntervalsWithConstraint(
                    IntervalsForUnsafeCode intres,
                    BoxedExpression key,
                    AtMostTwoExpressions <BoxedExpression> constr,
                    IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> mdDecoder
                    )
                {
                    if (constr.IsBottom || constr.IsTop)
                    {
                        return(intres);
                    }
                    BoxedExpression toBeChecked = MakeCondition(key, constr, mdDecoder);

                    intres = (IntervalsForUnsafeCode)intres.TestTrue(toBeChecked);
                    return(intres);
                }
 /// <summary>
 /// TODO: figure out the subtle uses of PC that Pietro introduced.
 /// </summary>
 private void RefineNullVariable(APC pc, BoxedExpression length, IntervalsForUnsafeCode prev, IntervalsForUnsafeCode result)
 {
     if (this.ContainsKey(length) && !this[length].IsTop)
     {
         if (result.ContainsKey(length) == false)
         {
             // result.elements.Add(length, this[length]);
             result[length] = this[length];
         }
     }
     if (prev.ContainsKey(length) && !prev[length].IsTop)
     {
         if (result.ContainsKey(length))
         {
             // result.Add(tempExp, prev[tempExp]);
             result[length] = prev[length];
         }
     }
 }
                /// <summary>
                /// The join operator improved in order to keep information about pointers that are null in a branch and != null in the other
                /// In this case we trace the length of the pointer != null ignoring the other branch
                /// </summary>
                /// <param name="pc">is the target of the join.</param>
                public IAbstractDomain Join(IAbstractDomain a, Set <BoxedExpression> bottomPointers, APC pc)
                {
                    var joined = base.Join((IntervalEnvironment <BoxedExpression>)a);

                    IntervalsForUnsafeCode prev   = new IntervalsForUnsafeCode((IntervalEnvironment <BoxedExpression>)a, this.context);
                    IntervalsForUnsafeCode result = new IntervalsForUnsafeCode((IntervalEnvironment <BoxedExpression>)joined, this.context);

                    //It traces all the pointers that in a branch are assigned to null and in the other are assigned to an allocated area of memory
                    //This information is used in order to refine the Join, as otherwise we would lose the size of the allocated memory
                    foreach (BoxedExpression ptr in bottomPointers)
                    {
                        BoxedExpression len;
                        // TODO: if this doesn't work, we need to pass in the pc to GetAssociatedInfo !
                        if (ptr.TryGetAssociatedInfo(pc, AssociatedInfo.WritableBytes, out len))
                        {
                            RefineNullVariable(pc, len, prev, 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);
                    //}
                }
Beispiel #10
0
                private bool isZero(BoxedExpression a, IntervalsForUnsafeCode oracle)
                {
                    Interval interval = oracle.BoundsFor(a);

                    return(interval.LowerBound == 0 && interval.UpperBound == 0);
                }
 public IntervalsForUnsafeCode(IntervalsForUnsafeCode original, IExpressionContext <APC, Local, Parameter, Method, Field, Type, ExternalExpression, Variable> context)
     : base(original)
 {
     this.context = context;
     this.decoder = original.decoder;
 }
                /// <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);
                }