Extended test with "cross-over arrays".
Rationale:
Since HIR is mostly sloppy with array references types, it is good
to extend the tests with some false invariant array references.
Bug: 22538329
Change-Id: I2ef22cbdc999c0d627590f76e7bac61984ac6ad6
diff --git a/test/525-arrays-and-fields/src/Main.java b/test/525-arrays-and-fields/src/Main.java
index cd976b2..cb1e4af 100644
--- a/test/525-arrays-and-fields/src/Main.java
+++ b/test/525-arrays-and-fields/src/Main.java
@@ -213,6 +213,64 @@
}
//
+ // Loops on static arrays with a cross-over reference.
+ //
+
+ private static void SCrossOverLoopZ() {
+ for (int i = 0; i < sArrZ.length; i++) {
+ sArrZ[i] = !sArrZ[20];
+ }
+ }
+
+ private static void SCrossOverLoopB() {
+ for (int i = 0; i < sArrB.length; i++) {
+ sArrB[i] = (byte)(sArrB[20] + 2);
+ }
+ }
+
+ private static void SCrossOverLoopC() {
+ for (int i = 0; i < sArrC.length; i++) {
+ sArrC[i] = (char)(sArrC[20] + 2);
+ }
+ }
+
+ private static void SCrossOverLoopS() {
+ for (int i = 0; i < sArrS.length; i++) {
+ sArrS[i] = (short)(sArrS[20] + 2);
+ }
+ }
+
+ private static void SCrossOverLoopI() {
+ for (int i = 0; i < sArrI.length; i++) {
+ sArrI[i] = sArrI[20] + 2;
+ }
+ }
+
+ private static void SCrossOverLoopJ() {
+ for (int i = 0; i < sArrJ.length; i++) {
+ sArrJ[i] = sArrJ[20] + 2;
+ }
+ }
+
+ private static void SCrossOverLoopF() {
+ for (int i = 0; i < sArrF.length; i++) {
+ sArrF[i] = sArrF[20] + 2;
+ }
+ }
+
+ private static void SCrossOverLoopD() {
+ for (int i = 0; i < sArrD.length; i++) {
+ sArrD[i] = sArrD[20] + 2;
+ }
+ }
+
+ private static void SCrossOverLoopL() {
+ for (int i = 0; i < sArrL.length; i++) {
+ sArrL[i] = (sArrL[20] == anObject) ? anotherObject : anObject;
+ }
+ }
+
+ //
// Loops on instance arrays with invariant instance field references.
//
@@ -345,6 +403,65 @@
mL = anotherObject;
}
}
+
+ //
+ // Loops on instance arrays with a cross-over reference.
+ //
+
+ private void CrossOverLoopZ() {
+ for (int i = 0; i < mArrZ.length; i++) {
+ mArrZ[i] = !mArrZ[20];
+ }
+ }
+
+ private void CrossOverLoopB() {
+ for (int i = 0; i < mArrB.length; i++) {
+ mArrB[i] = (byte)(mArrB[20] + 2);
+ }
+ }
+
+ private void CrossOverLoopC() {
+ for (int i = 0; i < mArrC.length; i++) {
+ mArrC[i] = (char)(mArrC[20] + 2);
+ }
+ }
+
+ private void CrossOverLoopS() {
+ for (int i = 0; i < mArrS.length; i++) {
+ mArrS[i] = (short)(mArrS[20] + 2);
+ }
+ }
+
+ private void CrossOverLoopI() {
+ for (int i = 0; i < mArrI.length; i++) {
+ mArrI[i] = mArrI[20] + 2;
+ }
+ }
+
+ private void CrossOverLoopJ() {
+ for (int i = 0; i < mArrJ.length; i++) {
+ mArrJ[i] = mArrJ[20] + 2;
+ }
+ }
+
+ private void CrossOverLoopF() {
+ for (int i = 0; i < mArrF.length; i++) {
+ mArrF[i] = mArrF[20] + 2;
+ }
+ }
+
+ private void CrossOverLoopD() {
+ for (int i = 0; i < mArrD.length; i++) {
+ mArrD[i] = mArrD[20] + 2;
+ }
+ }
+
+ private void CrossOverLoopL() {
+ for (int i = 0; i < mArrL.length; i++) {
+ mArrL[i] = (mArrL[20] == anObject) ? anotherObject : anObject;
+ }
+ }
+
//
// Driver and testers.
//
@@ -366,6 +483,10 @@
for (int i = 0; i < sArrZ.length; i++) {
expectEquals(i <= 10, sArrZ[i]);
}
+ SCrossOverLoopZ();
+ for (int i = 0; i < sArrZ.length; i++) {
+ expectEquals(i <= 20, sArrZ[i]);
+ }
// Type B.
sB = 1;
sArrB = new byte[100];
@@ -377,6 +498,10 @@
for (int i = 0; i < sArrB.length; i++) {
expectEquals(i <= 10 ? 1 : 2, sArrB[i]);
}
+ SCrossOverLoopB();
+ for (int i = 0; i < sArrB.length; i++) {
+ expectEquals(i <= 20 ? 4 : 6, sArrB[i]);
+ }
// Type C.
sC = 2;
sArrC = new char[100];
@@ -388,6 +513,10 @@
for (int i = 0; i < sArrC.length; i++) {
expectEquals(i <= 10 ? 2 : 3, sArrC[i]);
}
+ SCrossOverLoopC();
+ for (int i = 0; i < sArrC.length; i++) {
+ expectEquals(i <= 20 ? 5 : 7, sArrC[i]);
+ }
// Type S.
sS = 3;
sArrS = new short[100];
@@ -399,6 +528,10 @@
for (int i = 0; i < sArrS.length; i++) {
expectEquals(i <= 10 ? 3 : 4, sArrS[i]);
}
+ SCrossOverLoopS();
+ for (int i = 0; i < sArrS.length; i++) {
+ expectEquals(i <= 20 ? 6 : 8, sArrS[i]);
+ }
// Type I.
sI = 4;
sArrI = new int[100];
@@ -410,6 +543,10 @@
for (int i = 0; i < sArrI.length; i++) {
expectEquals(i <= 10 ? 4 : 5, sArrI[i]);
}
+ SCrossOverLoopI();
+ for (int i = 0; i < sArrI.length; i++) {
+ expectEquals(i <= 20 ? 7 : 9, sArrI[i]);
+ }
// Type J.
sJ = 5;
sArrJ = new long[100];
@@ -421,6 +558,10 @@
for (int i = 0; i < sArrJ.length; i++) {
expectEquals(i <= 10 ? 5 : 6, sArrJ[i]);
}
+ SCrossOverLoopJ();
+ for (int i = 0; i < sArrJ.length; i++) {
+ expectEquals(i <= 20 ? 8 : 10, sArrJ[i]);
+ }
// Type F.
sF = 6.0f;
sArrF = new float[100];
@@ -432,6 +573,10 @@
for (int i = 0; i < sArrF.length; i++) {
expectEquals(i <= 10 ? 6 : 7, sArrF[i]);
}
+ SCrossOverLoopF();
+ for (int i = 0; i < sArrF.length; i++) {
+ expectEquals(i <= 20 ? 9 : 11, sArrF[i]);
+ }
// Type D.
sD = 7.0;
sArrD = new double[100];
@@ -443,6 +588,10 @@
for (int i = 0; i < sArrD.length; i++) {
expectEquals(i <= 10 ? 7 : 8, sArrD[i]);
}
+ SCrossOverLoopD();
+ for (int i = 0; i < sArrD.length; i++) {
+ expectEquals(i <= 20 ? 10 : 12, sArrD[i]);
+ }
// Type L.
sL = anObject;
sArrL = new Object[100];
@@ -454,6 +603,10 @@
for (int i = 0; i < sArrL.length; i++) {
expectEquals(i <= 10 ? anObject : anotherObject, sArrL[i]);
}
+ SCrossOverLoopL();
+ for (int i = 0; i < sArrL.length; i++) {
+ expectEquals(i <= 20 ? anObject : anotherObject, sArrL[i]);
+ }
}
private void DoInstanceTests() {
@@ -468,6 +621,10 @@
for (int i = 0; i < mArrZ.length; i++) {
expectEquals(i <= 10, mArrZ[i]);
}
+ CrossOverLoopZ();
+ for (int i = 0; i < mArrZ.length; i++) {
+ expectEquals(i <= 20, mArrZ[i]);
+ }
// Type B.
mB = 1;
mArrB = new byte[100];
@@ -479,6 +636,10 @@
for (int i = 0; i < mArrB.length; i++) {
expectEquals(i <= 10 ? 1 : 2, mArrB[i]);
}
+ CrossOverLoopB();
+ for (int i = 0; i < mArrB.length; i++) {
+ expectEquals(i <= 20 ? 4 : 6, mArrB[i]);
+ }
// Type C.
mC = 2;
mArrC = new char[100];
@@ -490,6 +651,10 @@
for (int i = 0; i < mArrC.length; i++) {
expectEquals(i <= 10 ? 2 : 3, mArrC[i]);
}
+ CrossOverLoopC();
+ for (int i = 0; i < mArrC.length; i++) {
+ expectEquals(i <= 20 ? 5 : 7, mArrC[i]);
+ }
// Type S.
mS = 3;
mArrS = new short[100];
@@ -501,6 +666,10 @@
for (int i = 0; i < mArrS.length; i++) {
expectEquals(i <= 10 ? 3 : 4, mArrS[i]);
}
+ CrossOverLoopS();
+ for (int i = 0; i < mArrS.length; i++) {
+ expectEquals(i <= 20 ? 6 : 8, mArrS[i]);
+ }
// Type I.
mI = 4;
mArrI = new int[100];
@@ -512,6 +681,10 @@
for (int i = 0; i < mArrI.length; i++) {
expectEquals(i <= 10 ? 4 : 5, mArrI[i]);
}
+ CrossOverLoopI();
+ for (int i = 0; i < mArrI.length; i++) {
+ expectEquals(i <= 20 ? 7 : 9, mArrI[i]);
+ }
// Type J.
mJ = 5;
mArrJ = new long[100];
@@ -523,6 +696,10 @@
for (int i = 0; i < mArrJ.length; i++) {
expectEquals(i <= 10 ? 5 : 6, mArrJ[i]);
}
+ CrossOverLoopJ();
+ for (int i = 0; i < mArrJ.length; i++) {
+ expectEquals(i <= 20 ? 8 : 10, mArrJ[i]);
+ }
// Type F.
mF = 6.0f;
mArrF = new float[100];
@@ -534,6 +711,10 @@
for (int i = 0; i < mArrF.length; i++) {
expectEquals(i <= 10 ? 6 : 7, mArrF[i]);
}
+ CrossOverLoopF();
+ for (int i = 0; i < mArrF.length; i++) {
+ expectEquals(i <= 20 ? 9 : 11, mArrF[i]);
+ }
// Type D.
mD = 7.0;
mArrD = new double[100];
@@ -545,6 +726,10 @@
for (int i = 0; i < mArrD.length; i++) {
expectEquals(i <= 10 ? 7 : 8, mArrD[i]);
}
+ CrossOverLoopD();
+ for (int i = 0; i < mArrD.length; i++) {
+ expectEquals(i <= 20 ? 10 : 12, mArrD[i]);
+ }
// Type L.
mL = anObject;
mArrL = new Object[100];
@@ -556,6 +741,10 @@
for (int i = 0; i < mArrL.length; i++) {
expectEquals(i <= 10 ? anObject : anotherObject, mArrL[i]);
}
+ CrossOverLoopL();
+ for (int i = 0; i < mArrL.length; i++) {
+ expectEquals(i <= 20 ? anObject : anotherObject, mArrL[i]);
+ }
}
private static void expectEquals(boolean expected, boolean result) {