Do not eliminate array allocation if it may throw NegativeArraySizeException
Bug: 70023972
Test: run-test on host. 530-checker-lse.
Change-Id: I00e2d69f82b3dda21559ffcba827e0a52d900ff1
diff --git a/test/530-checker-lse/src/Main.java b/test/530-checker-lse/src/Main.java
index 98838c5..ebde3bf 100644
--- a/test/530-checker-lse/src/Main.java
+++ b/test/530-checker-lse/src/Main.java
@@ -1052,6 +1052,23 @@
return array[1] + array[i];
}
+ /// CHECK-START: int Main.testAllocationEliminationOfArray5(int) load_store_elimination (before)
+ /// CHECK: NewArray
+ /// CHECK: ArraySet
+ /// CHECK: ArrayGet
+
+ /// CHECK-START: int Main.testAllocationEliminationOfArray5(int) load_store_elimination (after)
+ /// CHECK: NewArray
+ /// CHECK-NOT: ArraySet
+ /// CHECK-NOT: ArrayGet
+ private static int testAllocationEliminationOfArray5(int i) {
+ // Cannot eliminate array allocation due to unknown i that may
+ // cause NegativeArraySizeException.
+ int[] array = new int[i];
+ array[1] = 12;
+ return array[1];
+ }
+
/// CHECK-START: int Main.testExitMerge(boolean) load_store_elimination (before)
/// CHECK: NewInstance
/// CHECK: InstanceFieldSet
@@ -1205,6 +1222,12 @@
assertIntEquals(testAllocationEliminationOfArray2(), 11);
assertIntEquals(testAllocationEliminationOfArray3(2), 4);
assertIntEquals(testAllocationEliminationOfArray4(2), 6);
+ assertIntEquals(testAllocationEliminationOfArray5(2), 12);
+ try {
+ testAllocationEliminationOfArray5(-2);
+ } catch (NegativeArraySizeException e) {
+ System.out.println("Got NegativeArraySizeException.");
+ }
assertIntEquals(testStoreStore().i, 41);
assertIntEquals(testStoreStore().j, 43);