Don't merge block suffixes if catch handlers are different.
PeepholeOptimizer::shareIdenticalBlockSuffix() should only merge
identical basic block suffixes if the blocks have same catch handlers.
BUG=
Change-Id: I8be4c521ce57dc26dceae56ab1f0db4dc0998148
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/InstructionEquivalence.java b/src/main/java/com/android/tools/r8/ir/optimize/InstructionEquivalence.java
index f9c0b30..2f2523d 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/InstructionEquivalence.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/InstructionEquivalence.java
@@ -17,7 +17,8 @@
@Override
protected boolean doEquivalent(Instruction a, Instruction b) {
- return a.identicalAfterRegisterAllocation(b, allocator);
+ return a.identicalAfterRegisterAllocation(b, allocator)
+ && a.getBlock().getCatchHandlers().equals(b.getBlock().getCatchHandlers());
}
@Override
@@ -32,6 +33,7 @@
hash += allocator.getRegisterForValue(inValue, instruction.getNumber());
}
}
+ hash = hash * 37 + instruction.getBlock().getCatchHandlers().hashCode();
return hash;
}
}
diff --git a/src/test/examples/nestedtrycatches/NestedTryCatches.java b/src/test/examples/nestedtrycatches/NestedTryCatches.java
new file mode 100644
index 0000000..00bec2a
--- /dev/null
+++ b/src/test/examples/nestedtrycatches/NestedTryCatches.java
@@ -0,0 +1,38 @@
+// 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 nestedtrycatches;
+
+public class NestedTryCatches {
+ private static void throwException() {
+ throw new RuntimeException("IGNORED");
+ }
+
+ private static void test() throws Throwable {
+ RuntimeException _primaryExc = null;
+ try {
+ throw new RuntimeException("PRIMARY");
+ } catch (RuntimeException _t) {
+ _primaryExc = _t;
+ throw _t;
+ } finally {
+ // Keep the two calls to throwException() the same line
+ if(_primaryExc!=null) {
+ try {
+ throwException();
+ } catch(Throwable _suppressed) {
+ }
+ } else {
+ throwException();
+ }
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ try {
+ test();
+ } catch (Throwable e) {
+ System.out.println("EXCEPTION: " + e.getMessage());
+ }
+ }
+}
diff --git a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
index 628036c..9e7588d 100644
--- a/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
+++ b/src/test/java/com/android/tools/r8/R8RunExamplesTest.java
@@ -86,6 +86,7 @@
{"throwing.Throwing", "Throwing"},
{"trivial.Trivial", null},
{"trycatch.TryCatch", "Success!"},
+ {"nestedtrycatches.NestedTryCatches", "EXCEPTION: PRIMARY"},
{"trycatchmany.TryCatchMany", "Success!"},
{"invokeempty.InvokeEmpty", "AB"},
{"regress.Regress", null},