From: yeom Date: Mon, 29 Oct 2012 01:22:26 +0000 (+0000) Subject: changes: mainly fixed problems of a tertiary node, pc loc checking, flow edges of... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=commitdiff_plain;h=cecb3c8f43767fd4f7c6134f6163152ec0018fea changes: mainly fixed problems of a tertiary node, pc loc checking, flow edges of array/index expressions. --- diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index 4dd4eaf2..b5f22d32 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -914,24 +914,25 @@ public class FlowDownCheck { // System.out.println("# false=" + tn.getFalseExpr().printNode(0) + " Loc=" // + falseLoc); - // check if condLoc is higher than trueLoc & falseLoc - if (!trueLoc.get(0).isTop() - && !CompositeLattice.isGreaterThan(condLoc, trueLoc, generateErrorMessage(cd, tn))) { - throw new Error( - "The location of the condition expression is lower than the true expression at " - + cd.getSourceFileName() + ":" + tn.getCond().getNumLine()); - } - - if (!falseLoc.get(0).isTop() - && !CompositeLattice.isGreaterThan(condLoc, falseLoc, - generateErrorMessage(cd, tn.getCond()))) { - throw new Error( - "The location of the condition expression is lower than the false expression at " - + cd.getSourceFileName() + ":" + tn.getCond().getNumLine()); - } + // we don't need to check that condLoc is higher than trueLoc & falseLoc + // if (!trueLoc.get(0).isTop() + // && !CompositeLattice.isGreaterThan(condLoc, trueLoc, generateErrorMessage(cd, tn))) { + // throw new Error( + // "The location of the condition expression is lower than the true expression at " + // + cd.getSourceFileName() + ":" + tn.getCond().getNumLine()); + // } + // + // if (!falseLoc.get(0).isTop() + // && !CompositeLattice.isGreaterThan(condLoc, falseLoc, + // generateErrorMessage(cd, tn.getCond()))) { + // throw new Error( + // "The location of the condition expression is lower than the false expression at " + // + cd.getSourceFileName() + ":" + tn.getCond().getNumLine()); + // } // then, return glb of trueLoc & falseLoc Set glbInputSet = new HashSet(); + glbInputSet.add(condLoc); glbInputSet.add(trueLoc); glbInputSet.add(falseLoc); @@ -1054,7 +1055,7 @@ public class FlowDownCheck { + " paramCompareResult=" + paramCompareResult); if (!(paramLocation.get(0).equals(calleePCLOC.get(0)) && calleePCLOC.getSize() > 1) - && paramCompareResult != ComparisonResult.GREATER) { + && paramCompareResult == ComparisonResult.LESS) { throw new Error( "The argument(idx=" + idx @@ -2127,7 +2128,11 @@ public class FlowDownCheck { } else if (lattice.isGreaterThan(loc1.getLocIdentifier(), loc2.getLocIdentifier())) { return ComparisonResult.GREATER; } else { - return ComparisonResult.LESS; + if (lattice.isComparable(loc1.getLocIdentifier(), loc2.getLocIdentifier())) { + return ComparisonResult.LESS; + } else { + return ComparisonResult.INCOMPARABLE; + } } } diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 2e7e9004..9ebbde38 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -481,109 +481,14 @@ public class LocationInference { translateMapLocationToInferCompositeLocationToCalleeGraph(callerGlobalFlowGraph, min); MethodDescriptor mdCallee = min.getMethod(); calleeSet.add(mdCallee); - // - // FlowGraph calleeFlowGraph = getFlowGraph(mdCallee); - // - // NTuple methodInvokeBaseDescTuple = mapMethodInvokeNodeToBaseTuple.get(min); - // NTuple methodInvokeBaseLocTuple = null; - // if (methodInvokeBaseDescTuple != null) { - // methodInvokeBaseLocTuple = translateToLocTuple(mdCaller, methodInvokeBaseDescTuple); - // } - - // //////////////// - // //////////////// - - // If the location of an argument has a composite location - // need to assign a proper composite location to the corresponding callee parameter - // System.out.println("---translate arg composite location to callee param. min=" - // + min.printNode(0)); - // Map> mapIdxToArgTuple = - // mapMethodInvokeNodeToArgIdxMap.get(min); - // Set idxSet = mapIdxToArgTuple.keySet(); - // for (Iterator iterator2 = idxSet.iterator(); iterator2.hasNext();) { - // Integer idx = (Integer) iterator2.next(); - // - // if (idx == 0 && !min.getMethod().isStatic()) { - // continue; - // } - // - // NTuple argTuple = mapIdxToArgTuple.get(idx); - // if (argTuple.size() > 0) { - // // check if an arg tuple has been already assigned to a composite location - // NTuple argLocTuple = translateToLocTuple(mdCaller, argTuple); - // Location argLocalLoc = argLocTuple.get(0); - // - // // if (!isPrimitiveType(argTuple)) { - // if (callerMapLocToCompLoc.containsKey(argLocalLoc)) { - // - // CompositeLocation argLocalCompositeLocation = callerMapLocToCompLoc.get(argLocalLoc); - // CompositeLocation argCompLoc = argLocalCompositeLocation.clone(); - // for (int i = 1; i < argLocTuple.size(); i++) { - // argCompLoc.addLocation(argLocTuple.get(i)); - // } - // - // FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx); - // - // System.out - // .println("----- argLocTuple=" + argLocTuple + " argLocalLoc=+" + argLocalLoc); - // System.out.println("-------need to translate argCompLoc=" + argCompLoc - // + " with baseTuple=" + methodInvokeBaseLocTuple + " calleeParamLocTuple=" - // + calleeParamFlowNode); - // - // // CompositeLocation paramCompLoc = translateArgCompLocToParamCompLoc(min, argCompLoc); - // // calleeParamFlowNode.setCompositeLocation(paramCompLoc); - // - // // if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) { - // // - // // FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx); - // // NTuple calleeParamDescTuple = calleeParamFlowNode.getDescTuple(); - // // NTuple calleeParamLocTuple - // // =###translateCompositeLocationAssignmentToFlowGraph mdCaller=public static void - // // huffcodetab.huffman_decoder(int htIdx, int x, BitReserve br) - // - // // translateToLocTuple(mdCallee, calleeParamDescTuple); - // // - // // System.out.println("---need to translate callerCompLoc=" + callerCompLoc - // // + " with baseTuple=" + baseLocTuple + " calleeParamLocTuple=" - // // + calleeParamLocTuple); - // // - // // CompositeLocation newCalleeCompLoc = - // // translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee); - // // - // // calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0), - // // newCalleeCompLoc); - // // - // // System.out.println("---callee loc=" + calleeParamLocTuple.get(0) - // // + " newCalleeCompLoc=" + newCalleeCompLoc); - // // - // // // System.out.println("###need to assign composite location to=" + - // // // calleeParamDescTuple - // // // + " with baseTuple=" + baseLocTuple); - // // } - // - // } - // } - // } } - // //////////////// - // //////////////// for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) { MethodDescriptor callee = (MethodDescriptor) iterator.next(); translateCompositeLocationAssignmentToFlowGraph(callee); } - // for (Iterator iterator = minSet.iterator(); iterator.hasNext();) { - // MethodInvokeNode min = (MethodInvokeNode) iterator.next(); - // // add an additional ordering constraint - // // if the first element of a parameter composite location matches 'this' reference, - // // the corresponding argument in the caller is required to be higher than the translated - // // parameter location in the caller lattice - // // TODO - // // addOrderingConstraintFromCompLocParamToArg(mdCaller, min); - // } - } private CompositeLocation translateArgCompLocToParamCompLoc(MethodInvokeNode min, @@ -864,18 +769,31 @@ public class LocationInference { } else { int paramIdx = getParamIdx(callerCompLoc, mapIdxToArgTuple); if (paramIdx == -1) { - // System.out.println("*****key=" + key + " callerCompLoc=" + callerCompLoc); + // here, the first element of the current composite location comes from the current + // callee + // so transfer the same composite location to the callee if (!calleeGlobalGraph.contrainsInferCompositeLocationMapKey(key)) { - // calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, callerCompLoc); - System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc - + " newCalleeCompLoc=" + callerCompLoc); - System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); - if (!callerCompLoc.get(0).getDescriptor().equals(mdCallee)) { - System.exit(0); + if (callerCompLoc.get(0).getDescriptor().equals(mdCallee)) { + System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc + + " newCalleeCompLoc=" + callerCompLoc); + System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee); + calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, callerCompLoc); + } else { + System.out.println("3---SKIP key=" + key + " callerCompLoc=" + callerCompLoc); } } continue; } + + // It is the case where two parameters have relative orderings between them by having + // composite locations + // if we found the param idx, it means that the first part of the caller composite + // location corresponds to the one of arguments. + // for example, if the caller argument is <,> + // and the current caller composite location mapping + // <,,> + // and the parameter which matches with the caller argument is 'Br brParam' + // then, the translated callee composite location will be <,> NTuple argTuple = mapIdxToArgTuple.get(paramIdx); FlowNode paramFlowNode = calleeFlowGraph.getParamFlowNode(paramIdx); @@ -1604,34 +1522,6 @@ public class LocationInference { return prefixList; - // List> prefixList = new ArrayList>(); - // - // for (Iterator iterator = incomingNodeSet.iterator(); iterator.hasNext();) { - // GlobalFlowNode inNode = (GlobalFlowNode) iterator.next(); - // NTuple inNodeTuple = inNode.getLocTuple(); - // - // for (int i = 1; i < inNodeTuple.size(); i++) { - // NTuple prefix = inNodeTuple.subList(0, i); - // if (!prefixList.contains(prefix)) { - // prefixList.add(prefix); - // } - // } - // } - // - // Collections.sort(prefixList, new Comparator>() { - // public int compare(NTuple arg0, NTuple arg1) { - // int s0 = arg0.size(); - // int s1 = arg1.size(); - // if (s0 > s1) { - // return -1; - // } else if (s0 == s1) { - // return 0; - // } else { - // return 1; - // } - // } - // }); - // return prefixList; } private boolean containsClassDesc(ClassDescriptor cd, NTuple prefixLocTuple) { @@ -2472,7 +2362,8 @@ public class LocationInference { NTuple srcCurTuple = srcNode.getCurrentDescTuple(); NTuple dstCurTuple = dstNode.getCurrentDescTuple(); - System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple); + System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple + + " srcNode=" + srcNode + " dstNode=" + dstNode); if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1) && srcCurTuple.get(0).equals(dstCurTuple.get(0))) { @@ -3648,9 +3539,14 @@ public class LocationInference { for (int idx = 0; idx < numParam; idx++) { FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx); CompositeLocation compLoc = paramNode.getCompositeLocation(); + System.out.println("paramNode=" + paramNode + " compLoc=" + compLoc); if (compLoc != null && compLoc.get(0).getLocDescriptor().equals(min.getMethod().getThis())) { - System.out.println("$$$COMPLOC CASE=" + compLoc); + System.out.println("$$$COMPLOC CASE=" + compLoc + " idx=" + idx); + NTuple argTuple = getNodeTupleByArgIdx(min, idx); + System.out.println("--- argTuple=" + argTuple + " current compLoc=" + + callerFlowGraph.getFlowNode(argTuple).getCompositeLocation()); + NTuple translatedParamTuple = translateCompositeLocationToCaller(idx, min, compLoc); System.out.println("add a flow edge= " + argTuple + "->" + translatedParamTuple); @@ -3689,7 +3585,7 @@ public class LocationInference { tuple.add(baseTuple.get(i)); } - for (int i = baseTuple.size(); i < compLocForParam1.getSize(); i++) { + for (int i = 1; i < compLocForParam1.getSize(); i++) { Location loc = compLocForParam1.get(i); tuple.add(loc.getLocDescriptor()); } @@ -4741,7 +4637,7 @@ public class LocationInference { private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) { - // System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0)); + System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0)); NodeTupleSet tertiaryTupleNode = new NodeTupleSet(); analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null, @@ -4770,6 +4666,7 @@ public class LocationInference { newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet()); + System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet); // add edges from tertiaryTupleNode to all nodes of conditional nodes // tertiaryTupleNode.addTupleSet(implicitFlowTupleSet); analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null, @@ -4958,6 +4855,7 @@ public class LocationInference { // } // } + System.out.println("paramNode=" + paramNode + " calleeReturnSet=" + calleeReturnSet); if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet) || mdCallee.getModifiers().isNative()) { addParamNodeFlowingToReturnValue(mdCallee, paramNode); @@ -4970,6 +4868,7 @@ public class LocationInference { if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) { FlowReturnNode setNode = getFlowGraph(mdCaller).createReturnNode(min); + System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + setNode); setNode.addTupleSet(tupleSet); nodeSet.addTuple(setNode.getDescTuple()); } @@ -5035,9 +4934,13 @@ public class LocationInference { private boolean hasInFlowTo(FlowGraph fg, FlowNode inNode, Set nodeSet) { // return true if inNode has in-flows to nodeSet + if (nodeSet.contains(inNode)) { + // in this case, the method directly returns a parameter variable. + return true; + } // Set reachableSet = fg.getReachFlowNodeSetFrom(inNode); Set reachableSet = fg.getReachableSetFrom(inNode.getDescTuple()); - // System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet); + System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet); for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) { FlowNode fn = (FlowNode) iterator.next(); @@ -5327,7 +5230,6 @@ public class LocationInference { analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base, implicitFlowTupleSet, isLHS); - nodeSet.addTupleSet(idxNodeTupleSet); } base = analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, isLHS); @@ -5363,6 +5265,7 @@ public class LocationInference { } } else { + nodeSet.addTupleSet(idxNodeTupleSet); // if it is the array case and not the LHS case if (isArrayCase) {