Fix invalid removal in redundant bridge remover
Bug: b/439776596
Change-Id: I3219df733aca087820fc8864361579d6afa04f5a
diff --git a/src/main/java/com/android/tools/r8/optimize/redundantbridgeremoval/RedundantBridgeRemover.java b/src/main/java/com/android/tools/r8/optimize/redundantbridgeremoval/RedundantBridgeRemover.java
index 67a1e76..5c52657 100644
--- a/src/main/java/com/android/tools/r8/optimize/redundantbridgeremoval/RedundantBridgeRemover.java
+++ b/src/main/java/com/android/tools/r8/optimize/redundantbridgeremoval/RedundantBridgeRemover.java
@@ -288,7 +288,8 @@
extends DepthFirstTopDownClassHierarchyTraversal {
private final ProgramMethodSet removedBridges = ProgramMethodSet.create();
- private ProgramMethodSet superTargets = null;
+ private ProgramMethodSet superTargets = ProgramMethodSet.create();
+ private WorkList<DexProgramClass> superTargetsWorklist = WorkList.newIdentityWorkList();
RedundantBridgeRemoverClassHierarchyTraversal() {
super(
@@ -397,14 +398,12 @@
}
private ProgramMethodSet getOrCreateSuperTargets(DexProgramClass root) {
- if (superTargets != null) {
+ if (!superTargetsWorklist.addIfNotSeen(root)) {
return superTargets;
}
AppView<? extends AppInfoWithClassHierarchy> appViewWithClassHierarchy = appView;
- superTargets = ProgramMethodSet.create();
- WorkList<DexProgramClass> worklist = WorkList.newIdentityWorkList(root);
- while (worklist.hasNext()) {
- DexProgramClass clazz = worklist.next();
+ while (superTargetsWorklist.hasNext()) {
+ DexProgramClass clazz = superTargetsWorklist.next();
clazz.forEachProgramMethodMatching(
DexEncodedMethod::hasCode,
method ->
@@ -424,7 +423,7 @@
}
}
}));
- worklist.addIfNotSeen(immediateSubtypingInfo.getSubclasses(clazz));
+ superTargetsWorklist.addIfNotSeen(immediateSubtypingInfo.getSubclasses(clazz));
}
return superTargets;
}
diff --git a/src/test/java/com/android/tools/r8/bridgeremoval/RedundantInterfaceBridgeMethodRemovalTest.java b/src/test/java/com/android/tools/r8/bridgeremoval/RedundantInterfaceBridgeMethodRemovalTest.java
index 2727764..ccd2f46 100644
--- a/src/test/java/com/android/tools/r8/bridgeremoval/RedundantInterfaceBridgeMethodRemovalTest.java
+++ b/src/test/java/com/android/tools/r8/bridgeremoval/RedundantInterfaceBridgeMethodRemovalTest.java
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.bridgeremoval;
+
import static com.android.tools.r8.utils.codeinspector.AssertUtils.assertFailsCompilationIf;
import com.android.tools.r8.NeverClassInline;
@@ -43,7 +44,6 @@
@Test
public void testR8() throws Exception {
- // TODO(b/439776596): Should succeed.
assertFailsCompilationIf(
parameters.isCfRuntime(),
() ->
@@ -51,9 +51,8 @@
.apply(this::configure)
.addKeepMainRule(Main.class)
.addVerticallyMergedClassesInspector(
- inspector -> {
- inspector.assertMergedIntoSubtype(LSub.class).assertNoOtherClassesMerged();
- })
+ inspector ->
+ inspector.assertMergedIntoSubtype(LSub.class).assertNoOtherClassesMerged())
.enableInliningAnnotations()
.enableNeverClassInliningAnnotations()
.enableNoHorizontalClassMergingAnnotations()