Fix wrong assumption in RemoveInstructionsAsUsersFromDeadBlocks.
It can be called in a situation where dead blocks can have phis:
the DCE pass would re-build the dominator tree and RemoveInstructionsAsUsersFromDeadBlocks
used to assume there cannot be phis.
Test: 695-simplify-throws
Bug: 131174581
Change-Id: I853956482487a8c7c8fb99499aef318d099754e4
diff --git a/compiler/optimizing/nodes.cc b/compiler/optimizing/nodes.cc
index f7c16d1..1940d55 100644
--- a/compiler/optimizing/nodes.cc
+++ b/compiler/optimizing/nodes.cc
@@ -147,7 +147,9 @@
if (!visited.IsBitSet(i)) {
HBasicBlock* block = blocks_[i];
if (block == nullptr) continue;
- DCHECK(block->GetPhis().IsEmpty()) << "Phis are not inserted at this stage";
+ for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) {
+ RemoveAsUser(it.Current());
+ }
for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
RemoveAsUser(it.Current());
}
diff --git a/test/695-simplify-throws/expected.txt b/test/695-simplify-throws/expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/695-simplify-throws/expected.txt
diff --git a/test/695-simplify-throws/info.txt b/test/695-simplify-throws/info.txt
new file mode 100644
index 0000000..3f76329
--- /dev/null
+++ b/test/695-simplify-throws/info.txt
@@ -0,0 +1,3 @@
+Regression test for the DCE pass of the compiler which used
+to trip on this code: the DCE pass would re-build the dominator
+tree and that code used to not anticipate seeing phis in the graph.
diff --git a/test/695-simplify-throws/src/Main.java b/test/695-simplify-throws/src/Main.java
new file mode 100644
index 0000000..2799624
--- /dev/null
+++ b/test/695-simplify-throws/src/Main.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+public class Main {
+ public static boolean alwaysThrows() {
+ throw new Error("");
+ }
+
+ public static void test() {
+ alwaysThrows();
+ while (condition) {
+ int a = 2;
+ while (otherCondition) {
+ a = 3;
+ }
+ staticField = a;
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ try {
+ test();
+ throw new Exception("Unexpected exception");
+ } catch (Error e) {
+ // Expected.
+ }
+ }
+
+ static boolean condition = false;
+ static boolean otherCondition = false;
+ static int staticField = 1;
+}