StandardInstructionVisitor: kill instruction state on ArrayIndexOutOfBounds

This commit is contained in:
Tagir Valeev
2019-02-20 11:17:09 +07:00
parent 591e3a00d5
commit dafe2e8918
6 changed files with 17 additions and 6 deletions

View File

@@ -166,6 +166,9 @@ public class StandardInstructionVisitor extends InstructionVisitor {
}
}
processArrayAccess(arrayExpression, alwaysOutOfBounds);
if (alwaysOutOfBounds) {
return DfaInstructionState.EMPTY_ARRAY;
}
DfaValue result = instruction.getValue();
LongRangeSet rangeSet = memState.getValueFact(index, DfaFactType.RANGE);

View File

@@ -3,7 +3,7 @@ class Test {
if (params == null) {
params = <flown1112>new int[]{<flown11121>-1};
}
params[3] = <flown1113>44;
params[0] = <flown1113>44;
for (int <flown11>param : <flown111>params) y(<flown1>param);
}

View File

@@ -28,7 +28,9 @@ class Auto {
{
Integer i = null;
int[] ia = new int[0];
int i2 = ia[<warning descr="Array index is out of bounds"><warning descr="Unboxing of 'i' may produce 'NullPointerException'">i</warning></warning>];
if (Math.random() > 0.5) {
int i2 = ia[<warning descr="Array index is out of bounds"><warning descr="Unboxing of 'i' may produce 'NullPointerException'">i</warning></warning>];
}
}
{
Integer i = null;

View File

@@ -56,7 +56,9 @@ class ArrayInitializerLength {
void test2DArray() {
int[][] md = {{1, 2, 3}, {3, 4}};
int elem = md[1][<warning descr="Array index is out of bounds">2</warning>];
if(Math.random() > 0.5) {
int elem = md[1][<warning descr="Array index is out of bounds">2</warning>];
}
int[] subArray = md[0];
if (<warning descr="Condition 'subArray.length == 3' is always 'true'">subArray.length == 3</warning>) {
System.out.println("Always");

View File

@@ -52,8 +52,12 @@ public final class ArrayLength {
}
public static void testArray(int[] x, int a) {
x[<warning descr="Array index is out of bounds">-1</warning>] = -2;
x[<warning descr="Array index is out of bounds">x.length</warning>] = -1;
if(Math.random() > 0.5) {
x[<warning descr="Array index is out of bounds">-1</warning>] = -2;
}
if(Math.random() > 0.5) {
x[<warning descr="Array index is out of bounds">x.length</warning>] = -1;
}
x[a] = 6;
if(<warning descr="Condition 'a < 0' is always 'false'">a < 0</warning>) {
System.out.println("never");

View File

@@ -11,7 +11,7 @@ class Test {
}
void test(Integer x, String[] data) {
if(x < 0 && data[<warning descr="Array index is out of bounds">x</warning>].isEmpty()) {}
if(<warning descr="Condition 'x < 0 && data[x].isEmpty()' is always 'false'">x < 0 && data[<warning descr="Array index is out of bounds">x</warning>].isEmpty()</warning>) {}
}
void testRangeOutOfThinAir(int x) {