Add test for inlining 'dead' method with addconfigurationdebugging
Bug: b/298965633
Change-Id: Iecb9e939e510bedd414c8575b9d3c80e81febc44
diff --git a/src/test/java/com/android/tools/r8/shaking/addconfigurationdebugging/ConfigurationDebuggingWithInliningTest.java b/src/test/java/com/android/tools/r8/shaking/addconfigurationdebugging/ConfigurationDebuggingWithInliningTest.java
new file mode 100644
index 0000000..6256a35
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/shaking/addconfigurationdebugging/ConfigurationDebuggingWithInliningTest.java
@@ -0,0 +1,81 @@
+// Copyright (c) 2023, 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.shaking.addconfigurationdebugging;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThrows;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.NeverInline;
+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.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+/** This is a reproduction of b/298965633. */
+@RunWith(Parameterized.class)
+public class ConfigurationDebuggingWithInliningTest extends TestBase {
+
+ @Parameter() public TestParameters parameters;
+
+ @Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ @Test
+ public void testForR8() throws Exception {
+ assertThrows(
+ CompilationFailedException.class,
+ () ->
+ testForR8(parameters.getBackend())
+ .addProgramClasses(Main.class, Bar.class)
+ .addKeepRules("-addconfigurationdebugging")
+ .addKeepMainRule(Main.class)
+ .setMinApi(parameters)
+ .enableInliningAnnotations()
+ // TODO(b/298965633): We should not fail.
+ .compileWithExpectedDiagnostics(
+ diagnostics ->
+ diagnostics.assertErrorMessageThatMatches(
+ containsString("Cannot compute relationship for not set"))));
+ }
+
+ public static class Main {
+
+ public static void main(String[] args) throws Exception {
+ System.out.println("Hello World");
+ callM();
+ }
+
+ private static String getObjectName() {
+ return new StringBuilder()
+ .append("com.android.tools.r8.shaking.addconfigurationdebugging")
+ .append(".ConfigurationDebuggingWithInliningTest$Bar")
+ .toString();
+ }
+
+ @NeverInline
+ private static void callM() {
+ try {
+ Bar bar = (Bar) Class.forName(getObjectName()).newInstance();
+ bar.print();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ public static class Bar {
+
+ public void print() {
+ System.out.println("Initialized");
+ }
+ }
+}