Regression test for array aliasing bug.

Rationale:
Bug b/64018485 exposed a ARM scheduling bug that
was traced back to the load/store eliminiation utility
ArrayAccessHeapLocation(). The original bug (showing
up on device only obviously) was a bit hard to reproduce
as it required compiling boot image first. This unit
test shows failure out of the box though.

Bug: 64018485

Test: itself

Change-Id: I6d0cbce591d0a142e82ae9e440421e95270055a2
diff --git a/test/662-regression-alias/expected.txt b/test/662-regression-alias/expected.txt
new file mode 100644
index 0000000..7250211
--- /dev/null
+++ b/test/662-regression-alias/expected.txt
@@ -0,0 +1 @@
+passed 127 4
diff --git a/test/662-regression-alias/info.txt b/test/662-regression-alias/info.txt
new file mode 100644
index 0000000..584d3ee
--- /dev/null
+++ b/test/662-regression-alias/info.txt
@@ -0,0 +1 @@
+Regression test on missed array element aliasing.
diff --git a/test/662-regression-alias/src/Main.java b/test/662-regression-alias/src/Main.java
new file mode 100644
index 0000000..aad61e2
--- /dev/null
+++ b/test/662-regression-alias/src/Main.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Regression test on ARM-scheduling/array-aliasing bug (b/64018485).
+ */
+public class Main {
+
+  //
+  // Mimic original bug.
+  //
+
+  static void setFields(int[] fields) {
+    if (fields == null || fields.length < 6)
+      fields = new int[6];  // creates phi
+    fields[5] = 127;
+  }
+
+  static void processFieldValues(int field0, int field1, int field2,
+                                 int field3, int field4, int field5) {
+    if (field5 != 127) {
+      throw new Error("field = " + field5);
+    } else if (field0 != 0) {
+      processFieldValues(0, 0, 0, 0, 0, 0);  // disable inlining
+    }
+  }
+
+  static int doit(int pass) {
+    int[] fields = new int[6];
+    for (; ; pass++) {
+      setFields(fields);
+      processFieldValues(fields[0], fields[1], fields[2],
+                         fields[3], fields[4], fields[5]);
+      if (pass == 0)
+        break;
+    }
+    return fields[5];
+  }
+
+  //
+  // Similar situation.
+  //
+
+  private static int aliasing(boolean f) {
+    int[] array = new int[6];
+    int[] array2 = null;
+    int s = 0;
+    for (int i = 0; i < 1; i++) {
+      if (f) {
+        array2 = array;
+      }
+      array2[1] = 4;
+      s = array[1];
+    }
+    return s;
+  }
+
+  //
+  // Main driver.
+  //
+
+  static public void main(String[] args) {
+    int r = doit(0);
+    int s = aliasing(true);
+    System.out.println("passed " + r + " " + s);
+  }
+}
diff --git a/test/knownfailures.json b/test/knownfailures.json
index bd9591a..f89fd0a 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -716,5 +716,11 @@
         "tests": "961-default-iface-resolution-gen",
         "env_vars": {"SANITIZE_HOST": "address"},
         "description": ["Test hits dex2oat watchdog timeout (60sec) on art-asan"]
+    },
+    {
+        "tests": "662-regression-alias",
+        "variant": "target",
+        "description": ["disable until ARM scheduling/aliasing bug is fixed."],
+        "bug": "b/64018485"
     }
 ]