InterProcMapping(InterProcMapping ipm) { this.calleePTG = ipm.calleePTG; this.callerPTG = ipm.callerPTG; this.callerThisRef = ipm.callerThisRef; this.arguments = ipm.arguments; this.mapping = new Dictionary<IPTAnalysisNode, Nodes>(ipm.mapping); }
public override void ApplyNonAnalyzableCall(Variable vr, Method callee, Variable receiver, ExpressionList arguments, Label lb, out InterProcMapping ipm) { Nodes receiverValues = Nodes.Empty; bool IsReceiverConsistent = false; if (receiver != null) { receiverValues = Values(receiver); IsReceiverConsistent = IsExposable(receiver); } ConsistencyForCalls(callee, lb, receiverValues, IsReceiverConsistent, receiver, arguments); // OJO!!!!!! base.ApplyNonAnalyzableCallOld(vr, callee, receiver, arguments, lb, out ipm); }
public override void ApplyAnalyzableCall(Variable vr, Method callee, Variable receiver, ExpressionList arguments, PointsToState calleecState, Label lb, out InterProcMapping ipm) { Nodes receiverValues = Nodes.Empty; bool IsReceiverConsistent = false; if (receiver != null) { receiverValues = Values(receiver); IsReceiverConsistent = IsExposable(receiver); } base.ApplyAnalyzableCall(vr, callee, receiver, arguments, calleecState, lb, out ipm); if (receiver == null) { return; } BeforeUpdateConsystency(vr, callee, receiver, arguments, calleecState, lb, ipm); ConsistencyForCalls(callee, lb, receiverValues, IsReceiverConsistent, receiver, arguments); AfterUpdateConsystency(vr, callee, receiver, arguments, calleecState, lb, ipm); }
// Get the least elements representing the bottom for the lattice of m //public static Reentrancy BottomFor(Method m) //{ // return new Reentrancy(m); //} #endregion protected override void BeforeBindCallWithCallee(PointsToState callerPTS, PointsToState calleePTS, Variable receiver, ExpressionList arguments, Variable vr, Label lb, InterProcMapping ipm) { base.BeforeBindCallWithCallee(callerPTS, calleePTS, receiver, arguments, vr, lb, ipm); Reentrancy reentrancyCalleeState = (Reentrancy)calleePTS; Receivers potentialReceivers = Receivers.Empty; // ** FOR REENTRANCY ANALYSIS if (receiver != null) { Nodes values = pointsToGraph.GetValuesIfEmptyLoadNode(receiver, lb); potentialReceivers.AddNodes(values); } bool isReentrant = false; // Check Exposure por every parameters if (!IsMethodToIgnoreForReentrancy(reentrancyCalleeState.Method)) { //isReentrant = ReentrancyAnalysisForAnalyzableCalls(reentrancyCalleeState.Method, reentrancyCalleeState, lb, // potentialReceivers, ipm); isReentrant = false; CheckExposureForCall(calleePTS, receiver, arguments, lb, isReentrant); } }
private static bool change(InterProcMapping ipm1, InterProcMapping ipm2) { int count1 = 0; int count2 = 0; foreach (IPTAnalysisNode n in ipm1.mapping.Keys) { count1 += ipm1.mapping[n].Count; } foreach (IPTAnalysisNode n in ipm2.mapping.Keys) { count2 += ipm2.mapping[n].Count; } return (count1 != count2); }
/// <summary> /// Compute the interProc mapping between callee and caller. /// This is a fixpoint of steps 1,2 and 3 /// </summary> /// <param name="caller"></param> /// <param name="callee"></param> /// <param name="thisRef"></param> /// <param name="arguments"></param> /// <returns></returns> private static InterProcMapping ComputeInterMapping(PTGraph callerPTG, PTGraph calleePTG, Variable thisRef, ExpressionList arguments, Variable vr) { /* // Be sure that every parameter has its value or load node foreach (Parameter p in callerPTG.ParameterMap.Keys) { callerPTG.GetValuesIfEmptyLoadNode(p, callerPTG.MethodLabel); } */ InterProcMapping ipm = new InterProcMapping(callerPTG, calleePTG, thisRef, arguments); ipm.RelateParams(); InterProcMapping oldImp = new InterProcMapping(ipm); do { oldImp = new InterProcMapping(ipm); ipm.MatchOutsideEdges(); ipm.MatchOutsideWithInsideInCallee(); } while (change(oldImp, ipm)); return ipm; }
protected virtual void BeforeUpdateConsystency(Variable vr, Method callee, Variable receiver, ExpressionList arguments, PointsToState calleecState, Label lb, InterProcMapping ipm) { }
/// <summary> /// Apply the inter-procedural analysis, binding information from caller and callee /// </summary> /// <param name="vr"></param> /// <param name="callee"></param> /// <param name="receiver"></param> /// <param name="arguments"></param> /// <param name="calleecState"></param> /// <param name="lb"></param> public virtual void ApplyAnalyzableCall(Variable vr, Method callee, Variable receiver, ExpressionList arguments, PointsToState calleecState, Label lb, out InterProcMapping ipm) { // Apply the binding between the pointsToGraph of the caller and the callee // Returns also the mapping used during the parameter-arguments nodes binding if (PointsToAnalysis.debug) { Console.Out.WriteLine("before call to {0}", callee.Name); //pointsToGraph.Dump(); this.Dump(); } if (this.Method.Name.Name.StartsWith("UsingFoo")) { } ipm = InterProcMapping.ComputeInterProgMapping(this.pointsToGraph, calleecState.pointsToGraph, receiver, arguments, vr, lb); BeforeBindCallWithCallee(this, calleecState, receiver, arguments, vr, lb, ipm); PTGraph interProcPTG = ipm.ComputeInterProgGraph(this.pointsToGraph, calleecState.pointsToGraph, receiver, arguments, vr, lb); pointsToGraph = interProcPTG; AfterBindCallWithCallee(this, calleecState, receiver, arguments, vr, lb, ipm); if (PointsToAnalysis.debug) { Console.Out.WriteLine("after call to {0}", callee.Name); Console.Out.WriteLine(ipm); Console.Out.WriteLine("Callee:"); calleecState.Dump(); Console.Out.WriteLine("Caller:"); this.Dump(); } // Update the set of write effects considering the writeffects of the callee // in nodes that will stay in the caller Set<LNode> removedLoadNodes = ipm.removedLoadNodes; // Join the set of non-analyzable calls //joinCalledMethod(callToNonAnalyzableMethods, calleecState.callToNonAnalyzableMethods); }
/// <summary> /// The old support for non Analyzables. TO DELETE /// </summary> /// <param name="vr"></param> /// <param name="callee"></param> /// <param name="receiver"></param> /// <param name="arguments"></param> /// <param name="lb"></param> /// <param name="ipm"></param> public virtual void ApplyNonAnalyzableCallOld(Variable vr, Method callee, Variable receiver, ExpressionList arguments, Label lb, out InterProcMapping ipm) { bool isPure = false; bool isReturnFresh = false; bool isReadingGlobals = true; bool isWritingGlobals = true; Set<Parameter> freshOutParameters = new Set<Parameter>(); Set<Parameter> escapingParameters = new Set<Parameter>(); Set<Parameter> capturedParameters = new Set<Parameter>(); Set<Variable> outArguments = new Set<Variable>(); isPure = PointsToAndEffectsAnnotations.IsAssumedPureMethod(callee); isReadingGlobals = PointsToAndEffectsAnnotations.IsDeclaredReadingGlobals(callee); isWritingGlobals = PointsToAndEffectsAnnotations.IsDeclaredWritingGlobals(callee); if (PointsToAnalysis.debug) { Console.Out.WriteLine("before NON call to {0}", callee.Name); pointsToGraph.Dump(); } if (!callee.ReturnType.IsPrimitive && !CciHelper.IsVoid(callee.ReturnType)) { isReturnFresh = PointsToAndEffectsAnnotations.IsDeclaredFresh(callee); } else if (CciHelper.IsConstructor(callee)) isReturnFresh = true; if (!callee.IsStatic && callee.ThisParameter != null) { bool captured; if (PointsToAndEffectsAnnotations.IsDeclaredEscaping(callee.ThisParameter, out captured)) { escapingParameters.Add(callee.ThisParameter); if (captured) capturedParameters.Add(callee.ThisParameter); } } if (callee.Parameters != null) { for (int i = 0; i < callee.Parameters.Count; i++) { Parameter p = callee.Parameters[i]; if (p.IsOut) { if (PointsToAndEffectsAnnotations.IsDeclaredFresh(p)) { freshOutParameters.Add(p); } outArguments.Add(arguments[i] as Variable); } bool captured; if (PointsToAndEffectsAnnotations.IsDeclaredEscaping(p, out captured)) { escapingParameters.Add(p); if (captured) capturedParameters.Add(p); } } } //if (isWritingGlobals) //{ // addNonAnalyzableMethod(lb, callee); //} if (callee.Name.Name.Equals("Hola") || callee.Name.Name.Equals("GetEnumerator2")) { } PTGraph calleFakePTG = null; // Create a fake PTG for the calle using annotations... calleFakePTG = PTGraph.PTGraphFromAnnotations(callee); // , isPure, isReturnFresh, isWritingGlobals, isReadingGlobals); // calleFakePTG.GenerateDotGraph(callee.FullName + ".dot"); NonAnalyzableCallBeforeUpdatingPTG(vr, callee, receiver, arguments, lb, isPure, isReturnFresh, isWritingGlobals, isReadingGlobals, escapingParameters, capturedParameters, freshOutParameters); /*InterProcMapping */ ipm = InterProcMapping.ComputeInterProgMapping(this.pointsToGraph, calleFakePTG, receiver, arguments, vr, lb); PTGraph interProcPTG = ipm.ComputeInterProgGraph(this.pointsToGraph, calleFakePTG, receiver, arguments, vr, lb); pointsToGraph = interProcPTG; NonAnalyzableCallAfterUpdatingPTG(vr, callee, receiver, arguments, lb, isPure, isReturnFresh, isWritingGlobals, isReadingGlobals, escapingParameters, capturedParameters, freshOutParameters); if (PointsToAnalysis.debug) { Console.Out.WriteLine("after NON call to {0}", callee.Name); pointsToGraph.Dump(); } }
/// <summary> /// Register effect of the non-analyzable call in the pointsToGraph inferring the information from the callee annotations /// Basicale creates a PTG of the callee using annotations and call the standard binding mechanism /// </summary> /// <param name="vr"></param> /// <param name="callee"></param> /// <param name="receiver"></param> /// <param name="arguments"></param> /// <param name="lb"></param> /// public virtual void ApplyNonAnalyzableCall(Variable vr, Method callee, Variable receiver, ExpressionList arguments, Label lb, out InterProcMapping ipm) { if (PointsToAnalysis.debug) { Console.Out.WriteLine("before NON call to {0}", callee.Name); pointsToGraph.Dump(); } PointsToState calleeState = CreateSummaryForFakeCallee(vr, callee, receiver, arguments, lb); ApplyAnalyzableCall(vr, callee, receiver, arguments, calleeState, lb, out ipm); if (PointsToAnalysis.debug) { Console.Out.WriteLine("after NON call to {0}", callee.Name); pointsToGraph.Dump(); } }
private void BindCallerReadEffects(PointsToAndWriteEffects calleePTWE, Label lb, InterProcMapping ipm) { foreach (AField af in calleePTWE.readEffects) { // Get the related caller's nodes foreach (IPTAnalysisNode n in ipm.RelatedExtended(af.Src)) { if (IsVisibleEffect(n, af.Field)) { readEffects.AddEffect(n, af.Field, lb); } allReadEffects.AddEffect(n, af.Field, lb); } } }
/* This was related with the old way of dealing with non analyzable calls private void RegisterModifiesInReachableObjects(Variable v, Label lb, bool confined) { // Use Filters for !owned!!!!!! Nodes reachables = PointsToGraph.NodesForwardReachableFromVariable(v, confined); foreach (IPTAnalysisNode n in reachables) { //if (n is LValueNode || n.IsGlobal) if(n.IsObjectAbstraction) { RegisterWriteEffect(n, PTGraph.allFields, lb,false); } } } private void RegisterReadInReachableObjects(Variable v, Label lb, bool confined) { // Use Filters for !owned!!!!!! Nodes reachables = PointsToGraph.NodesForwardReachableFromVariable(v,confined); foreach (IPTAnalysisNode n in reachables) { // Add Filters!!!!!! //if (n is LValueNode || n.IsGlobal) if (n.IsObjectAbstraction) { RegisterReadEffect(n, PTGraph.allFields, lb); } } } */ /// <summary> /// Apply the inter-procedural analysis, binding information from caller and callee /// </summary> /// <param name="vr"></param> /// <param name="callee"></param> /// <param name="receiver"></param> /// <param name="arguments"></param> /// <param name="calleePTWE"></param> /// <param name="lb"></param> /// public override void ApplyAnalyzableCall(Variable vr, Method callee, Variable receiver, ExpressionList arguments, PointsToState calleecState, Label lb, out InterProcMapping ipm) { if (this.method.FullName.Contains("Count")) { if (callee.Name.Name.Contains("Reverse")) { } if (callee.Name.Name.Contains("Dispose")) { } } if (callee.Name.Name.Contains("MoveNext2")) { } base.ApplyAnalyzableCall(vr, callee, receiver, arguments, calleecState, lb, out ipm); PointsToAndWriteEffects calleePTWE = (PointsToAndWriteEffects)calleecState; // Join the set of non-analyzable calls joinCalledMethod(callToNonAnalyzableMethods, calleePTWE.callToNonAnalyzableMethods); // For each write effect in the calee foreach (AField af in calleePTWE.writeEffects) { // Get the related caller's nodes foreach (IPTAnalysisNode n in ipm.RelatedExtended(af.Src)) { if (IsVisibleEffect(n, af.Field)) { writeEffects.AddEffect(n, af.Field, lb); } allWriteEffects.AddEffect(n, af.Field, lb); } } BindCallerReadEffects(calleePTWE, lb, ipm); }
/// <summary> /// Register effect of the non-analyzable call in the pointsToGraph inferring the information from the callee annotations /// </summary> /// <param name="vr"></param> /// <param name="callee"></param> /// <param name="receiver"></param> /// <param name="arguments"></param> /// <param name="lb"></param> /// public override void ApplyNonAnalyzableCall(Variable vr, Method callee, Variable receiver, ExpressionList arguments, Label lb, out InterProcMapping ipm) { if (this.method.FullName.Contains("<Except")) { if (callee.Name.Name.Contains("Reverse")) { } } if (this.method.FullName.Contains("Except")) { } if (this.method.Name.Name.Contains("MoveNext")) { } if (callee.Name.Name.Contains("MoveNext")) { } if (callee.Name.Name.Contains("GetEnumerator2")) { } if (receiver != null) { bool isDelegate = PTGraph.IsDelegateType(receiver.Type); if (isDelegate) { bool isPureDelegate = PointsToAndEffectsAnnotations.IsAssumedPureDelegate(callee.ThisParameter) || callee.FullName.Contains("Linq.Enumerable"); if (isPureDelegate) { ForceCheckForDelegate(lb, receiver); } } } // PointsToAndEffectsAnnotations.WorstCase = true; if (callee.Parameters != null) { for (int i = 0; i < callee.Parameters.Count; i++) { Parameter p = callee.Parameters[i]; bool isDelegate = PTGraph.IsDelegateType(p.Type); if (isDelegate) { bool isPureDelegate = PointsToAndEffectsAnnotations.IsAssumedPureDelegate(p) || callee.FullName.Contains("Linq.Enumerable"); if (isPureDelegate) { Variable v = (Variable)arguments[i]; ForceCheckForDelegate(lb, v); } } } } base.ApplyNonAnalyzableCall(vr, callee, receiver, arguments, lb, out ipm); // PointsToAndEffectsAnnotations.WorstCase = false; }
public override void ApplyNonAnalyzableCall(Variable vr, Method callee, Variable receiver, ExpressionList arguments, Label lb, out InterProcMapping ipm) { Nodes receiverValues = Nodes.Empty; bool IsReceiverConsistent = false; if (receiver != null) { receiverValues = Values(receiver); IsReceiverConsistent = IsExposable(receiver); } ConsistencyForCalls(callee, lb, receiverValues, IsReceiverConsistent, receiver,arguments); // OJO!!!!!! base.ApplyNonAnalyzableCallOld(vr, callee, receiver, arguments, lb, out ipm); }
protected virtual void AfterBindCallWithCallee(PointsToState callerPTS, PointsToState calleePTS, Variable receiver, ExpressionList arguments, Variable vr, Label lb, InterProcMapping ipm) { }
public override void ApplyAnalyzableCall(Variable vr, Method callee, Variable receiver, ExpressionList arguments, PointsToState calleecState, Label lb, out InterProcMapping ipm) { Nodes receiverValues = Nodes.Empty; bool IsReceiverConsistent = false; if (receiver != null) { receiverValues = Values(receiver); IsReceiverConsistent = IsExposable(receiver); } base.ApplyAnalyzableCall(vr, callee, receiver, arguments, calleecState, lb, out ipm); if(receiver==null) return; BeforeUpdateConsystency(vr, callee, receiver, arguments, calleecState, lb,ipm); ConsistencyForCalls(callee, lb, receiverValues, IsReceiverConsistent, receiver,arguments); AfterUpdateConsystency(vr, callee, receiver, arguments, calleecState, lb,ipm); }