Revert "ART: Allow PackedSwitch instructions with zero targets"
This fixed Optimizing but revealed the same issue in the interpreter.
This reverts commit 241f9c41924e33e0c3bab9a7c4306397458749ca.
Change-Id: Iad5a28b24f2c21d3575cf8ecc8b7c8fbf98d1132
diff --git a/compiler/optimizing/builder.cc b/compiler/optimizing/builder.cc
index cdd7636..1f9287c 100644
--- a/compiler/optimizing/builder.cc
+++ b/compiler/optimizing/builder.cc
@@ -1210,20 +1210,14 @@
}
void HGraphBuilder::BuildPackedSwitch(const Instruction& instruction, uint32_t dex_pc) {
- // Verifier guarantees that the payload for PackedSwitch contains:
- // (a) number of entries (may be zero)
- // (b) first and lowest switch case value (entry 0, always present)
- // (c) list of target pcs (entries 1 <= i <= N)
SwitchTable table(instruction, dex_pc, false);
// Value to test against.
HInstruction* value = LoadLocal(instruction.VRegA(), Primitive::kPrimInt);
- // Retrieve number of entries.
uint16_t num_entries = table.GetNumEntries();
- if (num_entries == 0) {
- return;
- }
+ // There should be at least one entry here.
+ DCHECK_GT(num_entries, 0U);
// Chained cmp-and-branch, starting from starting_key.
int32_t starting_key = table.GetEntryAt(0);
@@ -1235,10 +1229,6 @@
}
void HGraphBuilder::BuildSparseSwitch(const Instruction& instruction, uint32_t dex_pc) {
- // Verifier guarantees that the payload for SparseSwitch contains:
- // (a) number of entries (may be zero)
- // (b) sorted key values (entries 0 <= i < N)
- // (c) target pcs corresponding to the switch values (entries N <= i < 2*N)
SwitchTable table(instruction, dex_pc, true);
// Value to test against.
diff --git a/test/501-regression-packed-switch/expected.txt b/test/501-regression-packed-switch/expected.txt
deleted file mode 100644
index e69de29..0000000
--- a/test/501-regression-packed-switch/expected.txt
+++ /dev/null
diff --git a/test/501-regression-packed-switch/info.txt b/test/501-regression-packed-switch/info.txt
deleted file mode 100644
index f7df49d..0000000
--- a/test/501-regression-packed-switch/info.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Regression test for optimizing's builder which used to trip when compiled code
-contained a packed switch with no targets.
diff --git a/test/501-regression-packed-switch/smali/Test.smali b/test/501-regression-packed-switch/smali/Test.smali
deleted file mode 100644
index 8756ed5..0000000
--- a/test/501-regression-packed-switch/smali/Test.smali
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-# Copyright (C) 2015 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.
-
-.class public LTest;
-
-.super Ljava/lang/Object;
-
-.method public static EmptyPackedSwitch(I)I
- .registers 1
- packed-switch v0, :pswitch_data_6a
- const/4 v0, 0x5
- return v0
-
- :pswitch_data_6a
- .packed-switch 0x0
- .end packed-switch
-.end method
diff --git a/test/501-regression-packed-switch/src/Main.java b/test/501-regression-packed-switch/src/Main.java
deleted file mode 100644
index b80bc62..0000000
--- a/test/501-regression-packed-switch/src/Main.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2015 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.
- */
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-
-public class Main {
-
- // Workaround for b/18051191.
- class InnerClass {}
-
- public static void main(String args[]) throws Exception {
- Class<?> c = Class.forName("Test");
- Method m = c.getMethod("EmptyPackedSwitch", new Class[] { int.class });
- Integer result = (Integer) m.invoke(null, new Integer(42));
- if (result != 5) {
- throw new Error("Expected 5, got " + result);
- }
- }
-}