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; }
public IEnumerable<APC> Successors (APC pc) { DecoratorHelper.Push<IEdgeSubroutineAdaptor> (this); try { return this.underlying.Successors (pc); } finally { DecoratorHelper.Pop (); } }
public APC Next (APC pc) { APC next; if (this.HasSingleSuccessor (pc, out next)) return next; return pc; }
public bool HasSingleSuccessor (APC pc, out APC ifFound) { DecoratorHelper.Push<IEdgeSubroutineAdaptor> (this); try { return this.underlying.HasSingleSuccessor (pc, out ifFound); } finally { DecoratorHelper.Pop (); } }
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); }
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); }
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)); }
public void Suggestion(ClousotSuggestion.Kind type, string kind, APC pc, string suggestion, List<uint> causes, ClousotSuggestion.ExtraSuggestionInfo extraInfo) { }
public bool IsForwardBackEdge (APC @from, APC to) { return underlying.IsForwardBackEdge (from, to); }
public bool HasSinglePredecessor (APC pc, out APC ifFound) { return pc.Block.Subroutine.HasSinglePredecessor (pc, out ifFound); }
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) { }
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(); }
public bool IsSplitPoint (APC pc) { return this.underlying.IsSplitPoint (pc); }
public IEnumerable<APC> Successors (APC pc) { return pc.Block.Subroutine.Successors (pc); }
public bool IsBlockEnd (APC pc) { return this.underlying.IsBlockEnd (pc); }
public bool IsSplitPoint (APC pc) { if (pc.Index != pc.Block.Count) return false; return IsSplitPoint (pc.Block); }
public APC Post (APC pc) { return this.underlying.Post (pc); }
public bool IsBlockStart (APC pc) { return this.underlying.IsBlockStart (pc); }
public bool IsBlockStart (APC pc) { return pc.Index == 0; }
public APC Next (APC pc) { return this.underlying.Next (pc); }
public bool IsBlockEnd (APC pc) { return pc.Index == pc.Block.Count; }
public bool IsForwardBackEdge (APC @from, APC to) { if (to.Index != 0) return false; return this.IsForwardBackEdgeHelper (from, to); }
public APC Post (APC pc) { APC next; return this.HasSingleSuccessor (pc, out next) ? next : pc; }
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); }
public abstract Result ForwardDecode <Data, Result, Visitor> (APC pc, Visitor visitor, Data data) where Visitor : IILVisitor <APC, Dummy, Dummy, Data, Result>;