Add reproduction of issue 342067836
Bug: b/342067836
Change-Id: I1a36086a0e3b2abd3d11d73736fd97a0f79af778
diff --git a/src/test/java/com/android/tools/r8/regress/B342067836Test.java b/src/test/java/com/android/tools/r8/regress/B342067836Test.java
new file mode 100644
index 0000000..703abc2
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/regress/B342067836Test.java
@@ -0,0 +1,96 @@
+// Copyright (c) 2024, 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.regress;
+
+import static org.junit.Assume.assumeTrue;
+
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.google.common.collect.ImmutableList;
+import java.util.List;
+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;
+
+@RunWith(Parameterized.class)
+public class B342067836Test extends TestBase {
+
+ @Parameter(0)
+ public TestParameters parameters;
+
+ @Parameters(name = "{0}")
+ public static TestParametersCollection data() {
+ return getTestParameters().withAllRuntimesAndApiLevels().build();
+ }
+
+ private static final List<String> EXPECTED_OUTPUT = ImmutableList.of("50");
+ private static final List<String> NOT_EXPECTED_OUTPUT = ImmutableList.of("864691135031803904");
+
+ @Test
+ public void testJvm() throws Exception {
+ assumeTrue(parameters.isJvmTestParameters());
+ testForJvm(parameters)
+ .addInnerClasses(getClass())
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutputLines(EXPECTED_OUTPUT);
+ }
+
+ @Test
+ public void testD8() throws Exception {
+ assumeTrue(parameters.isDexRuntime());
+ testForD8(parameters.getBackend())
+ .addInnerClasses(getClass())
+ .setMinApi(parameters)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutputLines(EXPECTED_OUTPUT);
+ }
+
+ @Test
+ public void testR8() throws Exception {
+ testForR8(parameters.getBackend())
+ .addInnerClasses(getClass())
+ .addKeepMainRule(TestClass.class)
+ .setMinApi(parameters)
+ .run(parameters.getRuntime(), TestClass.class)
+ .assertSuccessWithOutputLines(NOT_EXPECTED_OUTPUT);
+ }
+
+ static class TestClass {
+
+ long a;
+ long b;
+
+ void c() {
+ double d;
+ int i6 = 1;
+ d = a += i6;
+ a <<= -10;
+ a <<= 37;
+ b += d;
+ }
+
+ void e(float g) {
+ c();
+ }
+
+ void h(float f, int i, int j) {
+ e(f);
+ }
+
+ void k(String[] l) {
+ for (int n = 0; n < 50; n++) {
+ h(6, 7, 4);
+ }
+ System.out.println(b);
+ }
+
+ public static void main(String[] o) {
+ TestClass _instance = new TestClass();
+ _instance.k(o);
+ }
+ }
+}