示例#1
0
        private int GetLoopId(WhileCmd wc)
        {
            AssertCmd inv = wc.Invariants[0] as AssertCmd;

            Debug.Assert(inv.Attributes.Key.Contains("loophead_"));
            return(Convert.ToInt32(inv.Attributes.Key.Substring("loophead_".Length)));
        }
示例#2
0
        private AssumeCmd MakeThreadSpecificAssumeFromAssert(AssertCmd a, int Thread)
        {
            AssumeCmd result = new AssumeCmd(Token.NoToken, new VariableDualiser(Thread,
                                                                                 verifier.uniformityAnalyser, procName).VisitExpr(a.Expr.Clone() as Expr));

            return(result);
        }
示例#3
0
        public static void Assign_Label_To_Declaration(ref Declaration decl)
        {
            Contract.Assert(decl != null);

            var axiomDecl     = decl as Axiom;
            var procedureDecl = decl as Procedure;
            var functionDecl  = decl as Function;
            var implemDecl    = decl as Implementation;

            if (axiomDecl != null)
            {
                var expr = axiomDecl.Expr;
                Assign_Label_To_Expression(ref expr);
            }
            else if (procedureDecl != null)
            {
                var requires     = procedureDecl.Requires;
                var ensures      = procedureDecl.Ensures;
                var list_ens_req = new List <Absy>();
                list_ens_req.AddRange(requires);
                list_ens_req.AddRange(ensures);
                Get_Names_For_Procedure(list_ens_req);
            }
            else if (functionDecl != null)
            {
                var body_expressions = (functionDecl.Body);
                if (body_expressions != null)
                {
                    Assign_Label_To_Expression(ref body_expressions);
                }
            }
            else if (implemDecl != null)
            {
                for (int i = 0; i < implemDecl.Blocks.Count; i++)
                {
                    for (int j = 0; j < implemDecl.Blocks.ToList()[i].Cmds.Count; j++)
                    {
                        Cmd       c    = implemDecl.Blocks.ToList()[i].Cmds.ToList()[j];
                        AssertCmd artc = c as AssertCmd;
                        AssumeCmd amec = c as AssumeCmd;
                        AssignCmd assc = c as AssignCmd;
                        Expr      tmp  = null;
                        if (artc != null)
                        {
                            tmp = artc.Expr;
                        }
                        else if (amec != null)
                        {
                            tmp = amec.Expr;
                        }
                        else if (assc != null)
                        {
                            var list_temp = assc.Rhss.ToList();
                            Assign_Label_To_Set_Of_Expressions(ref list_temp);
                        }
                        Assign_Label_To_Expression(ref tmp);
                    }
                }
            }
        }
示例#4
0
        private Program ApplyInvariants(Houdini.HoudiniOutcome outcome)
        {
            Program program = getFreshProgram(false, false);

            CommandLineOptions.Clo.PrintUnstructured = 2;
            Houdini.Houdini.ApplyAssignment(program, outcome);
            if (((GPUVerifyCruncherCommandLineOptions)CommandLineOptions.Clo).ReplaceLoopInvariantAssertions)
            {
                foreach (Block block in program.Blocks())
                {
                    List <Cmd> newCmds = new List <Cmd>();
                    foreach (Cmd cmd in block.Cmds)
                    {
                        AssertCmd assertion = cmd as AssertCmd;
                        if (assertion != null &&
                            QKeyValue.FindBoolAttribute(assertion.Attributes, "originated_from_invariant"))
                        {
                            AssumeCmd assumption = new AssumeCmd(assertion.tok, assertion.Expr, assertion.Attributes);
                            newCmds.Add(assumption);
                        }
                        else
                        {
                            newCmds.Add(cmd);
                        }
                    }
                    block.Cmds = newCmds;
                }
            }
            return(program);
        }
示例#5
0
 public virtual Cmd VisitAssertCmd(AssertCmd node)
 {
     Contract.Requires(node != null);
     Contract.Ensures(Contract.Result <Cmd>() != null);
     node.Expr = this.VisitExpr(node.Expr);
     return(node);
 }
 //precondition: each block contains at most one assert with SlashVerifyCommandType attribute,
 //              which is true since we use a block for each instruction
 private bool EquivalentCmd(Cmd c1, Cmd c2)
 {
     //Note: The assumption here is that we only instrument assignments and attributed-asserts in the original sourcefile
     if (c1.GetType() != c2.GetType())
     {
         return(false);
     }
     if (c1 is AssignCmd && c2 is AssignCmd)
     {
         AssignCmd c1_assignment = c1 as AssignCmd;
         AssignCmd c2_assignment = c2 as AssignCmd;
         //ASSUME: only 1 assignment to a variable in a block
         return((c1_assignment.Lhss[0].DeepAssignedVariable == c2_assignment.Lhss[0].DeepAssignedVariable) &&
                (c1_assignment.Rhss[0].ToString() == c2_assignment.Rhss[0].ToString())); //TODO: need better equality here
     }
     else if (c1 is AssertCmd && c2 is AssertCmd)
     {
         AssertCmd c1_assertion = c1 as AssertCmd;
         AssertCmd c2_assertion = c2 as AssertCmd;
         string    c1_attribute = QKeyValue.FindStringAttribute(c1_assertion.Attributes, "SlashVerifyCommandType");
         string    c2_attribute = QKeyValue.FindStringAttribute(c2_assertion.Attributes, "SlashVerifyCommandType");
         return(c1_attribute != null && c2_attribute != null && c1_attribute.Equals(c2_attribute));
     }
     return(false);
 }
示例#7
0
        bool ContainsReachVariable(Cmd c)
        {
            Contract.Requires(c != null);
            AssertCmd artc = c as AssertCmd;
            AssumeCmd amec = c as AssumeCmd;
            Expr      e;

            if (artc != null)
            {
                e = artc.Expr;
            }
            else if (amec != null)
            {
                e = amec.Expr;
            }
            else
            {
                return(false);
            }
            Set freevars = new Set();

            e.ComputeFreeVariables(freevars);
            foreach (Variable v in freevars)
            {
                Contract.Assert(v != null);
                if (v.Name.Contains(reachvarsuffix))
                {
                    return(true);
                }
            }
            return(false);
        }
示例#8
0
        public override AssertCmd GetAssertCmd()
        {
            AssertCmd result = base.GetAssertCmd();

            result.Expr = Expr.Imp(Verifier.ThreadsInSameGroup(), result.Expr);
            return(result);
        }
示例#9
0
        private AssertCmd makeHavocStyleSourceInfo(IList <object> list)
        {
            var fn    = new List <object>();
            var newFn = this.relativeDir + unifyPrefix((string)list[0]);

            if (File.Exists(newFn))
            {
                fn.Add(newFn);
            }
            else
            {
                newFn = this.relativeDir + trimDirectoryPrefix((string)list[0]);
                if (File.Exists(newFn))
                {
                    fn.Add(newFn);
                }
                else
                {
                    Console.WriteLine("[ERROR] Preprocessing. Cannot Map File to name using curent heuristics.");
                }
            }
            var lineno = new List <object>();

            lineno.Add(list[1]);
            var assert = new AssertCmd(Token.NoToken, Expr.True,
                                       new QKeyValue(Token.NoToken, "sourcefile", fn,
                                                     new QKeyValue(Token.NoToken, "sourceline", lineno, null)));

            return(assert);
        }
示例#10
0
 public Assert(AssertCmd boogieStatement, Expression expression, string message)
     : base(expression, message)
 {
     Debug.Assert(boogieStatement != null);
     Debug.Assert(message != null);
     this.boogieStatement = boogieStatement;
 }
 public void RecordAssertion(string label, Cmd typedCmd, AssertCmd assertion, SlashVerifyCmdType cmdType)
 {
     if (!Options.splitFiles)
     {
         return;
     }
     assertions.Add(new Tuple <string, Cmd, AssertCmd, SlashVerifyCmdType>(label, typedCmd, assertion, cmdType));
 }
示例#12
0
        public override Cmd VisitAssertCmd(AssertCmd node)
        {
            var result = Translate(node.Expr);

            ReturnResult(IsaBoogieTerm.Assert(result));

            return(node);
        }
示例#13
0
 public override Cmd VisitAssertCmd(AssertCmd node)
 {
     if (Util.IsSourceInfoAssertCmd(node))
     {
         node.Attributes = null;
     }
     return(base.VisitAssertCmd(node));
 }
示例#14
0
        //private readonly Dictionary<IToken, List<ErrorCode>> reportedVerificationErrors = new Dictionary<IToken, List<ErrorCode>>();
        //private readonly List<string> errors = new List<string>();

        public void ReportCounterexample(Counterexample ce, string message)
        {
            if (message != null)
            {
                message = " (" + message + ")";
            }
            else
            {
                message = "";
            }

            try {
                ReturnCounterexample /*?*/ rce = ce as ReturnCounterexample;
                if (rce != null)
                {
                    IToken tok = rce.FailingReturn.tok;
                    for (int i = rce.Trace.Length - 1; i >= 0; i--)
                    {
                        foreach (Cmd c in rce.Trace[i].Cmds)
                        {
                            AssertCmd assrt = c as AssertCmd;
                            if (assrt != null)
                            {
                                NAryExpr nary = assrt.Expr as NAryExpr;
                                if (nary != null)
                                {
                                    FunctionCall fcall = nary.Fun as FunctionCall;
                                    if (fcall != null && fcall.FunctionName == "$position_marker")
                                    {
                                        tok = assrt.tok;
                                    }
                                }
                            }
                        }
                    }
                    ReportOutcomePostconditionFailed(rce.FailingEnsures.tok, tok, message);
                }
                AssertCounterexample /*?*/ ace = ce as AssertCounterexample;
                if (ace != null)
                {
                    ReportOutcomeAssertFailed(ace.FailingAssert.tok,
                                              (ace.FailingAssert is LoopInvMaintainedAssertCmd ? "Loop body invariant" :
                                               ace.FailingAssert is LoopInitAssertCmd ? "Loop entry invariant" : "Assertion"),
                                              message
                                              );
                }
                CallCounterexample /*?*/ cce = ce as CallCounterexample;
                if (cce != null)
                {
                    ReportOutcomePreconditionFailed(cce.FailingCall.tok, cce.FailingRequires, message);
                }
            } finally {
                if (commandLineOptions != null && commandLineOptions.PrintCEVModel)
                {
                    ce.PrintModel();
                }
            }
        }
        public List <Cmd> CreateFinalAssertCmds()
        {
            var       cmds      = CreateAssertCmds();
            AssertCmd assertCmd = new AssertCmd(Token.NoToken, Expr.Ident(ok));

            assertCmd.ErrorData = "Failed to execute atomic action before procedure return";
            cmds.Add(assertCmd);
            return(cmds);
        }
示例#16
0
        public override List <Cmd> CreateReturnAssertCmds()
        {
            AssertCmd assertCmd = new AssertCmd(Token.NoToken, Expr.Ident(ok));

            assertCmd.ErrorData = "Failed to execute atomic action before procedure return";
            return(new List <Cmd> {
                assertCmd
            });
        }
示例#17
0
        private List <Cmd> CollectCausalStatements(Block b)
        {
            Contract.Requires(b != null);
            Contract.Ensures(cce.NonNullElements(Contract.Result <List <Cmd> >()));

            Cmd lastCausal = null;

            foreach (Cmd c in b.Cmds)
            {
                Contract.Assert(c != null);
                AssertCmd ac = c as AssertCmd;
                AssumeCmd uc = c as AssumeCmd;
                if (ac != null && !ContainsReachVariable(ac))
                {
                    if (ac.Expr != Expr.True)
                    {
                        lastCausal = c;
                    }
                }
                else if (uc != null && !ContainsReachVariable(uc))
                {
                    lastCausal = c;
                }
            }

            List <Cmd> causals = new List <Cmd>();
            GotoCmd    gc      = b.TransferCmd as GotoCmd;

            if (gc != null && gc.labelTargets != null)
            {
                List <Cmd> tmp;
                //bool allcausal = true;
                foreach (Block b_ in gc.labelTargets)
                {
                    Contract.Assert(b_ != null);
                    tmp = CollectCausalStatements(b_);

                    foreach (Cmd cau in tmp)
                    {
                        if (!causals.Contains(cau))
                        {
                            causals.Add(cau);
                        }
                    }
                }
                //if (allcausal)
                if (causals.Count > 0)
                {
                    return(causals);
                }
            }
            if (lastCausal != null)
            {
                causals.Add(lastCausal);
            }
            return(causals);
        }
示例#18
0
        /// <summary>
        /// Adds the required barriers.
        /// </summary>
        /// <param name="implementation">The procedure where the blocks are being added.</param>
        /// <param name="block">The block containing the shared read/write command.</param>
        /// <param name="index">The index of the assign command.</param>
        private bool AddBarrier(Implementation implementation, Block block, int index)
        {
            // an assert statement is needed to obtain the source location
            // skipping instrumentation if it doesn't exist
            if (index - 1 < 0)
            {
                return(false);
            }

            AssertCmd assert = block.Cmds[index - 1] as AssertCmd;

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

            // add the instrumentation key to the assert command
            QKeyValue assertAttribute = new QKeyValue(Token.NoToken, InstrumentationKey, new List <object>(), null);

            if (assert.Attributes != null)
            {
                assert.Attributes.AddLast(assertAttribute);
            }
            else
            {
                assert.Attributes = assertAttribute;
            }

            // get source location infromation
            int       location          = QKeyValue.FindIntAttribute(assert.Attributes, SourceLocationKey, -1);
            QKeyValue locationAttribute = null;

            if (location != -1)
            {
                LiteralExpr locationValue = new LiteralExpr(Token.NoToken, BigNum.FromInt(location));
                locationAttribute = new QKeyValue(Token.NoToken, SourceLocationKey, new List <object> {
                    locationValue
                }, null);
            }

            // create a conditional barrier
            if (sourceLanguage == SourceLanguage.CUDA && !disableGridBarriers)
            {
                Barrier barrier      = CreateCallCommand(block, locationAttribute, index, "$bugle_barrier");
                Barrier grid_barrier = CreateCallCommand(block, locationAttribute, index, "$bugle_grid_barrier");

                InsertBarriers(implementation, block, index, barrier, grid_barrier);
            }
            else
            {
                Barrier barrier = CreateCallCommand(block, locationAttribute, index, "$bugle_barrier");
                InsertBarrier(implementation, block, index, barrier);
            }

            analyzer.LinkBarrier(implementation, block);
            return(true);
        }
示例#19
0
        private AssertCmd MakeThreadSpecificAssert(AssertCmd a, int thread)
        {
            AssertCmd result = new AssertCmd(
                Token.NoToken,
                new VariableDualiser(thread, Verifier, procName).VisitExpr(a.Expr.Clone() as Expr),
                MakeThreadSpecificAttributes(a.Attributes, thread));

            return(result);
        }
示例#20
0
 public AssertCounterexample(List <Block> trace, List <object> augmentedTrace, AssertCmd failingAssert, Model model, VC.ModelViewInfo mvInfo,
                             ProverContext context)
     : base(trace, augmentedTrace, model, mvInfo, context)
 {
     Contract.Requires(trace != null);
     Contract.Requires(failingAssert != null);
     Contract.Requires(context != null);
     this.FailingAssert = failingAssert;
 }
        private void InstrumentAssertCandidate(Thread thread, Block block, Variable variable, bool value)
        {
            var  cons   = this.CreateConstant(thread);
            Expr expr   = this.CreateImplExpr(cons, variable, value);
            var  assert = new AssertCmd(Token.NoToken, expr);

            assert.Attributes = new QKeyValue(Token.NoToken, "candidate",
                                              new List <object>(), assert.Attributes);
            block.Cmds.Insert(0, assert);
        }
示例#22
0
        public override List <Cmd> CreateReturnAssertCmds()
        {
            AssertCmd assertCmd = CmdHelper.AssertCmd(
                tok,
                Expr.Ident(ok),
                "On some path no yield-to-yield fragment matched the refined atomic action");

            return(new List <Cmd> {
                assertCmd
            });
        }
示例#23
0
        public override Cmd VisitAssertCmd(AssertCmd node)
        {
            int phaseNum = QKeyValue.FindIntAttribute(node.Attributes, "phase", int.MaxValue);

            assertionPhaseNums.Add(phaseNum);
            if (phaseNum > enclosingProcPhaseNum)
            {
                Error(node, "The phase of assert cannot be greater than the phase of enclosing procedure");
            }
            return(node);
        }
示例#24
0
 public override Cmd VisitAssertCmd(AssertCmd node)
 {
     if (node.Attributes == null)
     {
         return(new AssertCmd(node.tok, VisitExpr(node.Expr)));
     }
     else
     {
         return(new AssertCmd(node.tok, VisitExpr(node.Expr), (QKeyValue)node.Attributes.Clone()));
     }
 }
示例#25
0
        public virtual AssertCmd GetAssertCmd()
        {
            AssertCmd result = new AssertCmd(
                Token.NoToken,
                new VariableDualiser(1, Dualiser.Verifier, ProcName).VisitExpr(Expr.Imp(Predicate, BarrierInvariant)),
                Dualiser.MakeThreadSpecificAttributes(sourceLocationInfo, 1));

            result.Attributes = new QKeyValue(Token.NoToken, "barrier_invariant", new List <object> {
                Expr.True
            }, result.Attributes);
            return(result);
        }
示例#26
0
 public static IEnumerable <AssertCmd> GetGateAsserts(AtomicAction action, Substitution subst, string msg)
 {
     foreach (var gate in action.gate)
     {
         AssertCmd cmd =
             subst != null
   ? (AssertCmd)Substituter.Apply(subst, gate)
   : new AssertCmd(gate.tok, gate.Expr);
         cmd.ErrorData = msg;
         yield return(cmd);
     }
 }
示例#27
0
 private bool IsTerminatingLoopHeader(Block block)
 {
     foreach (Cmd cmd in block.Cmds)
     {
         AssertCmd assertCmd = cmd as AssertCmd;
         if (assertCmd != null && QKeyValue.FindBoolAttribute(assertCmd.Attributes, "terminates") && moverTypeChecker.absyToLayerNums[assertCmd].Contains(currLayerNum))
         {
             return(true);
         }
     }
     return(false);
 }
        private AssertCmd CreateSkipOrBetaAssertCmd()
        {
            // assert pc || g_old == g || beta(i, g_old, o, g);
            var aa         = OldEqualityExprForGlobals();
            var assertExpr = Expr.Or(Expr.Ident(pc), Expr.Or(aa, beta));

            assertExpr.Typecheck(new TypecheckingContext(null));
            var skipOrBetaAssertCmd = new AssertCmd(Token.NoToken, assertExpr);

            skipOrBetaAssertCmd.ErrorData = "Transition invariant violated in initial state";
            return(skipOrBetaAssertCmd);
        }
        private AssertCmd CreateSkipAssertCmd()
        {
            // assert pc ==> o_old == o && g_old == g;
            Expr bb         = OldEqualityExpr();
            var  assertExpr = Expr.Imp(Expr.Ident(pc), bb);

            assertExpr.Typecheck(new TypecheckingContext(null));
            AssertCmd skipAssertCmd = new AssertCmd(Token.NoToken, assertExpr);

            skipAssertCmd.ErrorData = "Transition invariant violated in final state";
            return(skipAssertCmd);
        }
示例#30
0
        private void CreateFailurePreservationChecker(AtomicAction first, AtomicAction second)
        {
            if (!first.gateUsedGlobalVars.Intersect(second.modifiedGlobalVars).Any())
            {
                return;
            }
            if (!failurePreservationCheckerCache.Add(Tuple.Create(first, second)))
            {
                return;
            }

            HashSet <Variable> frame = new HashSet <Variable>();

            frame.UnionWith(first.gateUsedGlobalVars);
            frame.UnionWith(second.gateUsedGlobalVars);
            frame.UnionWith(second.actionUsedGlobalVars);

            var             linearTypeChecker = civlTypeChecker.linearTypeChecker;
            List <Requires> requires          = new List <Requires>
            {
                DisjointnessRequires(
                    first.firstImpl.InParams.Union(second.secondImpl.InParams)
                    .Where(v => linearTypeChecker.FindLinearKind(v) != LinearKind.LINEAR_OUT), frame)
            };
            Expr firstNegatedGate = Expr.Not(Expr.And(first.firstGate.Select(a => a.Expr)));

            firstNegatedGate.Type = Type.Bool; // necessary?
            requires.Add(new Requires(false, firstNegatedGate));
            foreach (AssertCmd assertCmd in second.secondGate)
            {
                requires.Add(new Requires(false, assertCmd.Expr));
            }

            IEnumerable <Expr> linearityAssumes =
                linearTypeChecker.DisjointnessExprForEachDomain(first.firstImpl.InParams.Union(second.secondImpl.OutParams)
                                                                .Union(frame));
            AssertCmd gateFailureCheck = CmdHelper.AssertCmd(
                first.proc.tok,
                Expr.Imp(Expr.And(linearityAssumes), firstNegatedGate),
                $"Gate failure of {first.proc.Name} not preserved by {second.proc.Name}");

            string checkerName = $"FailurePreservationChecker_{first.proc.Name}_{second.proc.Name}";

            List <Variable> inputs  = Enumerable.Union(first.firstImpl.InParams, second.secondImpl.InParams).ToList();
            List <Variable> outputs = Enumerable.Union(first.firstImpl.OutParams, second.secondImpl.OutParams).ToList();
            var             cmds    = new List <Cmd>
            {
                ActionCallCmd(second, second.secondImpl),
                gateFailureCheck
            };

            AddChecker(checkerName, inputs, outputs, new List <Variable>(), requires, cmds);
        }