Added minimum size analysis.
[repair.git] / Repair / RepairCompiler / MCC / IR / DotExpr.java
index be8d32489fbae24cd327c32c5192b6f99005c2fa..2e5021e940909a488fec446aa81790f79f63f319 100755 (executable)
@@ -57,12 +57,23 @@ public class DotExpr extends Expr {
     public boolean isSafe() {
        if (!left.isSafe())
            return false;
     public boolean isSafe() {
        if (!left.isSafe())
            return false;
+
        FieldDescriptor tmpfd=fd;
        FieldDescriptor tmpfd=fd;
-       if (tmpfd instanceof ArrayDescriptor)
-           return false; // Arrays could be out of bounds
+
        if (tmpfd.getPtr()) // Pointers cound be invalid
            return false;
        if (tmpfd.getPtr()) // Pointers cound be invalid
            return false;
-       return true;
+
+       if (tmpfd instanceof ArrayDescriptor) {
+            Expr arrayindex=((ArrayDescriptor)tmpfd).getIndexBound();
+            if (index instanceof IntegerLiteralExpr&&arrayindex instanceof IntegerLiteralExpr) {
+                int indexvalue=((IntegerLiteralExpr)index).getValue();
+                int arrayindexvalue=((IntegerLiteralExpr)arrayindex).getValue();
+                if (indexvalue>=0&&indexvalue<arrayindexvalue)
+                    return true;
+            }
+           return false; // Otherwise, arrays could be out of bounds
+        }
+        return true;
     }
 
     public Set freeVars() {
     }
 
     public Set freeVars() {