Add test for unrepresentable rewriting on guava
Bug: b/238175192
Change-Id: I2f1c31f39faaa5faf4d47c178e308d254c87b8f7
diff --git a/src/main/java/com/android/tools/r8/cf/code/CfStackInstruction.java b/src/main/java/com/android/tools/r8/cf/code/CfStackInstruction.java
index 2640c16..2746906 100644
--- a/src/main/java/com/android/tools/r8/cf/code/CfStackInstruction.java
+++ b/src/main/java/com/android/tools/r8/cf/code/CfStackInstruction.java
@@ -134,7 +134,7 @@
case Pop:
{
Slot pop = state.pop();
- assert !pop.type.isWide();
+ assert !pop.type.isWide() : "Expected stack type to be single width";
break;
}
case Pop2:
diff --git a/src/test/java/com/android/tools/r8/code/invokedynamic/CompileGuavaWithUnrepresentableRewritingTest.java b/src/test/java/com/android/tools/r8/code/invokedynamic/CompileGuavaWithUnrepresentableRewritingTest.java
new file mode 100644
index 0000000..c747eff
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/code/invokedynamic/CompileGuavaWithUnrepresentableRewritingTest.java
@@ -0,0 +1,57 @@
+// Copyright (c) 2022, 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.code.invokedynamic;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assume.assumeTrue;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.ToolHelper;
+import com.android.tools.r8.utils.AndroidApiLevel;
+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 regression test for b/238175192 */
+@RunWith(Parameterized.class)
+public class CompileGuavaWithUnrepresentableRewritingTest extends TestBase {
+
+ @Parameter() public TestParameters parameters;
+
+ @Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withNoneRuntime().build();
+ }
+
+ @Test
+ public void testD8DexNoDesugaring() throws Throwable {
+ assumeTrue(ToolHelper.isTestingR8Lib());
+ // TODO(b/238175192): We should not generate invalid bytecode
+ assertThrows(
+ CompilationFailedException.class,
+ () -> {
+ testForD8(Backend.DEX)
+ // DEPS contains all R8 dependencies, including guava, which extends the surface
+ // of UnrepresentableRewriting.
+ .addProgramFiles(ToolHelper.DEPS)
+ .setMinApi(AndroidApiLevel.B)
+ .disableDesugaring()
+ .mapUnsupportedFeaturesToWarnings()
+ .compileWithExpectedDiagnostics(
+ diagnostics ->
+ diagnostics
+ .assertErrorMessageThatMatches(
+ containsString("Expected stack type to be single width"))
+ .assertWarningMessageThatMatches(
+ containsString("Invalid stack map table at instruction")));
+ });
+ }
+}