Beispiel #1
0
    public static Dictionary<CFGBlock, List<CFGBlock>> ComputeContainingLoopMap(ICFG cfg)
    {
      Contract.Requires(cfg != null);
      Contract.Ensures(Contract.Result<Dictionary<CFGBlock, List<CFGBlock>>>() != null);

      var result = new Dictionary<CFGBlock, List<CFGBlock>>();
      var visitedSubroutines = new Set<int>();
      var pendingSubroutines = new Stack<Subroutine>();
      var pendingAPCs = new Stack<APC>();

      var graph = cfg.AsBackwardGraph(includeExceptionEdges:false, skipContracts:true);
      foreach (var loophead in cfg.LoopHeads)
      {
        // push back-edge sources
        var loopPC = new APC(loophead, 0, null);
        foreach (var pred in cfg.Predecessors(loopPC))
        {
          if (cfg.IsForwardBackEdge(pred, loopPC))
          {
            var normalizedPred = new APC(pred.Block, 0, null);
            pendingAPCs.Push(normalizedPred);
          }
        }
        var visit = new DepthFirst.Visitor<APC, Unit>(graph,
          (APC pc) =>
          {
            if (pc.SubroutineContext != null)
            {
              // push continuation PC
              pendingAPCs.Push(new APC(pc.SubroutineContext.Head.One, 0, null));
              if (visitedSubroutines.AddQ(pc.Block.Subroutine.Id))
              {
                pendingSubroutines.Push(pc.Block.Subroutine);
              }
              return false; // stop exploration
            }
            return !pc.Equals(loopPC);
          });

        while (pendingAPCs.Count > 0)
        {
          var root = pendingAPCs.Pop();
          visit.VisitSubGraphNonRecursive(root);

          while (pendingSubroutines.Count > 0)
          {
            var sub = pendingSubroutines.Pop();
            pendingAPCs.Push(new APC(sub.Exit, 0, null));
          }
        }

        foreach (var visited in visit.Visited)
        {
          if (visited.SubroutineContext != null) continue; // ignore non-primary pcs
          MaterializeContainingLoop(result, visited.Block).AssumeNotNull().Add(loophead);
        }
      }

      return result;
    }
 public ProofObligation(APC pc, object provenance)
 {
     this.PC = pc;
     this.codeFixes = new List<ICodeFix> ();
     this.hasCodeFix = false;
     this.ID = ProofObligation.nextID++;
     this.Provenance = provenance;
 }
Beispiel #3
0
		public IEnumerable<APC> Successors (APC pc)
		{
			DecoratorHelper.Push<IEdgeSubroutineAdaptor> (this);
			try {
				return this.underlying.Successors (pc);
			} finally {
				DecoratorHelper.Pop ();
			}
		}
Beispiel #4
0
                public APC Next (APC pc)
                {
                        APC next;

                        if (this.HasSingleSuccessor (pc, out next))
                                return next;

                        return pc;
                }
Beispiel #5
0
		public bool HasSingleSuccessor (APC pc, out APC ifFound)
		{
			DecoratorHelper.Push<IEdgeSubroutineAdaptor> (this);
			try {
				return this.underlying.HasSingleSuccessor (pc, out ifFound);
			} finally {
				DecoratorHelper.Pop ();
			}
		}
Beispiel #6
0
 IEnumerable<Pair<Dummy, APC>> SuccessorsEdges (APC pc)
 {
         APC last = pc.LastInBlock ();
         foreach (APC succ in this.Successors (last))
                 yield return new Pair<Dummy, APC> (Dummy.Value, succ);
 }
Beispiel #7
0
                bool IsForwardBackEdgeHelper (APC @from, APC to)
                {
                        if (to.Block.Subroutine.EdgeInfo.IsBackEdge (from.Block, Dummy.Value, to.Block))
                                return true;

                        if (from.SubroutineContext.IsEmpty () || from.SubroutineContext.Tail != to.SubroutineContext)
                                return false;

                        Edge<CFGBlock, EdgeTag> edge = @from.SubroutineContext.Head;
                        return edge.To.Subroutine.EdgeInfo.IsBackEdge (edge.From, Dummy.Value, edge.To);
                }
Beispiel #8
0
 public Result ForwardDecode <Data, Result, Visitor> (APC pc, Visitor visitor, Data state)
     where Visitor : IILVisitor <APC, LabeledSymbol <APC, TSymbolicValue>, TSymbolicValue, Data, Result>
 {
     return(this.value_decoder.ForwardDecode <Data, Result, ILDecoderAdapter <TSymbolicValue, Data, Result, Visitor> >
                (pc, new ILDecoderAdapter <TSymbolicValue, Data, Result, Visitor> (visitor), state));
 }
Beispiel #9
0
 public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List<uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo)
 {
 }
Beispiel #10
0
 public bool IsForwardBackEdge (APC @from, APC to)
 {
         return underlying.IsForwardBackEdge (from, to);
 }
Beispiel #11
0
 public bool HasSinglePredecessor (APC pc, out APC ifFound)
 {
         return pc.Block.Subroutine.HasSinglePredecessor (pc, out ifFound);
 }
Beispiel #12
0
                public bool IsJoinPoint (APC pc)
                {
                        if (pc.Index != 0)
                                return false;

                        return IsJoinPoint (pc.Block);
                }
 public MinimalProofObligation(APC pc, BoxedExpression condition, string obligationName, object provenance)
     : base(pc, provenance)
 {
     this.condition = condition;
       		this.obligationName = obligationName;
 }
 private double GetScoreForPC(APC pc)
 {
   var Score = 1.0;
   if (pc.Block != null && !pc.PrimaryMethodLocation().HasRealSourceContext)
   {
     Score *= ScoreNoSourceContext;
   }
   return Score;
 }
 public UnderflowVisitor(APC pc, IFactQuery<BoxedExpression, Variable> facts)
     : base(pc, facts)
 {
 }
Beispiel #16
0
 public bool IsUnreachable(APC pc)
 {
     return(this.parent.IsUnreachable(pc));
 }
 public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List<uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo)
 {
   throw new NotImplementedException();
 }
Beispiel #18
0
		public bool IsSplitPoint (APC pc)
		{
			return this.underlying.IsSplitPoint (pc);
		}
Beispiel #19
0
 public IEnumerable<APC> Successors (APC pc)
 {
         return pc.Block.Subroutine.Successors (pc);
 }
Beispiel #20
0
		public bool IsBlockEnd (APC pc)
		{
			return this.underlying.IsBlockEnd (pc);
		}
Beispiel #21
0
                public bool IsSplitPoint (APC pc)
                {
                        if (pc.Index != pc.Block.Count)
                                return false;

                        return IsSplitPoint (pc.Block);
                }
Beispiel #22
0
 public APC Post (APC pc)
 {
         return this.underlying.Post (pc);
 }
Beispiel #23
0
		public bool IsBlockStart (APC pc)
		{
			return this.underlying.IsBlockStart (pc);
		}
Beispiel #24
0
 public bool IsBlockStart (APC pc)
 {
         return pc.Index == 0;
 }
Beispiel #25
0
		public APC Next (APC pc)
		{
			return this.underlying.Next (pc);
		}
Beispiel #26
0
 public bool IsBlockEnd (APC pc)
 {
         return pc.Index == pc.Block.Count;
 }
Beispiel #27
0
                public bool IsForwardBackEdge (APC @from, APC to)
                {
                        if (to.Index != 0)
                                return false;

                        return this.IsForwardBackEdgeHelper (from, to);
                }
Beispiel #28
0
 public APC Post (APC pc)
 {
         APC next;
         return this.HasSingleSuccessor (pc, out next) ? next : pc;
 }
Beispiel #29
0
 public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List<uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo)
 {
     this.WriteLine("{0}: message : Suggested {1}: {2}", pc.PrimarySourceContext(), kind, suggestion);
 }
Beispiel #30
0
 public abstract Result ForwardDecode <Data, Result, Visitor> (APC pc, Visitor visitor, Data data)
     where Visitor : IILVisitor <APC, Dummy, Dummy, Data, Result>;