X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FFlowDownCheck.java;h=8886dccd7f3d56862125a2de476810de245a40ea;hp=f466b0edbe8abaedb2c3931d54a883e8d0007e5f;hb=aa7bbfbe86d24ae3b0e45e426b172a4bea21f97e;hpb=ff3ceae6b47a1a01bc56fa55fa5770cba0bf252f diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index f466b0ed..8886dccd 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -332,7 +332,7 @@ public class FlowDownCheck { } // second, check return location annotation - if (!md.getReturnType().isVoid()) { + if (!md.getReturnType().isVoid() && !ssjava.getMethodContainingSSJavaLoop().equals(md)) { if (!hasReturnLocDeclaration) { // if developer does not define method lattice // search return location in the method default lattice @@ -351,7 +351,7 @@ public class FlowDownCheck { } - if (!md.getReturnType().isVoid()) { + if (!md.getReturnType().isVoid() && !ssjava.getMethodContainingSSJavaLoop().equals(md)) { MethodLattice methodLattice = ssjava.getMethodLattice(md); String thisLocId = methodLattice.getThisLoc(); if ((!md.isStatic()) && thisLocId == null) { @@ -547,6 +547,8 @@ public class FlowDownCheck { ExpressionNode returnExp = rn.getReturnExpression(); + CompositeLocation declaredReturnLoc = md2ReturnLoc.get(md); + CompositeLocation returnValueLoc; if (returnExp != null) { returnValueLoc = @@ -568,9 +570,40 @@ public class FlowDownCheck { // generateErrorMessage(md.getClassDesc(), rn)); // } + if (constraint != null) { + + // Set inputGLB = new HashSet(); + // inputGLB.add(returnValueLoc); + // inputGLB.add(constraint); + // returnValueLoc = + // CompositeLattice.calculateGLB(inputGLB, + // generateErrorMessage(md.getClassDesc(), rn)); + + // if (!returnValueLoc.get(returnValueLoc.getSize() - 1).isTop()) { + // if (!CompositeLattice.isGreaterThan(constraint, returnValueLoc, + // generateErrorMessage(md.getClassDesc(), rn))) { + // System.out.println("returnValueLoc.get(returnValueLoc.getSize() - 1).isTop()=" + // + returnValueLoc.get(returnValueLoc.getSize() - 1).isTop()); + // throw new Error("The value flow from " + constraint + " to " + + // returnValueLoc + // + " does not respect location hierarchy on the assignment " + + // rn.printNode(0) + // + " at " + md.getClassDesc().getSourceFileName() + "::" + + // rn.getNumLine()); + // } + // } + + if (!CompositeLattice.isGreaterThan(constraint, declaredReturnLoc, + generateErrorMessage(md.getClassDesc(), rn))) { + throw new Error("The value flow from " + constraint + " to " + declaredReturnLoc + + " does not respect location hierarchy on the assignment " + rn.printNode(0) + + " at " + md.getClassDesc().getSourceFileName() + "::" + rn.getNumLine()); + } + + } + // check if return value is equal or higher than RETRUNLOC of method // declaration annotation - CompositeLocation declaredReturnLoc = md2ReturnLoc.get(md); int compareResult = CompositeLattice.compare(returnValueLoc, declaredReturnLoc, false, @@ -668,7 +701,6 @@ public class FlowDownCheck { constraint, false); // addLocationType(isn.getCondition().getType(), condLoc); - constraint = generateNewConstraint(constraint, condLoc); checkLocationFromBlockNode(md, nametable, isn.getTrueBlock(), constraint); @@ -1021,6 +1053,10 @@ public class FlowDownCheck { // location in the caller's perspective CompositeLocation ceilingLoc = computeCeilingLocationForCaller(md, nametable, min, baseLocation, constraint); + + if (ceilingLoc == null) { + return new CompositeLocation(Location.createTopLocation(md)); + } return ceilingLoc; } } @@ -1140,7 +1176,9 @@ public class FlowDownCheck { List argList = new ArrayList(); // by default, method has a THIS parameter - argList.add(baseLocation); + if (!min.getMethod().isStatic()) { + argList.add(baseLocation); + } for (int i = 0; i < min.numArgs(); i++) { ExpressionNode en = min.getArg(i); @@ -1150,8 +1188,7 @@ public class FlowDownCheck { argList.add(callerArg); } - // System.out.println("\n## computeReturnLocation=" + min.getMethod() + - // " argList=" + argList); + // System.out.println("\n## computeReturnLocation=" + min.getMethod() + " argList=" + argList); CompositeLocation ceilLoc = md2ReturnLocGen.get(min.getMethod()).computeReturnLocation(argList); // System.out.println("## ReturnLocation=" + ceilLoc); @@ -1162,11 +1199,13 @@ public class FlowDownCheck { private void checkCalleeConstraints(MethodDescriptor md, SymbolTable nametable, MethodInvokeNode min, CompositeLocation callerBaseLoc, CompositeLocation constraint) { - // System.out.println("checkCalleeConstraints=" + min.printNode(0)); - MethodDescriptor calleemd = min.getMethod(); MethodLattice calleeLattice = ssjava.getMethodLattice(calleemd); + + System.out.println("checkCalleeConstraints=" + calleemd + " calleeLattice.getThisLoc()=" + + calleeLattice.getThisLoc()); + CompositeLocation calleeThisLoc = new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc())); @@ -1179,7 +1218,8 @@ public class FlowDownCheck { // setup caller args set // first, add caller's base(this) location - callerArgList.add(callerBaseLoc); + if (!calleemd.isStatic()) + callerArgList.add(callerBaseLoc); // second, add caller's arguments for (int i = 0; i < min.numArgs(); i++) { ExpressionNode en = min.getArg(i); @@ -1191,7 +1231,8 @@ public class FlowDownCheck { // setup callee params set // first, add callee's this location - calleeParamList.add(calleeThisLoc); + if (!calleemd.isStatic()) + calleeParamList.add(calleeThisLoc); // second, add callee's parameters for (int i = 0; i < calleemd.numParameters(); i++) { VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i); @@ -1274,7 +1315,7 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromArrayAccessNode(MethodDescriptor md, SymbolTable nametable, ArrayAccessNode aan, CompositeLocation constraint, boolean isLHS) { - + System.out.println("aan=" + aan.printNode(0) + " line#=" + aan.getNumLine()); ClassDescriptor cd = md.getClassDesc(); CompositeLocation arrayLoc = @@ -1499,26 +1540,28 @@ public class FlowDownCheck { } } + Set inputGLB = new HashSet(); if (left instanceof ArrayAccessNode) { ArrayAccessNode aan = (ArrayAccessNode) left; - left = aan.getExpression(); + CompositeLocation indexLoc = + checkLocationFromExpressionNode(md, nametable, aan.getIndex(), loc, constraint, false); + inputGLB.add(indexLoc); } loc = checkLocationFromExpressionNode(md, nametable, left, loc, constraint, false); - // System.out.println("### checkLocationFromFieldAccessNode=" + - // fan.printNode(0)); - // System.out.println("### left=" + left.printNode(0)); if (!left.getType().isPrimitive()) { - if (fd.getSymbol().equals("length")) { + if (!fd.getSymbol().equals("length")) { // array.length access, return the location of the array - return loc; + Location fieldLoc = getFieldLocation(fd); + loc.addLocation(fieldLoc); } - Location fieldLoc = getFieldLocation(fd); - loc.addLocation(fieldLoc); } + + inputGLB.add(loc); + loc = CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(md.getClassDesc(), fan)); return loc; } @@ -1562,7 +1605,6 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md, SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) { - ClassDescriptor cd = md.getClassDesc(); Set inputGLBSet = new HashSet(); @@ -1602,11 +1644,21 @@ public class FlowDownCheck { } if (constraint != null) { - inputGLBSet.add(srcLocation); - inputGLBSet.add(constraint); - srcLocation = CompositeLattice.calculateGLB(inputGLBSet, generateErrorMessage(cd, an)); + + if (!CompositeLattice.isGreaterThan(constraint, destLocation, generateErrorMessage(cd, an))) { + throw new Error("The value flow from " + constraint + " to " + destLocation + + " does not respect location hierarchy on the assignment " + an.printNode(0) + + " at " + cd.getSourceFileName() + "::" + an.getNumLine()); + } + // inputGLBSet.add(srcLocation); + // inputGLBSet.add(constraint); + // srcLocation = CompositeLattice.calculateGLB(inputGLBSet, + // generateErrorMessage(cd, an)); } + // System.out.println("src=" + srcLocation + " dest=" + destLocation + " const=" + + // constraint); + if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) { String context = ""; @@ -1636,9 +1688,17 @@ public class FlowDownCheck { constraint, false); if (constraint != null) { - inputGLBSet.add(rhsLocation); - inputGLBSet.add(constraint); - srcLocation = CompositeLattice.calculateGLB(inputGLBSet, generateErrorMessage(cd, an)); + + if (!CompositeLattice.isGreaterThan(constraint, destLocation, generateErrorMessage(cd, an))) { + throw new Error("The value flow from " + constraint + " to " + destLocation + + " does not respect location hierarchy on the assignment " + an.printNode(0) + + " at " + cd.getSourceFileName() + "::" + an.getNumLine()); + } + // inputGLBSet.add(rhsLocation); + // inputGLBSet.add(constraint); + // srcLocation = CompositeLattice.calculateGLB(inputGLBSet, + // generateErrorMessage(cd, an)); + srcLocation = rhsLocation; } else { srcLocation = rhsLocation; } @@ -2081,7 +2141,6 @@ public class FlowDownCheck { SSJavaLattice locOrder = getLatticeByDescriptor(priorityDescriptor); String glbOfPriorityLoc = locOrder.getGLB(priorityLocIdentifierSet); - glbCompLoc.addLocation(new Location(priorityDescriptor, glbOfPriorityLoc)); Set compSet = locId2CompLocSet.get(glbOfPriorityLoc); @@ -2343,6 +2402,9 @@ class ReturnLocGenerator { // compute GLB of arguments subset that are same or higher than return // location if (inputGLB.isEmpty()) { + if (args.size() == 0) { + return null; + } CompositeLocation rtr = new CompositeLocation(Location.createTopLocation(args.get(0).get(0).getDescriptor())); return rtr;