Remove incorrect assertion in new array rewriting.
Integers that are outside the 8 bit area can be written to byte
arrays and are truncated. The filled-array data optimization
will do proper truncation of the value and is therefore already
correct. We just have to remove the assertion.
R=sgjesse@google.com
Change-Id: I94ee98ee3af598ca5abdc8e5e0a5887add1d12f4
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
index 509bc05..ba5611a 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
@@ -931,8 +931,6 @@
if (elementSize == 1) {
short[] result = new short[(size + 1) / 2];
for (int i = 0; i < size; i += 2) {
- assert values[i].getIntValue() <= Constants.S8BIT_MAX
- && values[i].getIntValue() >= Constants.S8BIT_MIN;
short value = (short) (values[i].getIntValue() & 0xFF);
if (i + 1 < size) {
value |= (short) ((values[i + 1].getIntValue() & 0xFF) << 8);
diff --git a/src/test/java/com/android/tools/r8/jasmin/BooleanByteConfusion.java b/src/test/java/com/android/tools/r8/jasmin/BooleanByteConfusion.java
index 2db35c4..8857e2c 100644
--- a/src/test/java/com/android/tools/r8/jasmin/BooleanByteConfusion.java
+++ b/src/test/java/com/android/tools/r8/jasmin/BooleanByteConfusion.java
@@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.jasmin;
-import static junit.framework.TestCase.assertEquals;
+import static org.junit.Assert.assertEquals;
import com.google.common.collect.ImmutableList;
import org.junit.Test;
diff --git a/src/test/java/com/android/tools/r8/jasmin/FillBooleanArrayTruncation.java b/src/test/java/com/android/tools/r8/jasmin/FillBooleanArrayTruncation.java
new file mode 100644
index 0000000..b5b2a3c
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/jasmin/FillBooleanArrayTruncation.java
@@ -0,0 +1,93 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+package com.android.tools.r8.jasmin;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.ImmutableList;
+import org.junit.Test;
+
+public class FillBooleanArrayTruncation extends JasminTestBase {
+
+ private void runTest(JasminBuilder builder, String main) throws Exception {
+ String javaResult = runOnJava(builder, main);
+ String artResult = runOnArt(builder, main);
+ assertEquals(javaResult, artResult);
+ String dxArtResult = runOnArtDx(builder, main);
+ assertEquals(javaResult, dxArtResult);
+ }
+
+ @Test
+ public void filledArray() throws Exception {
+ JasminBuilder builder = new JasminBuilder();
+ JasminBuilder.ClassBuilder clazz = builder.addClass("Test");
+
+ // Corresponds to something like the following (which doesn't compile with javac):
+ //
+ // public static void foo() {
+ // byte[] bytes = new byte[5];
+ // bytes[0] = 257;
+ // bytes[1] = -257;
+ // bytes[2] = 88;
+ // bytes[3] = 129;
+ // bytes[4] = -129;
+ // for (int i = 0; i < bytes.length; i++) {
+ // System.out.println(bytes[i]);
+ // }
+ // }
+ clazz.addStaticMethod("foo", ImmutableList.of(), "V",
+ ".limit stack 10",
+ ".limit locals 10",
+ " iconst_5",
+ " newarray byte",
+ " astore_0",
+ " aload_0",
+ " iconst_0",
+ " sipush 257",
+ " bastore",
+ " aload_0",
+ " iconst_1",
+ " sipush -257",
+ " bastore",
+ " aload_0",
+ " iconst_2",
+ " bipush 88",
+ " bastore",
+ " aload_0",
+ " iconst_3",
+ " sipush 129",
+ " bastore",
+ " aload_0",
+ " iconst_4",
+ " sipush -129",
+ " bastore",
+ " iconst_0",
+ " istore_1",
+ "PrintLoop:",
+ " iload_1",
+ " aload_0",
+ " arraylength",
+ " if_icmpge Return",
+ " getstatic java/lang/System.out Ljava/io/PrintStream;",
+ " aload_0",
+ " iload_1",
+ " baload",
+ " invokevirtual java/io/PrintStream.println(I)V",
+ " iinc 1 1",
+ " goto PrintLoop",
+ "Return:",
+ " return");
+
+ // public static void main(String args[]) {
+ // foo();
+ // }
+ clazz.addMainMethod(
+ ".limit stack 2",
+ ".limit locals 10",
+ " invokestatic Test/foo()V",
+ " return");
+
+ runTest(builder, clazz.name);
+ }
+}