public ParametersFixMethodCallReturnValue(ProofObligation obl, APC pc, Func <APC> pcWithSourceContext, Variable dest, ArgList args,
                                                  BoxedExpression condition, List <BoxedExpression> premises,
                                                  Method method,
                                                  IDecodeMethods <Method> mdDecoder,
                                                  ICFG cfg,
                                                  Func <APC, BoxedExpression, bool, BoxedExpression> ReadAt,
                                                  Func <APC, Variable, FList <PathElement> > AccessPath,
                                                  Func <FList <PathElement>, bool> IsRootedInParameter,
                                                  Func <Variable, FList <PathElement>, BoxedExpression> MakeMethodCall, Func <Variable, BoxedExpression> MakeEqualZero
                                                  )
        {
            Contract.Requires(mdDecoder != null);

            this.obl = obl;
            this.pc  = pc;
            this.pcWithSourceContext = pcWithSourceContext;
            this.dest                = dest;
            this.args                = args;
            this.condition           = condition;
            this.premises            = premises;
            this.mdDecoder           = mdDecoder;
            this.cfg                 = cfg;
            this.method              = method;
            this.ReadAt              = ReadAt;
            this.AccessPath          = AccessPath;
            this.IsRootedInParameter = IsRootedInParameter;
            this.MakeMethodCall      = MakeMethodCall;
            this.MakeEqualZero       = MakeEqualZero;
        }
        public ProofOutcome AddObjectInvariants(ProofObligation obl, IEnumerable <BoxedExpression> objectInvariants, ProofOutcome originalOutcome)
        {
            Contract.Requires(obl != null);
            Contract.Requires(objectInvariants != null);

            return(ProofOutcome.Top);
        }
Beispiel #3
0
        public ProofOutcome AddPreconditions(ProofObligation obl, IEnumerable <BoxedExpression> preconditions, ProofOutcome originalOutcome)
        {
            Contract.Requires(obl != null);
            Contract.Requires(preconditions != null);

            return(ProofOutcome.Top);
        }
        public bool TryInferConditions(ProofObligation obl, ICodeFixesManager codefixesManager, out InferredConditions preConditions)
        {
            preConditions = null;
            foreach (var inferencer in this.inferencers)
            {
                if (inferencer == null)
                {
                    continue;
                }

                InferredConditions tmp;
                if (inferencer.TryInferConditions(obl, codefixesManager, out tmp))
                {
                    Contract.Assert(tmp != null);
                    if (preConditions == null)
                    {
                        preConditions = tmp;
                    }
                    else
                    {
                        preConditions.AddRange(tmp);
                    }
                }
            }

            return(preConditions != null);
        }
Beispiel #5
0
        virtual public bool TryInferConditions(ProofObligation obl, ICodeFixesManager codefixesManager, out InferredConditions preConditions)
        {
            var preConds = PreconditionSuggestion.ExpressionsInPreState(obl.ConditionForPreconditionInference, this.MethodDriver.Context, this.MethodDriver.MetaDataDecoder, obl.PC, allowedKinds: ExpressionInPreStateKind.All);

            preConditions = /*preConds == null ? null : */ preConds.Where(pre => pre.hasVariables).AsInferredPreconditions(isSufficient: true);
            return /*preConditions != null && */ (preConditions.Any());
        }
Beispiel #6
0
        public IEnumerable <WarningContext> AddCalleeAssumes(ProofObligation obl, IEnumerable <IInferredCondition> assumes)
        {
            Contract.Requires(obl != null);
            Contract.Requires(assumes != null);

            Contract.Ensures(Contract.Result <IEnumerable <WarningContext> >() != null);

            return(null);
        }
        public void AddPotentialPreconditions(ProofObligation obl, IEnumerable <BoxedExpression> preconditions)
        {
            var newPre = preconditions.Distinct().ToList().ConvertAll(exp => this.BoxedExpressionTransformer.Visit(exp, new Void()));

            this.inferenceSitesToExpressions.AddOrUpdate(this.CurrentMethod, newPre);

            foreach (var m in this.mdDecoder.OverriddenAndImplementedMethods(CurrentMethod))
            {
                this.definitionsToExpressions.AddOrUpdate(m, newPre);
            }
        }
        public ParametersSuggestOffByOneFix(ProofObligation obl, APC pc, Func <APC, APC> pcWithSourceContext, bool isArrayAccess, BoxedExpression exp, Func <Variable, FList <PathElement> > AccessPath, Func <BoxedExpression, bool> IsArrayLength, IFactQuery <BoxedExpression, Variable> factQuery)
        {
            Contract.Requires(pcWithSourceContext != null);

            this.obl = obl;
            this.pc  = pc;
            this.pcWithSourceContext = pcWithSourceContext(pc);
            this.isArrayAccess       = isArrayAccess;
            this.exp           = exp;
            this.AccessPath    = AccessPath;
            this.IsArrayLength = IsArrayLength;
            this.factQuery     = factQuery;
        }
        public InitializationFix(ProofObligation obl, APC pc, Variable dest, BoxedExpression sourceExp, Set <Variable> varsInSourceExp)
        {
            Contract.Requires(obl != null);
            Contract.Requires(sourceExp != null);
            Contract.Requires(varsInSourceExp != null);

            this.obl              = obl;
            this.pc               = pc;
            this.dest             = dest;
            this.sourceExp        = sourceExp;
            this.varsInSourceExp  = varsInSourceExp;
            this.cached_SourceExp = default(Optional <BoxedExpression>);
        }
Beispiel #10
0
        public override bool TryInferConditions(ProofObligation obl, ICodeFixesManager codefixesManager, out InferredConditions preConditions)
        {
            // First we try to read exp in the prestate

            if (base.TryInferConditions(obl, codefixesManager, out preConditions))
            {
                // if we succeed, now we should prove it is a precondition according to Sect. 4 of [CCL-VMCAI11]
                var necessarypreConditions = preConditions.Where(pre => new PreconditionCheckedAllOverThePathsAnalysis(this.obligations, this.MethodDriver).CheckPreconditionAdmissibility(pre.Expr)).AsInferredPreconditions();
                obl.NotifySufficientYetNotNecessaryPreconditions(preConditions.Except(necessarypreConditions));

                preConditions = necessarypreConditions;
                return(necessarypreConditions.Any());
            }

            return(false);
        }
Beispiel #11
0
        public ProofOutcome AddPreconditionOrAssume(ProofObligation obl, IEnumerable <BoxedExpression> conditions, ProofOutcome outcome = ProofOutcome.Top)
        {
            Contract.Requires(conditions != null);
            Contract.Requires(obl != null);

            if (this.CanAddPreconditions)
            {
                Contract.Assume(this.PreCondition.Dispatch != null);
                return(this.PreCondition.Dispatch.AddPreconditions(obl, conditions, outcome));
            }
            else
            {
                this.Assumptions.AddEntryAssumes(obl, conditions);
                this.OverriddenMethodPreconditionDispatcher.AddPotentialPreconditions(obl, conditions);

                return(outcome);
            }
        }
        protected ProofOutcome GenericAddPreconditions(ProofObligation obl, IEnumerable <BoxedExpression> preconditions, ProofOutcome originalOutcome,
                                                       InferenceDB preconditionDB, PreconditionChecker checkPrecondition)
        {
            var outcome = originalOutcome;

            foreach (var pre in preconditions)
            {
                if (pre == null)
                {
                    continue;
                }

                // 1. Simplify the expression
                var simplified = SimplifyAndFix(obl.PCForValidation, pre);

                if (simplified == null)
                {
                    continue;
                }

                if (DisjunctivePreconditionsAreDisallowed(simplified))
                {
                    continue;
                }

                // 2. Have we already seen this precondition?
                if (preconditionDB.TryLookUp(obl, simplified, out outcome))
                {
                    continue;
                }
                else
                {
                    outcome = originalOutcome;
                }

                // 3. See if it is valid
                if (checkPrecondition(simplified, outcome, out outcome))
                {
                    preconditionDB.Add(obl, simplified, outcome);
                }
            }

            return(outcome);
        }
        static private void WalkProvenance(ProofObligation thisObl, int depth, Witness witness)
        {
            var obligationList = thisObl.Provenance;

            if (obligationList != null && obligationList.Any())
            {
                foreach (var obl in obligationList)
                {
                    Contract.Assume(obl != null);
                    if (obl.Condition != null)
                    {
                        var depthString = new String('-', depth + 1);

                        witness.AddTrace(obl.PC, string.Format("{0} Cause {1} obligation: {2}", depthString, obl.ObligationName, obl.Condition.ToString()));

                        WalkProvenance(obl, depth + 1, witness);
                    }
                }
            }
        }
Beispiel #14
0
        public bool TryInferConditions(ProofObligation obl, ICodeFixesManager codefixesManager, out InferredConditions preConditions)
        {
            var watch = new Stopwatch();

            watch.Start();
            var result = inner.TryInferConditions(obl, codefixesManager, out preConditions);

            watch.Stop();

            inferenceTime += watch.Elapsed;

            if (preConditions == null)
            {
                return(false);
            }

            if (result)
            {
                inferred += preConditions.Count();
            }

            return(result);
        }
        public IEnumerable <WarningContext> AddCalleeAssumes(ProofObligation obl, IEnumerable <IInferredCondition> calleeAssumes)
        {
            var md     = this.mdriver;
            var result = new List <WarningContext>();

            foreach (var calleeAssume in calleeAssumes.OfType <InferredCalleeCondition <Method> >())
            {
                InferenceDB db;
                if (!this.calleeAssumptions.TryGetValue(calleeAssume.Callee, out db))
                {
                    var calleeWarningContext = GetContextForCallee(calleeAssume.Callee);
                    db = new InferenceDB(exp => exp.Simplify(md.MetaDataDecoder), _ => true, calleeWarningContext);
                    this.calleeAssumptions.Add(calleeAssume.Callee, db);
                    this.calleeAssumptionsPCs.Add(calleeAssume.Callee, new List <APC>()); // add the entry to the map calleAssumptions --> PC

                    // Get the witnesses for the scoring
                    result.Add(new WarningContext(WarningContext.ContextType.InferredCalleeAssume, (int)calleeWarningContext));

                    if (calleeAssume.Expr.IsBinary && calleeAssume.Expr.BinaryOp == BinaryOperator.LogicalOr)
                    {
                        result.Add(new WarningContext(WarningContext.ContextType.InferredCalleeAssumeContainsDisjunction, /*unused?*/ 1));
                    }

                    if (md.AnalysisDriver.MethodCache.GetWitnessForMayReturnNull(calleeAssume.Callee))
                    {
                        result.Add(new WarningContext(WarningContext.ContextType.ViaMethodCallThatMayReturnNull, /*unused?*/ 1));
                    }
                }
                base.GenericAddPreconditions(obl, new[] { calleeAssume.Expr }, ProofOutcome.Top, db, this.True);
                this.calleeAssumptionsPCs[calleeAssume.Callee].Add(calleeAssume.CalleePC);
            }

            this.necessaryPostconditionCandidates = calleeAssumes.OfType <InferredCalleeNecessaryConditionCandidate <Method> >();

            return(result.Distinct());
        }
Beispiel #16
0
 public bool TrySuggestTestStrengthening(ProofObligation obl, APC pc, BoxedExpression additionalGuard, bool strengthenNullCheck)
 {
     return(ProfileAndTrace("Test strenghtening", inner.TrySuggestTestStrengthening(obl, pc, additionalGuard, strengthenNullCheck), ref TestStrenghteningFixes));
 }
Beispiel #17
0
 public bool TrySuggestTestFix <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(ProofObligation obl, Func <APC> pc, BoxedExpression guard, BoxedExpression failingCondition, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> metaDataDecoder, Func <BoxedExpression, bool> IsArrayLength)
 {
     return(ProfileAndTrace("Condition in a test", inner.TrySuggestTestFix(obl, pc, guard, failingCondition, metaDataDecoder, IsArrayLength), ref TestFalseFixes));
 }
Beispiel #18
0
 public IEnumerable <WarningContext> AddCalleeAssumes(ProofObligation obl, IEnumerable <IInferredCondition> assumes)
 {
     calleeAssumeStatistics.Generated += assumes.Count();
     return(this.inner.AddCalleeAssumes(obl, assumes));
 }
Beispiel #19
0
 public void AddEntryAssumes(ProofObligation obl, IEnumerable <BoxedExpression> assumes)
 {
     Contract.Requires(obl != null);
     Contract.Requires(assumes != null);
 }
Beispiel #20
0
 public bool TrySuggestConstantInitializationFix <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Variable>(ProofObligation obl, Func <APC> pc, BoxedExpression failingCondition, BoxedExpression falseCondition, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> metaDataDecoder, Func <Variable, BoxedExpression> VariableValueBeforeRenaming, Func <Variable, BoxedExpression> VariableName)
 {
     return(false);
 }
Beispiel #21
0
 public void AddEntryAssumes(ProofObligation obl, IEnumerable <BoxedExpression> assumes)
 {
     entryAssumeStatistics.Generated += assumes.Count();
     this.inner.AddEntryAssumes(obl, assumes);
 }
Beispiel #22
0
 public bool TrySuggestConstantInititalizationFix(ProofObligation obl, APC pc, BoxedExpression dest, BoxedExpression oldInitialization, BoxedExpression newInitialization, BoxedExpression constraint)
 {
     return(false);
 }
Beispiel #23
0
 public bool TryInferConditions(ProofObligation obl, ICodeFixesManager codefixesManager, out InferredConditions preConditions)
 {
     preConditions = null;
     return(false);
 }
 public ProofOutcome AddObjectInvariants(ProofObligation obl, IEnumerable <BoxedExpression> objectInvariants, ProofOutcome originalOutcome)
 {
     generated += objectInvariants.Count();
     return(this.inner.AddObjectInvariants(obl, objectInvariants, originalOutcome));
 }
Beispiel #25
0
 public bool TrySuggestTestFix <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(ProofObligation obl, Func <APC> pc, BoxedExpression guard, BoxedExpression failingCondition, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> metaDataDecoder, Func <BoxedExpression, bool> IsArrayLength)
 {
     return(false);
 }
Beispiel #26
0
 public bool TrySuggestTestStrengthening(ProofObligation obl, APC pc, BoxedExpression additionalGuard, bool strengthenNullCheck)
 {
     return(false);
 }
Beispiel #27
0
 public bool TrySuggestFloatingPointComparisonFix(ProofObligation obl, APC pc, BoxedExpression left, BoxedExpression right, ConcreteFloat leftType, ConcreteFloat rightType)
 {
     return(false);
 }
Beispiel #28
0
 public bool TrySuggestLargerAllocation <Variable>(ProofObligation obl, Func <APC> definitionPC, APC failingConditionPC, BoxedExpression failingCondition, Variable array, Variable length, Func <Variable, BoxedExpression> Converter, IFactQuery <BoxedExpression, Variable> factQuery)
 {
     return(false);
 }
Beispiel #29
0
 public ProofOutcome AddPreconditions(ProofObligation obl, IEnumerable <BoxedExpression> preconditions, ProofOutcome originalOutcome)
 {
     return(inner.AddPreconditions(obl, preconditions, originalOutcome));
 }
Beispiel #30
0
 public bool TrySuggestFloatingPointComparisonFix(ProofObligation obl, APC pc, BoxedExpression left, BoxedExpression right, ConcreteFloat leftType, ConcreteFloat rightType)
 {
     return(ProfileAndTrace("Floating point comparison", inner.TrySuggestFloatingPointComparisonFix(obl, pc, left, right, leftType, rightType), ref FloatComparisonMismatchesFixes));
 }