Fix error when exception value is used directly in invoke/range
Bug: b/438933684
Change-Id: Id4cd527410793f8a8013525206a25d96c09c4097
diff --git a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
index 6803b23..e088250 100644
--- a/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
+++ b/src/main/java/com/android/tools/r8/ir/regalloc/LinearScanRegisterAllocator.java
@@ -1252,8 +1252,13 @@
MoveException moveException = block.entry().asMoveException();
LiveIntervals intervals = moveException.outValue().getLiveIntervals();
if (intervals.getValue().hasAnyUsers()) {
- LiveIntervals split = intervals.splitAfter(intervals.getValue().getDefinition(), mode);
- unhandled.add(split);
+ // Split the live intervals immediately after the move-exception instruction. Check if the
+ // live intervals has already been split at this point due to an invoke/range instruction.
+ if (intervals.getSplitCovering(moveException).getEnd()
+ != toGapPosition(moveException.getNext().getNumber())) {
+ LiveIntervals split = intervals.splitAfter(intervals.getValue().getDefinition(), mode);
+ unhandled.add(split);
+ }
}
if (intervals.getStart() < moveException.getNumber()) {
intervals = intervals.splitBefore(moveException, mode);
diff --git a/src/test/java/com/android/tools/r8/ir/regalloc/MoveExceptionInvokeRangeTest.java b/src/test/java/com/android/tools/r8/ir/regalloc/MoveExceptionInvokeRangeTest.java
index b3a6077..fbc0a2e 100644
--- a/src/test/java/com/android/tools/r8/ir/regalloc/MoveExceptionInvokeRangeTest.java
+++ b/src/test/java/com/android/tools/r8/ir/regalloc/MoveExceptionInvokeRangeTest.java
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.ir.regalloc;
-import static com.android.tools.r8.utils.codeinspector.AssertUtils.assertFailsCompilation;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
@@ -28,13 +27,13 @@
@Test
public void test() throws Exception {
parameters.assumeDexRuntime();
- assertFailsCompilation(
- () ->
- testForD8(parameters)
- .addInnerClasses(getClass())
- .release()
- .setMinApi(parameters)
- .compile());
+ testForD8(parameters)
+ .addInnerClasses(getClass())
+ .release()
+ .setMinApi(parameters)
+ .compile()
+ .run(parameters.getRuntime(), Main.class, "a", "b", "c", "d", "e")
+ .assertSuccessWithEmptyOutput();
}
static class Main {