2 bug fixes to getRequiredConstraints
[repair.git] / Repair / RepairCompiler / MCC / IR / DotExpr.java
index 4f550a4cce8231f1c18b72f3229785be1f6ed6f9..54133026fdc63f38a933a044e3796cea27d1f3db 100755 (executable)
@@ -57,12 +57,23 @@ public class DotExpr extends Expr {
     public boolean isSafe() {
        if (!left.isSafe())
            return false;
+
        FieldDescriptor tmpfd=fd;
-       if (tmpfd instanceof ArrayDescriptor)
-           return false; // Arrays could be out of bounds
+
        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() {
@@ -147,6 +158,7 @@ public class DotExpr extends Expr {
         if (intindex != null) {
             v.addAll(intindex.getRequiredDescriptors());
         }
+        v.add(fd);
         return v;
     }
 
@@ -380,6 +392,9 @@ public class DotExpr extends Expr {
                assert intindex == null;
                intindex = ld.getIndex();
            } else {
+                if (fd==null) {
+                    throw new Error("Null fd for: "+field);
+                }
                fieldtype = fd.getType();
                intindex=index;
            }