Ejemplo n.º 1
0
    private void WaitForOutput(object dummy) {
      lock (this)
      {
        try
        {
          outcome = thmProver.CheckOutcome(cce.NonNull(handler));
        }
        catch (UnexpectedProverOutputException e)
        {
          outputExn = e;
        }

        switch (outcome)
        {
          case ProverInterface.Outcome.Valid:
            thmProver.LogComment("Valid");
            break;
          case ProverInterface.Outcome.Invalid:
            thmProver.LogComment("Invalid");
            break;
          case ProverInterface.Outcome.TimeOut:
            thmProver.LogComment("Timed out");
            break;
          case ProverInterface.Outcome.OutOfMemory:
            thmProver.LogComment("Out of memory");
            break;
          case ProverInterface.Outcome.Undetermined:
            thmProver.LogComment("Undetermined");
            break;
        }

        hasOutput = true;
        proverRunTime = DateTime.UtcNow - proverStart;
      }
    }
Ejemplo n.º 2
0
        public ProverInterface.Outcome Verify(ProverInterface proverInterface, Dictionary <Variable, bool> assignment, out List <Counterexample> errors, int taskID = -1)
        {
            collector.examples.Clear();

            if (CommandLineOptions.Clo.Trace)
            {
                Console.WriteLine("Verifying " + descriptiveName);
            }
            DateTime now = DateTime.UtcNow;

            VCExpr vc = proverInterface.VCExprGen.Implies(BuildAxiom(proverInterface, assignment), conjecture);

            proverInterface.BeginCheck(descriptiveName, vc, handler);
            ProverInterface.Outcome proverOutcome = proverInterface.CheckOutcome(handler, taskID: taskID);

            double queryTime = (DateTime.UtcNow - now).TotalSeconds;

            stats.proverTime += queryTime;
            stats.numProverQueries++;
            if (CommandLineOptions.Clo.Trace)
            {
                Console.WriteLine("Outcome = " + proverOutcome);
                Console.WriteLine("Time taken = " + queryTime);
            }

            errors = collector.examples;
            return(proverOutcome);
        }
Ejemplo n.º 3
0
 public override void OnModel(IList <string> labels, Model model, ProverInterface.Outcome proverOutcome)
 {
     if (CommandLineOptions.Clo.PrintErrorModel >= 1 && model != null)
     {
         model.Write(Console.Out);
     }
     this.model = model;
 }
Ejemplo n.º 4
0
        protected override void HoudiniVerifyCurrent(HoudiniSession session, int stage, IEnumerable <int> completedStages)
        {
            while (true)
            {
                this.NotifyAssignment(currentHoudiniState.Assignment);

                //check the VC with the current assignment
                List <Counterexample>   errors;
                ProverInterface.Outcome outcome = TryCatchVerify(session, stage, completedStages, out errors);
                this.NotifyOutcome(outcome);

                DebugRefutedCandidates(currentHoudiniState.Implementation, errors);

                #region Explain Houdini
                if (CommandLineOptions.Clo.ExplainHoudini && outcome == ProverInterface.Outcome.Invalid)
                {
                    Contract.Assume(errors != null);
                    // make a copy of this variable
                    errors = new List <Counterexample>(errors);
                    var refutedAnnotations = new List <RefutedAnnotation>();
                    foreach (Counterexample error in errors)
                    {
                        RefutedAnnotation refutedAnnotation = ExtractRefutedAnnotation(error);
                        if (refutedAnnotation == null || refutedAnnotation.Kind == RefutedAnnotationKind.ASSERT)
                        {
                            continue;
                        }
                        refutedAnnotations.Add(refutedAnnotation);
                    }
                    foreach (var refutedAnnotation in refutedAnnotations)
                    {
                        session.Explain(proverInterface, currentHoudiniState.Assignment, refutedAnnotation.Constant);
                    }
                }
                #endregion

                if (UpdateHoudiniOutcome(currentHoudiniState.Outcome, currentHoudiniState.Implementation, outcome, errors)) // abort
                {
                    currentHoudiniState.WorkQueue.Dequeue();
                    this.NotifyDequeue();
                    FlushWorkList(stage, completedStages);
                    return;
                }
                else if (UpdateAssignmentWorkList(outcome, errors))
                {
                    if (CommandLineOptions.Clo.UseUnsatCoreForContractInfer && outcome == ProverInterface.Outcome.Valid)
                    {
                        session.UpdateUnsatCore(proverInterface, currentHoudiniState.Assignment);
                    }
                    currentHoudiniState.WorkQueue.Dequeue();
                    this.NotifyDequeue();
                    return;
                }
            }
        }
Ejemplo n.º 5
0
 // This method is called to inform about the prover outcome for the previous GetNextBlock call.
 override public bool SetCurrentResult(List <Variable> reachvar, ProverInterface.Outcome outcome, DoomErrorHandler cb)
 {
     this.__DEBUG_BlocksChecked++;
     // outcome==Valid means that there is no feasible execution for the current block/path (i.e., might be doomed)
     if (outcome == ProverInterface.Outcome.Valid && m_Current <= m_Blocks.Count)
     {
         List <Block> lb = new List <Block>();
         lb.Add(m_Blocks[m_Current - 1]);
         DetectedBlock.Add(lb);
     }
     return(true);
 }
Ejemplo n.º 6
0
        override public bool SetCurrentResult(List <Variable> reachvar, ProverInterface.Outcome outcome, DoomErrorHandler cb)
        {
            this.__DEBUG_BlocksChecked++;
            // Valid means infeasible...
            int oldl    = MinBlocks;
            int oldsize = m_Uncheckedlocks.Count;


            if (outcome == ProverInterface.Outcome.Valid)
            {
                this.__DEBUG_InfeasibleTraces++;
                if (MinBlocks == 1)
                {
                    m_NoMoreMoves = true;
                }
                else
                {
                    MinBlocks = 1;
                }
            }
            else if (outcome == ProverInterface.Outcome.Invalid)
            {
                this.__DEBUG_TracesChecked++;

                List <Block> errortrace = m_GetErrorTraceFromCE(cb);
                foreach (Block b in errortrace)
                {
                    if (m_Uncheckedlocks.Contains(b))
                    {
                        m_Uncheckedlocks.Remove(b);
                    }
                }
                cb.TraceNodes.Clear();
                m_MaxK = m_BlockH.GetMaxK(m_Uncheckedlocks);
                if (m_MaxK < 1)
                {
                    m_NoMoreMoves = true; m_Uncheckedlocks.Clear();
                }
                MinBlocks = m_MaxK / 2 + (m_MaxK % 2 > 0 ? 1 : 0);
                //if (MinBlocks > m_MaxK) MinBlocks = m_MaxK;
            }
            else
            {
                m_NoMoreMoves = true; m_Uncheckedlocks.Clear();
            }
            if (__DEBUGOUT)
            {
                Console.WriteLine("K := {0,3}, L := {1,3}, deltaSp {2,3}, out {3,8}, time {4,8}", MaxBlocks, oldl, (oldsize - m_Uncheckedlocks.Count), outcome, sw.ElapsedTicks);
            }
            sw.Stop();
            sw.Reset();
            return(true);
        }
Ejemplo n.º 7
0
 public void Retarget(Program prog, ProverContext ctx)
 {
     lock (this)
     {
         hasOutput = default(bool);
         outcome   = default(ProverInterface.Outcome);
         outputExn = default(UnexpectedProverOutputException);
         handler   = default(ProverInterface.ErrorHandler);
         TheoremProver.FullReset(gen);
         ctx.Reset();
         Setup(prog, ctx);
     }
 }
Ejemplo n.º 8
0
            private static List <VCExpr> AnalyzeUsingUnsatCoreHelper(VCExpr programVC,
                                                                     ref List <Counterexample> cexs,
                                                                     ref ProverInterface.Outcome outcome,
                                                                     ref VCExpr preInp, List <VCExpr> assumptions)
            {
                List <int> unsatClauseIdentifiers = new List <int>();

                if (true) //in case we have to turn off the unsat core related logic
                {
                    //VERY IMPORTANT: TO USE UNSAT CORE, SET ContractInfer to true in CommandLineOptions.Clo.
                    outcome = ProverInterface.Outcome.Undetermined;
                    outcome = SymDiffVC.proverInterface.CheckAssumptions(assumptions, out unsatClauseIdentifiers, SymDiffVC.handler);
                    Debug.Assert(outcome == ProverInterface.Outcome.Valid);
                    Console.Write("+");
                    Debug.Assert(unsatClauseIdentifiers.Count() > 0, "Something went wrong! Unsat core with 0 elements");
                    //newVC should be always at 0, since it has to participate in inconsistency
                    Debug.Assert(unsatClauseIdentifiers.Remove(0), "Something went wrong! The VC itself is not part of UNSAT core");
                }
                var core0 = unsatClauseIdentifiers.Count() > 0 ?
                            unsatClauseIdentifiers.Select(i => assumptions[i]) :
                            assumptions;

                Console.Write("(upper bound on tainted after unsat core ={0}/{1})", core0.Count(), assumptions.Count() / 2);
                var core = new List <VCExpr>(core0);

                //Core may not be minimal, need to iterate
                if (true)
                {
                    foreach (var b in core0)
                    {
                        //for singleton checks, we can disable all other Booleans to only consider this equality
                        var tmpAssumps = new List <VCExpr>(assumptions);
                        tmpAssumps.Remove(b);
                        preInp = tmpAssumps.Aggregate(VCExpressionGenerator.True, (x, y) => SymDiffVC.exprGen.And(x, y));
                        preInp = SymDiffVC.exprGen.And(preInp, SymDiffVC.exprGen.Not(b)); //consider the actual output
                        Console.Write(".");
                        outcome = SymDiffVC.VerifyVC("RefinedStmtTaint", SymDiffVC.exprGen.Implies(preInp, programVC), out cexs);
                        if (outcome == ProverInterface.Outcome.Valid)
                        {
                            Console.Write("*");
                            core.Remove(b);
                            continue;
                        }
                        Console.Write("/"); //possibly different
                    }
                }
                return(core);
            }
Ejemplo n.º 9
0
        public void UpdateUnsatCore(ProverInterface proverInterface, Dictionary <Variable, bool> assignment)
        {
            DateTime now = DateTime.UtcNow;

            Boogie2VCExprTranslator exprTranslator = proverInterface.Context.BoogieExprTranslator;

            proverInterface.Push();
            proverInterface.Assert(conjecture, false);
            foreach (var v in assignment.Keys)
            {
                if (assignment[v])
                {
                    continue;
                }
                proverInterface.Assert(exprTranslator.LookupVariable(v), false);
            }

            List <Variable> assumptionVars  = new List <Variable>();
            List <VCExpr>   assumptionExprs = new List <VCExpr>();

            foreach (var v in assignment.Keys)
            {
                if (!assignment[v])
                {
                    continue;
                }
                assumptionVars.Add(v);
                assumptionExprs.Add(exprTranslator.LookupVariable(v));
            }

            List <int> unsatCore;

            ProverInterface.Outcome tmp = proverInterface.CheckAssumptions(assumptionExprs, out unsatCore, handler);
            System.Diagnostics.Debug.Assert(tmp == ProverInterface.Outcome.Valid);
            unsatCoreSet = new HashSet <Variable>();
            foreach (int i in unsatCore)
            {
                unsatCoreSet.Add(assumptionVars[i]);
            }
            proverInterface.Pop();

            double unsatCoreQueryTime = (DateTime.UtcNow - now).TotalSeconds;

            stats.unsatCoreProverTime += unsatCoreQueryTime;
            stats.numUnsatCoreProverQueries++;
        }
Ejemplo n.º 10
0
        // This method is called to inform about the prover outcome for the previous GetNextBlock call.
        override public bool SetCurrentResult(List <Variable> reachvar, ProverInterface.Outcome outcome, DoomErrorHandler cb)
        {
            this.__DEBUG_BlocksChecked++;
            // outcome==Valid means that there is no feasible execution for the current block/path (i.e., might be doomed)
            if (outcome == ProverInterface.Outcome.Valid && m_Current <= m_Blocks.Count)
            {
                m_doomedBlocks.Add(m_Blocks[m_Current - 1]);
            }
            if (__DEBUGOUT)
            {
                Console.WriteLine("K := {0,3} , out {1,8}, time {2,12}", MaxBlocks, outcome, sw.ElapsedTicks);
            }
            sw.Stop();
            sw.Reset();

            return(true);
        }
Ejemplo n.º 11
0
        public override void OnModel(IList <string> /*!>!*/ labels, Model model, ProverInterface.Outcome proverOutcome)
        {
            // TODO: it would be better to check which reachability variables are actually set to one!
            List <Block>     traceNodes  = new List <Block>();
            List <AssertCmd> assertNodes = new List <AssertCmd>();

            foreach (string s in labels)
            {
                Contract.Assert(s != null);
                Absy node = Label2Absy(s);
                if (node is Block)
                {
                    Block b = (Block)node;
                    traceNodes.Add(b);
                    //Console.Write("{0}, ", b.Label);
                }
            }
            m_CurrentTrace.AddRange(traceNodes);
        }
Ejemplo n.º 12
0
 // This method is called to inform about the prover outcome for the previous GetNextBlock call.
 override public bool SetCurrentResult(List <Variable> reachvar, ProverInterface.Outcome outcome, DoomErrorHandler cb)
 {
     this.__DEBUG_BlocksChecked++;
     // outcome==Valid means that there is no feasible execution for the current block/path (i.e., might be doomed)
     if (outcome == ProverInterface.Outcome.Valid && m_Current != null)
     {
         m_doomedBlocks.Add(m_Current);
     }
     else if (outcome == ProverInterface.Outcome.Invalid)
     {
         List <Block> errortrace = m_GetErrorTraceFromCE(cb);
         foreach (Block b in errortrace)
         {
             if (m_Blocks.Contains(b))
             {
                 m_Blocks.Remove(b);
             }
         }
         cb.TraceNodes.Clear();
     }
     return(true);
 }
Ejemplo n.º 13
0
        bool ReCheckImpl(Variable reachvar, Implementation impl, VerifierCallback callback,
                         out ProverInterface.Outcome outcome)
        {
            Contract.Requires(reachvar != null);
            Contract.Requires(impl != null);
            Contract.Requires(callback != null);
            Checker checker = FindCheckerFor(impl, 1000);

            Contract.Assert(checker != null);
            DoomCheck dc = new DoomCheck(impl, this.exitBlock, checker, m_UncheckableBlocks);

            dc.ErrorHandler = new DoomErrorHandler(dc.Label2Absy, callback);
            outcome         = ProverInterface.Outcome.Undetermined;
            List <Variable> rv = new List <Variable>();

            rv.Add(reachvar);
            if (!dc.CheckLabel(rv, null, out outcome))
            {
                checker.Close();
                return(false);
            }
            checker.Close();
            return(true);
        }
Ejemplo n.º 14
0
 /*  - Checking a label means to ask the prover if |= ( rvar=false -> vc ) holds.
  *  - outcome is set to Outcome.Invalid if the Block denoted by reachvar is doomed.
  *  - returns false if the theorem prover throws an exception, otherwise true.
  */
 public bool CheckLabel(List <Variable> lv, Dictionary <Expr, int> finalreachvars, out ProverInterface.Outcome outcome)
 {
     Contract.Requires(lv != null);
     outcome = ProverInterface.Outcome.Undetermined;
     DEBUG_ProverTime.Reset();
     DEBUG_ProverTime.Start();
     if (m_Evc.CheckReachvar(lv, finalreachvars, m_Order.MaxBlocks, m_Order.MinBlocks, m_Order.HACK_NewCheck, out outcome))
     {
         DEBUG_ProverTime.Stop();
         if (!m_Order.SetCurrentResult(lv, outcome, m_ErrHandler))
         {
             outcome = ProverInterface.Outcome.Undetermined;
         }
         return(true);
     }
     else
     {
         DEBUG_ProverTime.Stop();
         Console.WriteLine(outcome);
         m_Order.SetCurrentResult(lv, ProverInterface.Outcome.Undetermined, m_ErrHandler);
         return(false);
     }
 }
Ejemplo n.º 15
0
        private void WaitForOutput(object dummy)
        {
            lock (this)
              {
            try
            {
              outcome = thmProver.CheckOutcome(cce.NonNull(handler));
            }
            catch (UnexpectedProverOutputException e)
            {
              outputExn = e;
            }

            switch (outcome)
            {
              case ProverInterface.Outcome.Valid:
            thmProver.LogComment("Valid");
            break;
              case ProverInterface.Outcome.Invalid:
            thmProver.LogComment("Invalid");
            break;
              case ProverInterface.Outcome.TimeOut:
            thmProver.LogComment("Timed out");
            break;
              case ProverInterface.Outcome.OutOfMemory:
            thmProver.LogComment("Out of memory");
            break;
              case ProverInterface.Outcome.Undetermined:
            thmProver.LogComment("Undetermined");
            break;
            }

            hasOutput = true;
            proverRunTime = DateTime.UtcNow - proverStart;
              }
        }
Ejemplo n.º 16
0
 public void Retarget(Program prog, ProverContext ctx, int timeout = 0)
 {
     lock (this)
       {
     hasOutput = default(bool);
     outcome = default(ProverInterface.Outcome);
     outputExn = default(UnexpectedProverOutputException);
     handler = default(ProverInterface.ErrorHandler);
     TheoremProver.FullReset(gen);
     ctx.Reset();
     Setup(prog, ctx);
     this.timeout = timeout;
     SetTimeout();
       }
 }
Ejemplo n.º 17
0
        public bool CheckReachvar(List <Variable> lv, Dictionary <Expr, int> finalreachvars,
                                  int k, int l, bool usenew, out ProverInterface.Outcome outcome)
        {
            Contract.Requires(lv != null);

            VCExpr vc = VCExpressionGenerator.False;

            if (usenew)
            {
                foreach (Variable v in lv)
                {
                    vc = m_Checker.VCExprGen.Or(
                        m_Checker.VCExprGen.Neq(
                            m_Checker.VCExprGen.Integer(BigNum.ZERO),
                            m_Checker.TheoremProver.Context.BoogieExprTranslator.LookupVariable(v)),
                        vc);
                }
                //Console.WriteLine("TPQuery k={0}, l={1}, |Sp|={2}", k, l, finalreachvars.Count);

                VCExpr vc21 = m_Checker.VCExprGen.Integer(BigNum.ZERO); // Ask: is the necessary or can we use the same instance term in two inequalities?
                VCExpr vc22 = m_Checker.VCExprGen.Integer(BigNum.ZERO);

                foreach (KeyValuePair <Expr, int> kvp in finalreachvars)
                {
                    vc21 = m_Checker.VCExprGen.Add(vc21, m_Checker.TheoremProver.Context.BoogieExprTranslator.Translate(kvp.Key));
                    vc22 = m_Checker.VCExprGen.Add(vc22, m_Checker.TheoremProver.Context.BoogieExprTranslator.Translate(kvp.Key));
                }

                VCExpr post = m_Checker.VCExprGen.Gt(m_Checker.VCExprGen.Integer(BigNum.FromInt(l)), vc21);

                if (k != -1)
                {
                    post = m_Checker.VCExprGen.Or(
                        post, m_Checker.VCExprGen.Gt(vc22, m_Checker.VCExprGen.Integer(BigNum.FromInt(k)))
                        );
                }
                vc = (m_Checker.VCExprGen.Or(vc, (post)));
            }
            else
            {
                foreach (Variable v in lv)
                {
                    vc = m_Checker.VCExprGen.Or(
                        m_Checker.VCExprGen.Eq(
                            m_Checker.VCExprGen.Integer(BigNum.ONE),
                            m_Checker.TheoremProver.Context.BoogieExprTranslator.LookupVariable(v)),
                        vc);
                }
                Contract.Assert(vc != null);

                // Add the desired outcome of the reachability variables
                foreach (KeyValuePair <Expr, int> kvp in finalreachvars)
                {
                    vc = m_Checker.VCExprGen.Or(
                        m_Checker.VCExprGen.Neq(
                            m_Checker.VCExprGen.Integer(BigNum.FromInt(kvp.Value)),
                            m_Checker.TheoremProver.Context.BoogieExprTranslator.Translate(kvp.Key)),
                        vc);
                }
            }

            // Todo: Check if vc is trivial true or false
            outcome = ProverInterface.Outcome.Undetermined;
            Contract.Assert(m_ErrorHandler != null);
            try
            {
                m_Checker.BeginCheck(lv[0].Name, vc, m_ErrorHandler);
                m_Checker.ProverTask.Wait();
                outcome = m_Checker.ReadOutcome();
            }
            catch (UnexpectedProverOutputException e)
            {
                if (CommandLineOptions.Clo.TraceVerify)
                {
                    Console.WriteLine("Prover is unable to check {0}! Reason:", lv[0].Name);
                    Console.WriteLine(e.ToString());
                }
                return(false);
            }
            finally
            {
                m_Checker.GoBackToIdle();
            }
            return(true);
        }
Ejemplo n.º 18
0
        public void ReadOutcome(ref ConditionGeneration.Outcome curOutcome, out bool proverFailed)
        {
            Contract.EnsuresOnThrow <UnexpectedProverOutputException>(true);
            ProverInterface.Outcome outcome = cce.NonNull(checker).ReadOutcome();

            if (CommandLineOptions.Clo.Trace && splitNum >= 0)
            {
                System.Console.WriteLine("      --> split #{0} done,  [{1} s] {2}", splitNum,
                                         checker.ProverRunTime.TotalSeconds, outcome);
            }

            if (CommandLineOptions.Clo.VcsDumpSplits)
            {
                DumpDot(splitNum);
            }

            proverFailed = false;

            switch (outcome)
            {
            case ProverInterface.Outcome.Valid:
                return;

            case ProverInterface.Outcome.Invalid:
                curOutcome = ConditionGeneration.Outcome.Errors;
                return;

            case ProverInterface.Outcome.OutOfMemory:
                proverFailed = true;
                if (curOutcome != ConditionGeneration.Outcome.Errors && curOutcome != ConditionGeneration.Outcome.Inconclusive)
                {
                    curOutcome = ConditionGeneration.Outcome.OutOfMemory;
                }
                return;

            case ProverInterface.Outcome.TimeOut:
                proverFailed = true;
                if (curOutcome != ConditionGeneration.Outcome.Errors && curOutcome != ConditionGeneration.Outcome.Inconclusive)
                {
                    curOutcome = ConditionGeneration.Outcome.TimedOut;
                }
                return;

            case ProverInterface.Outcome.OutOfResource:
                proverFailed = true;
                if (curOutcome != ConditionGeneration.Outcome.Errors && curOutcome != ConditionGeneration.Outcome.Inconclusive)
                {
                    curOutcome = ConditionGeneration.Outcome.OutOfResource;
                }
                return;

            case ProverInterface.Outcome.Undetermined:
                if (curOutcome != ConditionGeneration.Outcome.Errors)
                {
                    curOutcome = ConditionGeneration.Outcome.Inconclusive;
                }
                return;

            default:
                Contract.Assert(false);
                throw new cce.UnreachableException();
            }
        }
Ejemplo n.º 19
0
        bool BruteForceCESearch(Variable reachvar, Implementation impl, VerifierCallback callback,
                                Dictionary <Block, List <Cmd> > cmdbackup, int startidx, int endidx)
        {
            Contract.Requires(reachvar != null);
            Contract.Requires(impl != null);
            Contract.Requires(callback != null);
            Contract.Requires(cce.NonNullElements(cmdbackup));
            #region Modify implementation
            for (int i = startidx; i <= endidx; i++)
            {
                if (_copiedBlock.Contains(impl.Blocks[i]))
                {
                    continue;
                }
                List <Cmd> cs = new List <Cmd>();
                cmdbackup.Add(impl.Blocks[i], impl.Blocks[i].Cmds);
                foreach (Cmd c in impl.Blocks[i].Cmds)
                {
                    Contract.Assert(c != null);
                    if (ContainsReachVariable(c))
                    {
                        cs.Add(c);
                        continue;
                    }
                    AssertCmd ac = c as AssertCmd;
                    AssumeCmd uc = c as AssumeCmd;
                    if (ac != null)
                    {
                        cs.Add(new AssertCmd(ac.tok, Expr.True));
                    }
                    else if (uc != null)
                    {
                        cs.Add(new AssertCmd(uc.tok, Expr.True));
                    }
                    else
                    {
                        cs.Add(c);
                    }
                }
                impl.Blocks[i].Cmds = cs;
            }
            #endregion

            ProverInterface.Outcome outcome = ProverInterface.Outcome.Undetermined;
            if (!ReCheckImpl(reachvar, impl, callback, out outcome))
            {
                UndoBlockModifications(impl, cmdbackup, startidx, endidx);
                return(false);
            }
            if (outcome == ProverInterface.Outcome.Valid)
            {
                return(true);
            }
            else if (outcome == ProverInterface.Outcome.Invalid)
            {
                UndoBlockModifications(impl, cmdbackup, startidx, endidx);
                int mid = startidx + (endidx - startidx) / 2;
                if (startidx >= endidx)
                {
                    // Now we found an interesting Block and we have to
                    // search for the interesting statements.
                    int cmdcount = impl.Blocks[endidx].Cmds.Length;
                    BruteForceCmd(impl.Blocks[endidx], 0, cmdcount / 2 - 1, reachvar, impl, callback);
                    BruteForceCmd(impl.Blocks[endidx], cmdcount / 2, cmdcount - 1, reachvar, impl, callback);
                    return(true);
                }
                else
                {
                    BruteForceCESearch(reachvar, impl, callback, cmdbackup, startidx, mid);
                    BruteForceCESearch(reachvar, impl, callback, cmdbackup, mid + 1, endidx);
                    return(true);
                }
            }
            else
            {
                UndoBlockModifications(impl, cmdbackup, startidx, endidx);
                return(false);
            }
        }
Ejemplo n.º 20
0
 // This method is called to inform about the prover outcome for the previous GetNextBlock call.
 abstract public bool SetCurrentResult(List <Variable> reachvar, ProverInterface.Outcome outcome, DoomErrorHandler cb);
Ejemplo n.º 21
0
        bool BruteForceCmd(Block b, int startidx, int endidx, Variable reachvar,
                           Implementation impl, VerifierCallback callback)
        {
            Contract.Requires(b != null);
            Contract.Requires(reachvar != null);
            Contract.Requires(impl != null);
            Contract.Requires(callback != null);
            #region Modify Cmds
            List <Cmd> backup = b.Cmds;
            Contract.Assert(backup != null);
            List <Cmd> cs = new List <Cmd>();
            for (int i = 0; i < startidx; i++)
            {
                cs.Add(b.Cmds[i]);
            }
            for (int i = startidx; i <= endidx; i++)
            {
                Cmd c = b.Cmds[i];
                if (ContainsReachVariable(c))
                {
                    cs.Add(c);
                    continue;
                }
                cs.Add(new AssertCmd(c.tok, Expr.True));
            }
            for (int i = endidx + 1; i < b.Cmds.Length; i++)
            {
                cs.Add(b.Cmds[i]);
            }

            b.Cmds = cs;
            #endregion

            #region Recheck
            ProverInterface.Outcome outcome = ProverInterface.Outcome.Undetermined;
            if (!ReCheckImpl(reachvar, impl, callback, out outcome))
            {
                b.Cmds = backup;
                return(false);
            }
            #endregion

            if (outcome == ProverInterface.Outcome.Valid)
            {
                return(true);
            }
            else if (outcome == ProverInterface.Outcome.Invalid)
            {
                b.Cmds = backup;
                if (startidx >= endidx)
                {
                    if (!ContainsReachVariable(b.Cmds[endidx]))
                    {
                        //                    Console.Write("   Witness (");
                        //
                        //                    ConsoleColor col = Console.ForegroundColor;
                        //                    Console.ForegroundColor = ConsoleColor.White;
                        //                    Console.Write("{0};{1}", b.Cmds[endidx].tok.line, b.Cmds[endidx].tok.col );
                        //                    Console.ForegroundColor = col;
                        //                    Console.Write("):   ");
                        //                    Console.ForegroundColor = ConsoleColor.Yellow;
                        //                    b.Cmds[endidx].Emit(new TokenTextWriter("<console>", Console.Out, false), 0);
                        //                    Console.ForegroundColor = col;

                        m_doomedCmds.Add(b.Cmds[endidx]);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    int mid = startidx + (endidx - startidx) / 2;
                    BruteForceCmd(b, startidx, mid, reachvar, impl, callback);
                    BruteForceCmd(b, mid + 1, endidx, reachvar, impl, callback);
                    return(false); // This is pure random
                }
            }
            else
            {
                b.Cmds = backup;
                return(false);
            }
        }
Ejemplo n.º 22
0
        protected override bool UpdateAssignmentWorkList(ProverInterface.Outcome outcome,
                                                         List <Counterexample> errors)
        {
            Contract.Assume(currentHoudiniState.Implementation != null);
            bool dequeue = true;

            switch (outcome)
            {
            case ProverInterface.Outcome.Valid:
                //yeah, dequeue
                break;

            case ProverInterface.Outcome.Invalid:
                Contract.Assume(errors != null);

                foreach (Counterexample error in errors)
                {
                    RefutedAnnotation refutedAnnotation = ExtractRefutedAnnotation(error);
                    // some candidate annotation removed
                    if (refutedAnnotation != null)
                    {
                        refutedSharedAnnotations.TryAdd(refutedAnnotation.Constant.Name, refutedAnnotation);
                        AddRelatedToWorkList(refutedAnnotation);
                        UpdateAssignment(refutedAnnotation);
                        dequeue = false;

                        #region Extra debugging output
                        if (CommandLineOptions.Clo.Trace)
                        {
                            using (var cexWriter = new System.IO.StreamWriter(cexTraceFile, true)) {
                                cexWriter.WriteLine("Counter example for " + refutedAnnotation.Constant);
                                cexWriter.Write(error.ToString());
                                cexWriter.WriteLine();
                                using (var writer = new Microsoft.Boogie.TokenTextWriter(cexWriter))
                                    foreach (Microsoft.Boogie.Block blk in error.Trace)
                                    {
                                        blk.Emit(writer, 15);
                                    }
                                //cexWriter.WriteLine();
                            }
                        }
                        #endregion
                    }
                }

                if (ExchangeRefutedAnnotations())
                {
                    dequeue = false;
                }

                break;

            default:
                if (CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Timeout/Spaceout while verifying " + currentHoudiniState.Implementation.Name);
                }

                HoudiniSession houdiniSession;
                houdiniSessions.TryGetValue(currentHoudiniState.Implementation, out houdiniSession);

                foreach (Variable v in houdiniSession.houdiniAssertConstants)
                {
                    if (CommandLineOptions.Clo.Trace)
                    {
                        Console.WriteLine("Removing " + v);
                    }
                    currentHoudiniState.Assignment.Remove(v);
                    currentHoudiniState.Assignment.Add(v, false);
                    this.NotifyConstant(v.Name);
                }

                currentHoudiniState.addToBlackList(currentHoudiniState.Implementation.Name);
                break;
            }

            return(dequeue);
        }