Add minimal reproduction of R8 generated code not throwing exception

Bug: 371247958
Change-Id: I110fb4cad4634aa93e5e5f489ef213716b444eaa
diff --git a/src/test/java/com/android/tools/r8/regress/Regress371247958.java b/src/test/java/com/android/tools/r8/regress/Regress371247958.java
new file mode 100644
index 0000000..96fc07d
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/regress/Regress371247958.java
@@ -0,0 +1,61 @@
+// 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 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;
+
+@RunWith(Parameterized.class)
+public class Regress371247958 extends TestBase {
+
+  private final TestParameters parameters;
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withDefaultRuntimes().withAllApiLevels().build();
+  }
+
+  public Regress371247958(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  public void testR8() throws Exception {
+    testForR8(parameters.getBackend())
+        .addProgramClasses(TestClass.class)
+        .addKeepMainRule(TestClass.class)
+        .setMinApi(parameters)
+        .compile()
+        .run(parameters.getRuntime(), TestClass.class)
+        // TODO(b/371247958): Should throw a RuntimeException
+        .assertSuccess();
+  }
+
+  @Test
+  public void testD8() throws Exception {
+    testForD8(parameters.getBackend())
+        .addProgramClasses(TestClass.class)
+        .applyIf(parameters.isDexRuntime(), b -> b.setMinApi(parameters))
+        .compile()
+        .run(parameters.getRuntime(), TestClass.class)
+        .assertFailureWithErrorThatThrows(RuntimeException.class);
+  }
+
+  public static class TestClass {
+    static int throwException(RuntimeException runtimeException, boolean shouldReturnValue) {
+      if (shouldReturnValue) {
+        return 1;
+      }
+      throw runtimeException;
+    }
+
+    public static void main(String[] p) throws Exception {
+      throwException(new RuntimeException("always thrown"), false);
+    }
+  }
+}