Version 2.0.37
Cherry pick: Adjust the fallthrough block index after switch case elimination
CL: https://r8-review.googlesource.com/c/r8/+/49029
Cherry pick: Never class inline singleton instances with instance-put users
CL: https://r8-review.googlesource.com/c/r8/+/49051
Bug: 149468959
Change-Id: If0432d4ea0ff31d5867f256203aa68ddd253a4ee
diff --git a/src/main/java/com/android/tools/r8/Version.java b/src/main/java/com/android/tools/r8/Version.java
index 72b9c00..e3ab84c 100644
--- a/src/main/java/com/android/tools/r8/Version.java
+++ b/src/main/java/com/android/tools/r8/Version.java
@@ -11,7 +11,7 @@
// This field is accessed from release scripts using simple pattern matching.
// Therefore, changing this field could break our release scripts.
- public static final String LABEL = "2.0.36";
+ public static final String LABEL = "2.0.37";
private Version() {
}
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/SwitchCaseEliminator.java b/src/main/java/com/android/tools/r8/ir/optimize/SwitchCaseEliminator.java
index 8799529..0aabe6e 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/SwitchCaseEliminator.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/SwitchCaseEliminator.java
@@ -135,13 +135,12 @@
}
}
- assert targetBlockIndexOffset[theSwitch.getFallthroughBlockIndex()] == 0;
-
iterator.replaceCurrentInstruction(
new IntSwitch(
theSwitch.value(),
newKeys,
newTargetBlockIndices,
- theSwitch.getFallthroughBlockIndex()));
+ theSwitch.getFallthroughBlockIndex()
+ - targetBlockIndexOffset[theSwitch.getFallthroughBlockIndex()]));
}
}
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/classinliner/InlineCandidateProcessor.java b/src/main/java/com/android/tools/r8/ir/optimize/classinliner/InlineCandidateProcessor.java
index f78ba2c..3e5280d 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/classinliner/InlineCandidateProcessor.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/classinliner/InlineCandidateProcessor.java
@@ -321,6 +321,10 @@
}
if (user.isInstancePut()) {
+ if (root.isStaticGet()) {
+ // We can't remove instructions that mutate the singleton instance.
+ return user; // Not eligible.
+ }
if (!receivers.addIllegalReceiverAlias(user.asInstancePut().value())) {
return user; // Not eligible.
}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/membervaluepropagation/B149468959.java b/src/test/java/com/android/tools/r8/ir/optimize/membervaluepropagation/B149468959.java
new file mode 100644
index 0000000..dff369b
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/membervaluepropagation/B149468959.java
@@ -0,0 +1,61 @@
+// Copyright (c) 2020, 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.ir.optimize.membervaluepropagation;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class B149468959 extends TestBase {
+
+ private final TestParameters parameters;
+
+ @Parameterized.Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ public B149468959(TestParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ @Test
+ public void test() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(B149468959.class)
+ .addKeepMainRule(TestClass.class)
+ .setMinApi(parameters.getApiLevel())
+ .compile()
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutputLines("A");
+ }
+
+ static class TestClass {
+
+ public static void main(String[] args) {
+ mutate();
+ for (MyEnum x : MyEnum.values()) {
+ if (x.include) {
+ System.out.println(x);
+ }
+ }
+ }
+
+ static void mutate() {
+ MyEnum.B.include = false;
+ }
+ }
+
+ enum MyEnum {
+ A,
+ B;
+
+ boolean include = true;
+ }
+}