Example #1
0
        public void AddLoopInvariantDisabledTag()
        {
            AssumeCmd assume = new AssumeCmd(Token.NoToken, Expr.True, null);

            assume.Attributes = new QKeyValue(Token.NoToken, "invGenSkippedLoop", new List <object>(), assume.Attributes);
            header.Cmds.Insert(0, assume);
        }
Example #2
0
 private void AddHoudiniConstant(AssumeCmd assumeCmd)
 {
     if (houdini.MatchCandidate(assumeCmd.Expr, out Variable houdiniConstant))
     {
         houdiniAssumeConstants.Add(houdiniConstant);
     }
 }
Example #3
0
        private static void ProcessCounterexampleForDiffInliningWOSymbolicOut(List <Variable> eqLocVars, Implementation vtLeftProcImpl, Implementation vtRightProcImpl, string v1Name, string v2Name, List <Block> listBlocksV1, List <Block> listBlocksV2, GotoCmd labelEntry)
        {
            if (vtLeftProcImpl != null && vtRightProcImpl != null) //only when diff inlining is on
            {
                var blocksLeftProcImpl      = vtLeftProcImpl.Blocks.ToArray();
                var blocksRightProcImpl     = vtRightProcImpl.Blocks.ToArray();
                var firstCmdThirdBlockLeft  = new AssumeCmd(Token.NoToken, Expr.Not(Expr.True));
                var firstCmdThirdBlockRight = new AssumeCmd(Token.NoToken, Expr.Not(Expr.True));

                var leftThirdBlockCmdElems  = blocksLeftProcImpl[2].Cmds;
                var rightThirdBlockCmdElems = blocksRightProcImpl[2].Cmds;

                leftThirdBlockCmdElems[0]  = firstCmdThirdBlockLeft;
                rightThirdBlockCmdElems[0] = firstCmdThirdBlockRight;

                blocksLeftProcImpl[2].Cmds  = leftThirdBlockCmdElems;
                blocksRightProcImpl[2].Cmds = rightThirdBlockCmdElems;

                // re-building the first block (only the goto cmds)
                blocksLeftProcImpl[0].TransferCmd  = labelEntry;
                blocksRightProcImpl[0].TransferCmd = labelEntry;

                // removing the second block
                vtLeftProcImpl.Blocks.RemoveAt(1);
                vtRightProcImpl.Blocks.RemoveAt(1);

                foreach (Block currentBlockV1 in listBlocksV1)
                {
                    vtLeftProcImpl.Blocks.Add(currentBlockV1);
                }

                foreach (Block currentBlockV2 in listBlocksV2)
                {
                    vtRightProcImpl.Blocks.Add(currentBlockV2);
                }

                //vtLeftProcImpl.Blocks.Add(blockV1);
                //vtRightProcImpl.Blocks.Add(blockV2);

                //hemr - handling local variable declarations
                List <Variable> locVarsV1_diff_inline = new List <Variable>();
                List <Variable> locVarsV2_diff_inline = new List <Variable>();

                foreach (Variable currentVariable in eqLocVars)
                {
                    if (currentVariable.ToString().Contains("inline$" + v1Name))
                    {
                        locVarsV1_diff_inline.Add(currentVariable);
                    }

                    else if (currentVariable.ToString().Contains("inline$" + v2Name))
                    {
                        locVarsV2_diff_inline.Add(currentVariable);
                    }
                }

                vtLeftProcImpl.LocVars  = locVarsV1_diff_inline;
                vtRightProcImpl.LocVars = locVarsV2_diff_inline;
            }
        }
Example #4
0
        //additional stuff needed to do for diff inlining is on
        private static void ProcessCounterexampleForDiffInline(SDiffCounterexamples errors, Implementation vtLeftProcImpl, Implementation vtRightProcImpl, Expr disjunctionDiffCond)
        {
            if (vtLeftProcImpl != null && vtRightProcImpl != null)
            {
                var blocksLeftProcImpl       = vtLeftProcImpl.Blocks.ToArray();
                var blocksRightProcImpl      = vtRightProcImpl.Blocks.ToArray();
                var firstCmdSecondBlockLeft  = new AssumeCmd(Token.NoToken, disjunctionDiffCond);
                var firstCmdSecondBlockRight = new AssumeCmd(Token.NoToken, disjunctionDiffCond);
                var firstCmdThirdBlockLeft   = new AssumeCmd(Token.NoToken, Expr.Not(disjunctionDiffCond));
                var firstCmdThirdBlockRight  = new AssumeCmd(Token.NoToken, Expr.Not(disjunctionDiffCond));

                if (Options.PropagateSingleDifference && errors.Count > 1)
                {
                    firstCmdThirdBlockLeft  = new AssumeCmd(Token.NoToken, Expr.False);
                    firstCmdThirdBlockRight = new AssumeCmd(Token.NoToken, Expr.False);
                }

                var leftSecondBlockCmdElems  = blocksLeftProcImpl[1].Cmds;
                var leftThirdBlockCmdElems   = blocksLeftProcImpl[2].Cmds;
                var rightSecondBlockCmdElems = blocksRightProcImpl[1].Cmds;
                var rightThirdBlockCmdElems  = blocksRightProcImpl[2].Cmds;

                leftSecondBlockCmdElems[0]  = firstCmdSecondBlockLeft;
                leftThirdBlockCmdElems[0]   = firstCmdThirdBlockLeft;
                rightSecondBlockCmdElems[0] = firstCmdSecondBlockRight;
                rightThirdBlockCmdElems[0]  = firstCmdThirdBlockRight;

                blocksLeftProcImpl[1].Cmds  = leftSecondBlockCmdElems;
                blocksLeftProcImpl[2].Cmds  = leftThirdBlockCmdElems;
                blocksRightProcImpl[1].Cmds = rightSecondBlockCmdElems;
                blocksRightProcImpl[2].Cmds = rightThirdBlockCmdElems;
            }
        }
Example #5
0
        private bool AnalyseConflict(string state1, string state2, AssumeCmd assume1, AssumeCmd assume2)
        {
            string t1 = this.GetThreadName(assume1.Attributes);
            string t2 = this.GetThreadName(assume2.Attributes);

//      if (!this.Pair.EntryPoint1.Name.Equals(ep1))
//        return false;
//      if (!this.Pair.EntryPoint2.Name.Equals(ep2))
//        return false;

            string access1 = this.GetAccessType(assume1.Attributes);
            string access2 = this.GetAccessType(assume2.Attributes);

            if (access1.Equals("read") && access2.Equals("read"))
            {
                return(false);
            }

//      var sourceInfoForAccess1 = new SourceLocationInfo(assume1.Attributes);
//      var sourceInfoForAccess2 = new SourceLocationInfo(assume2.Attributes);

//      ErrorReporter.ErrorWriteLine("\n" + sourceInfoForAccess1.GetFile() + ":",
//        "potential " + access1 + "-" + access2 + " race:\n", ErrorMsgType.Error);

//      Console.Error.Write(access1 + " by thread " + t1 + ", ");
//      Console.Error.WriteLine(sourceInfoForAccess1.ToString());
//      sourceInfoForAccess1.PrintStackTrace();

//      Console.Error.WriteLine(access2 + " by entry point " + ep2 + ", " + sourceInfoForAccess2.ToString());
//      sourceInfoForAccess2.PrintStackTrace();

            return(true);
        }
        // goto label1, label2;
        //
        // label1:
        //   assume {:avn tok} !assertsPassed;
        //   return;
        //
        // label2:
        //   assume assertsPassed;
        //   goto lab;
        //
        // lab:
        //
        // Inputs: the list of blocks being constructed; the current block being constructed.
        // End current block and adds two new blocks.
        // Returns "lab".

        private string addInstr(List <Block> instrumented, List <Cmd> curr, string curr_label, int token)
        {
            string lbl1 = getNewLabel();
            string lbl2 = getNewLabel();

            List <String> ssp = new List <String> {
                lbl1, lbl2
            };

            instrumented.Add(new Block(Token.NoToken, curr_label, curr, new GotoCmd(Token.NoToken, ssp)));

            string common_label = getNewLabel();
            // assume (!assertsPassed)
            AssumeCmd cmd1 = new AssumeCmd(Token.NoToken, Expr.Not(Expr.Ident(assertsPassed)));

            if (token >= 0)
            {
                cmd1.Attributes = new QKeyValue(Token.NoToken, "avn", new List <object> {
                    Expr.Literal(token)
                }, cmd1.Attributes);
            }

            // assume (assertsPassed)
            AssumeCmd cmd2 = new AssumeCmd(Token.NoToken, Expr.Ident(assertsPassed));

            curr = new List <Cmd>();
            curr.Add(cmd1);
            instrumented.Add(new Block(Token.NoToken, lbl1, curr, new ReturnCmd(Token.NoToken)));

            curr = new List <Cmd>();
            curr.Add(cmd2);
            instrumented.Add(new Block(Token.NoToken, lbl2, curr, BoogieAstFactory.MkGotoCmd(common_label)));

            return(common_label);
        }
Example #7
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);
        }
Example #8
0
    public Dictionary<Block, List<CallSite>> CollectCallSites(Implementation implementation)
    {
      var callSites = new Dictionary<Block, List<CallSite>>();
      foreach (Block block in implementation.Blocks)
      {
        for (int i = 0; i < block.Cmds.Count; i++)
        {
          Cmd cmd = block.Cmds[i];
          AssumeCmd assumeCmd = cmd as AssumeCmd;
          if (assumeCmd == null) continue;
          NAryExpr naryExpr = assumeCmd.Expr as NAryExpr;
          if (naryExpr == null) continue;
          if (!implName2StratifiedInliningInfo.ContainsKey(naryExpr.Fun.FunctionName)) continue;
          List<VCExpr> interfaceExprs = new List<VCExpr>();
          foreach (Expr e in naryExpr.Args)
          {
            interfaceExprs.Add(prover.Context.BoogieExprTranslator.Translate(e));
          }

          int instr = i;
          i++;
          AssumeCmd callSiteAssumeCmd = (AssumeCmd) block.Cmds[i];
          IdentifierExpr iexpr = (IdentifierExpr) callSiteAssumeCmd.Expr;
          CallSite cs = new CallSite(naryExpr.Fun.FunctionName, interfaceExprs,
            prover.Context.BoogieExprTranslator.LookupVariable(iexpr.Decl), block, instr, assumeCmd.Attributes);
          if (!callSites.ContainsKey(block))
            callSites[block] = new List<CallSite>();
          callSites[block].Add(cs);
        }
      }

      return callSites;
    }
Example #9
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);
        }
        private void AddPath()
        {
            Dictionary <Variable, Expr> varToExpr =
                frame
                .Concat(first != null ? first.thatOutParams : Enumerable.Empty <Variable>())
                .Concat(second.thisOutParams)
                .ToDictionary(v => v, v => Expr.Ident(v) as Expr);

            List <Expr> pathExprs = new List <Expr>();

            foreach (Cmd cmd in cmdStack)
            {
                if (cmd is AssumeCmd)
                {
                    AssumeCmd assumeCmd = cmd as AssumeCmd;
                    FlattenAnd(assumeCmd.Expr, pathExprs);
                }
                else if (cmd is AssignCmd)
                {
                    AssignCmd assignCmd             = (cmd as AssignCmd).AsSimpleAssignCmd;
                    Dictionary <Variable, Expr> map = new Dictionary <Variable, Expr>();
                    for (int k = 0; k < assignCmd.Lhss.Count; k++)
                    {
                        map[assignCmd.Lhss[k].DeepAssignedVariable] = assignCmd.Rhss[k];
                    }
                    Substitute(map, ref pathExprs, ref varToExpr);
                }
                else
                {
                    Debug.Assert(false);
                }
            }
            paths.Add(new PathInfo(varToExpr, pathExprs));
        }
Example #11
0
    public Dictionary<Block, List<CallSite>> CollectRecordProcedureCallSites(Implementation implementation)
    {
      var callSites = new Dictionary<Block, List<CallSite>>();
      foreach (Block block in implementation.Blocks)
      {
        for (int i = 0; i < block.Cmds.Count; i++)
        {
          AssumeCmd assumeCmd = block.Cmds[i] as AssumeCmd;
          if (assumeCmd == null) continue;
          NAryExpr naryExpr = assumeCmd.Expr as NAryExpr;
          if (naryExpr == null) continue;
          if (!naryExpr.Fun.FunctionName.StartsWith(recordProcName)) continue;
          List<VCExpr> interfaceExprs = new List<VCExpr>();
          foreach (Expr e in naryExpr.Args)
          {
            interfaceExprs.Add(prover.Context.BoogieExprTranslator.Translate(e));
          }

          CallSite cs = new CallSite(naryExpr.Fun.FunctionName, interfaceExprs, null, block, i, assumeCmd.Attributes);
          if (!callSites.ContainsKey(block))
            callSites[block] = new List<CallSite>();
          callSites[block].Add(cs);
        }
      }

      return callSites;
    }
Example #12
0
        public override List <AssumeCmd> GetInstantiationCmds()
        {
            var result = new List <AssumeCmd>();

            foreach (var instantiation in instantiationExprs)
            {
                foreach (var thread in Enumerable.Range(1, 2))
                {
                    var vd = new VariableDualiser(thread, Dualiser.Verifier, ProcName);
                    var ti = new ThreadInstantiator(instantiation, thread, Dualiser.Verifier, ProcName);

                    var assume = new AssumeCmd(
                        Token.NoToken,
                        Expr.Imp(
                            vd.VisitExpr(Predicate),
                            Expr.Imp(
                                Expr.And(
                                    NonNegative(instantiation),
                                    NotTooLarge(instantiation)),
                                ti.VisitExpr(BarrierInvariant))));
                    result.Add(vd.VisitAssumeCmd(assume) as AssumeCmd);
                }
            }

            return(result);
        }
        private HashSet <VariableDescriptor> GetControlDependencyVariables(string proc, Block b)
        {
            // This method works under the assumption that assume statements
            // relevant to control flow between basic blocks have the "partition" attribute

            HashSet <VariableDescriptor> result = new HashSet <VariableDescriptor>();
            var gotoCmd = b.TransferCmd as GotoCmd;

            if (gotoCmd != null && gotoCmd.labelTargets.Count >= 2)
            {
                foreach (Block succ in gotoCmd.labelTargets)
                {
                    foreach (Cmd c in succ.Cmds)
                    {
                        AssumeCmd a = c as AssumeCmd;
                        if (a != null && QKeyValue.FindBoolAttribute(a.Attributes, "partition"))
                        {
                            var VarCollector = new VariableCollector();
                            VarCollector.VisitExpr(a.Expr);
                            result.UnionWith(VarCollector.usedVars.Where(Item => VariableRelevantToAnalysis(Item, proc)).
                                             Select(Item => MakeDescriptor(proc, Item)));
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            return(result);
        }
Example #14
0
 public virtual Cmd VisitAssumeCmd(AssumeCmd node)
 {
     Contract.Requires(node != null);
     Contract.Ensures(Contract.Result <Cmd>() != null);
     node.Expr = this.VisitExpr(node.Expr);
     return(node);
 }
Example #15
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);
        }
Example #16
0
        public override List <AssumeCmd> GetInstantiationCmds()
        {
            var result = new List <AssumeCmd>();

            foreach (var instantiation in instantiationExprPairs)
            {
                foreach (var thread in new int[] { 1, 2 })
                {
                    var vd = new VariableDualiser(thread, Dualiser.Verifier, ProcName);
                    var ti = new ThreadPairInstantiator(Dualiser.Verifier, instantiation.Item1, instantiation.Item2, thread);

                    var assume = new AssumeCmd(
                        Token.NoToken,
                        Expr.Imp(
                            vd.VisitExpr(Predicate),
                            Expr.Imp(
                                Expr.And(
                                    Expr.And(
                                        Expr.And(
                                            NonNegative(instantiation.Item1),
                                            NotTooLarge(instantiation.Item1)),
                                        Expr.And(
                                            NonNegative(instantiation.Item2),
                                            NotTooLarge(instantiation.Item2))),
                                    Expr.Neq(instantiation.Item1, instantiation.Item2)),
                                ti.VisitExpr(BarrierInvariant))));
                    result.Add(vd.VisitAssumeCmd(assume) as AssumeCmd);
                }
            }

            return(result);
        }
Example #17
0
    public void InstrumentCallSites(Implementation implementation)
    {
      var callSiteId = 0;
      foreach (Block block in implementation.Blocks)
      {
        List<Cmd> newCmds = new List<Cmd>();
        for (int i = 0; i < block.Cmds.Count; i++)
        {
          Cmd cmd = block.Cmds[i];
          newCmds.Add(cmd);
          AssumeCmd assumeCmd = cmd as AssumeCmd;
          if (assumeCmd == null) continue;
          NAryExpr naryExpr = assumeCmd.Expr as NAryExpr;
          if (naryExpr == null) continue;
          if (!implName2StratifiedInliningInfo.ContainsKey(naryExpr.Fun.FunctionName)) continue;
          Variable callSiteVar = new LocalVariable(Token.NoToken,
            new TypedIdent(Token.NoToken, "SICS" + callSiteId, Microsoft.Boogie.Type.Bool));
          implementation.LocVars.Add(callSiteVar);
          var toInsert = new AssumeCmd(Token.NoToken, new IdentifierExpr(Token.NoToken, callSiteVar),
            new QKeyValue(Token.NoToken, callSiteVarAttr, new List<object>(), null));
          newCmds.Add(toInsert);
          callSiteId++;
        }

        block.Cmds = newCmds;
      }
    }
Example #18
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);
                    }
                }
            }
        }
Example #19
0
            private void AddPath()
            {
                HashSet <Variable>          existsVars = new HashSet <Variable>();
                Dictionary <Variable, Expr> varToExpr  = new Dictionary <Variable, Expr>();

                foreach (Variable v in frame)
                {
                    varToExpr[v] = Expr.Ident(v);
                }
                if (first != null)
                {
                    foreach (Variable v in first.thatOutParams)
                    {
                        varToExpr[v] = Expr.Ident(v);
                    }
                }
                foreach (Variable v in second.thisOutParams)
                {
                    varToExpr[v] = Expr.Ident(v);
                }
                List <Expr> pathExprs          = new List <Expr>();
                int         boundVariableCount = 0;

                foreach (Cmd cmd in cmdStack)
                {
                    if (cmd is AssumeCmd)
                    {
                        AssumeCmd assumeCmd = cmd as AssumeCmd;
                        FlattenAnd(assumeCmd.Expr, pathExprs);
                    }
                    else if (cmd is AssignCmd)
                    {
                        AssignCmd assignCmd             = (cmd as AssignCmd).AsSimpleAssignCmd;
                        Dictionary <Variable, Expr> map = new Dictionary <Variable, Expr>();
                        for (int k = 0; k < assignCmd.Lhss.Count; k++)
                        {
                            map[assignCmd.Lhss[k].DeepAssignedVariable] = assignCmd.Rhss[k];
                        }
                        Substitute(map, ref pathExprs, ref varToExpr);
                    }
                    else if (cmd is HavocCmd)
                    {
                        HavocCmd havocCmd = cmd as HavocCmd;
                        Dictionary <Variable, Expr> map = new Dictionary <Variable, Expr>();
                        foreach (IdentifierExpr ie in havocCmd.Vars)
                        {
                            BoundVariable bv = new BoundVariable(Token.NoToken, new TypedIdent(Token.NoToken, "#tmp_" + boundVariableCount++, ie.Decl.TypedIdent.Type));
                            map[ie.Decl] = Expr.Ident(bv);
                            existsVars.Add(bv);
                        }
                        Substitute(map, ref pathExprs, ref varToExpr);
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
                paths.Add(new PathInfo(existsVars, varToExpr, pathExprs));
            }
Example #20
0
            public override Cmd VisitAssumeCmd(AssumeCmd node)
            {
                currCmd = node;
                var b = base.VisitAssumeCmd(node);

                currCmd = null;
                return(b);
            }
Example #21
0
        public override Cmd VisitAssumeCmd(AssumeCmd node)
        {
            var result = Translate(node.Expr);

            ReturnResult(IsaBoogieTerm.Assume(result));

            return(node);
        }
Example #22
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);
        }
Example #23
0
        AssumeCmd GetQuery(Function func, Expr arg)
        {
            var ret = new AssumeCmd(Token.NoToken, new NAryExpr(Token.NoToken, new FunctionCall(func), new List <Expr> {
                arg
            }));

            ret.Attributes = new QKeyValue(Token.NoToken, "ForDeadCodeDetection", new List <object>(), ret.Attributes);
            return(ret);
        }
Example #24
0
 public override Cmd VisitAssumeCmd(AssumeCmd node)
 {
     if (node.Expr.Equals(Expr.False))
     {
         // "assume false" has a special return command inserted as the TransferCmd, which is not recognized initially for some reason
         // this is a hack to force its addition to the nodeToImpl dictionary. A
         nodeToImpl[worklist.cmdBlocks[node].TransferCmd] = nodeToImpl[node];
     }
     return(worklist.SimpleTransform(node) as Cmd);
 }
Example #25
0
        private static AssumeCmd DetermineConflictingAction(CallCounterexample CallCex, string RaceyState, string AccessHasOccurred, string AccessOffset)
        {
            AssumeCmd LastLogAssume   = null;
            string    LastOffsetValue = null;

            foreach (var b in CallCex.Trace)
            {
                bool finished = false;
                foreach (var c in b.Cmds.OfType <AssumeCmd>())
                {
                    string StateName = QKeyValue.FindStringAttribute(c.Attributes, "captureState");
                    if (StateName == null)
                    {
                        continue;
                    }
                    Model.CapturedState state = GetStateFromModel(StateName, CallCex.Model);
                    if (state == null || state.TryGet(AccessHasOccurred) is Model.Uninterpreted)
                    {
                        // Either the state was not recorded, or the state has nothing to do with the reported error, so do not
                        // analyse it further.
                        continue;
                    }

                    Model.Boolean   AHO_value = state.TryGet(AccessHasOccurred) as Model.Boolean;
                    Model.BitVector AO_value  =
                        (RaceInstrumentationUtil.RaceCheckingMethod == RaceCheckingMethod.ORIGINAL
            ? state.TryGet(AccessOffset)
            : CallCex.Model.TryGetFunc(AccessOffset).GetConstant()) as Model.BitVector;

                    if (!AHO_value.Value)
                    {
                        LastLogAssume   = null;
                        LastOffsetValue = null;
                    }
                    else if (LastLogAssume == null || !AO_value.Numeral.Equals(LastOffsetValue))
                    {
                        LastLogAssume   = c;
                        LastOffsetValue = AO_value.Numeral;
                    }
                    if (StateName.Equals(RaceyState))
                    {
                        finished = true;
                    }
                    break;
                }
                if (finished)
                {
                    break;
                }
            }

            Debug.Assert(LastLogAssume != null);
            return(LastLogAssume);
        }
Example #26
0
 private void ParseAndRenameFunctionsInAssume(Thread thread, Implementation impl, Block block,
                                              AssumeCmd cmd, IdentifierExpr tid)
 {
     if (cmd.Expr is NAryExpr)
     {
         this.ParseAndRenameNAryExpr(thread, impl, block, cmd.Expr as NAryExpr, tid);
     }
     else if (cmd.Expr is IdentifierExpr)
     {
         this.ParseAndRenameIdentifier(thread, impl, block, cmd.Expr as IdentifierExpr, tid);
     }
 }
        private void InstrumentSourceLocationInfo(Implementation impl)
        {
            foreach (var b in impl.Blocks)
            {
                for (int idx = 0; idx < b.Cmds.Count; idx++)
                {
                    if (!(b.Cmds[idx] is CallCmd))
                    {
                        continue;
                    }
                    CallCmd call = b.Cmds[idx] as CallCmd;

                    AssumeCmd assume = null;
                    for (int i = idx; i >= 0; i--)
                    {
                        if (b.Cmds[i] is AssumeCmd)
                        {
                            assume = b.Cmds[i] as AssumeCmd;
                            break;
                        }
                    }

                    if (assume == null)
                    {
                        for (int i = idx; i < b.Cmds.Count; i++)
                        {
                            if (b.Cmds[i] is AssumeCmd)
                            {
                                assume = b.Cmds[i] as AssumeCmd;
                                break;
                            }
                        }
                    }

                    if (call.callee.Contains("_UPDATE_CLS"))
                    {
                        call.Attributes = this.GetSourceLocationAttributes(
                            assume.Attributes, call.Attributes);
                    }
                    else if (call.callee.Contains("_WRITE_LS_"))
                    {
                        call.Attributes = this.GetSourceLocationAttributes(
                            assume.Attributes, call.Attributes);
                    }
                    else if (call.callee.Contains("_READ_LS_"))
                    {
                        call.Attributes = this.GetSourceLocationAttributes(
                            assume.Attributes, call.Attributes);
                    }
                }
            }
        }
Example #28
0
        List <Cmd> ProcessAssume(AssumeCmd cmd)
        {
            var ret = new List <Cmd>();

            Reset();
            var expr = base.VisitExpr(cmd.Expr);

            ret.AddRange(GetTmpAssignments());
            cmd.Expr = expr;
            ret.Add(cmd);

            return(ret);
        }
Example #29
0
        List <Cmd> ProcessAssume(AssumeCmd cmd, Dictionary <string, string> varDecls)
        {
            var ret = new List <Cmd>();

            var gm = new GatherMemAccesses();

            gm.VisitExpr(cmd.Expr);
            foreach (var tup in gm.accesses)
            {
                ret.Add(MkAssert(tup.Item2));
            }
            ret.Add(cmd);
            return(ret);
        }
Example #30
0
        List <Cmd> ProcessAssume(AssumeCmd cmd)
        {
            var ret = new List <Cmd>();

            var gm = new GatherMemAccesses();

            gm.VisitExpr(cmd.Expr);
            foreach (var tup in gm.accesses)
            {
                ret.AddRange(MkAssert(tup.Item2));
            }
            ret.Add(cmd);
            return(ret);
        }