Version 1.6.58

Cherry-pick: Reproduce bug in unused argument removal
CL: https://r8-review.googlesource.com/c/r8/+/45174

Cherry-pick: Consider all implemented interfaces when removing unused arguments
CL: https://r8-review.googlesource.com/c/r8/+/45433

Bug: 143934502
Change-Id: Idedd89eedc60033527a554310dccd83197f4aaeb
diff --git a/src/main/java/com/android/tools/r8/Version.java b/src/main/java/com/android/tools/r8/Version.java
index 34e9cba..8bf104c 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 = "1.6.57";
+  public static final String LABEL = "1.6.58";
 
   private Version() {
   }
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/MemberPoolCollection.java b/src/main/java/com/android/tools/r8/ir/optimize/MemberPoolCollection.java
index 3b1284d..8b74c30 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/MemberPoolCollection.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/MemberPoolCollection.java
@@ -222,7 +222,9 @@
     }
 
     private boolean hasSeenBelow(Wrapper<T> member, boolean inclusive) {
-      if (inclusive && hasSeenDirectly(member)) {
+      if (inclusive
+          && (hasSeenDirectly(member)
+              || interfaces.stream().anyMatch(itf -> itf.hasSeenAbove(member, true)))) {
         return true;
       }
       return subTypes.stream().anyMatch(subType -> subType.hasSeenBelow(member, true));
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/unusedarguments/UnusedArgumentsInMethodThatImplementsInterfaceMethodOnSubTest.java b/src/test/java/com/android/tools/r8/ir/optimize/unusedarguments/UnusedArgumentsInMethodThatImplementsInterfaceMethodOnSubTest.java
new file mode 100644
index 0000000..9001472
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/unusedarguments/UnusedArgumentsInMethodThatImplementsInterfaceMethodOnSubTest.java
@@ -0,0 +1,74 @@
+// Copyright (c) 2019, 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.unusedarguments;
+
+import com.android.tools.r8.NeverMerge;
+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;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class UnusedArgumentsInMethodThatImplementsInterfaceMethodOnSubTest extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimesAndApiLevels().build();
+  }
+
+  public UnusedArgumentsInMethodThatImplementsInterfaceMethodOnSubTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void test() throws Exception {
+    testForR8(parameters.getBackend())
+        .addInnerClasses(UnusedArgumentsInMethodThatImplementsInterfaceMethodOnSubTest.class)
+        .addKeepMainRule(TestClass.class)
+        .enableMergeAnnotations()
+        .setMinApi(parameters.getApiLevel())
+        .run(parameters.getRuntime(), TestClass.class)
+        .assertSuccessWithOutputLines("Hello from A", "Hello from C");
+  }
+
+  static class TestClass {
+
+    public static void main(String[] args) {
+      for (I o : new I[] {new B(), new C()}) {
+        o.method(new Object());
+      }
+    }
+  }
+
+  interface I {
+
+    void method(Object o);
+  }
+
+  @NeverMerge
+  static class A {
+
+    public void method(Object unused) {
+      System.out.println("Hello from A");
+    }
+  }
+
+  static class B extends A implements I {}
+
+  static class C implements I {
+
+    @Override
+    public void method(Object o) {
+      if (o != null) {
+        System.out.println("Hello from C");
+      }
+    }
+  }
+}