src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java Tue Dec 18 10:12:28 2018 +0100
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java Tue Jan 15 10:40:32 2019 -0800
@@ -86,6 +86,46 @@
}
}
+ public void testIntegerExactOverflowWithoutUse1(int input) {
+ Math.addExact(intCounter, input);
+ }
+
+ public void testIntegerExactOverflowWithoutUse2(int input, boolean cond) {
+ if (cond) {
+ Math.addExact(intCounter, input);
+ } else {
+ intCounter = Math.addExact(intCounter, input);
+ }
+ }
+
+ @Test
+ public void testIntegerExactWithoutUse1() throws InvalidInstalledCodeException {
+ ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse1");
+ InstalledCode code = getCode(method);
+
+ boolean gotException = false;
+ try {
+ code.executeVarargs(this, Integer.MAX_VALUE);
+ } catch (ArithmeticException e) {
+ gotException = true;
+ }
+ assertTrue(gotException);
+ }
+
+ @Test
+ public void testIntegerExactWithoutUse2() throws InvalidInstalledCodeException {
+ ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse2");
+ InstalledCode code = getCode(method);
+
+ boolean gotException = false;
+ try {
+ code.executeVarargs(this, Integer.MAX_VALUE, true);
+ } catch (ArithmeticException e) {
+ gotException = true;
+ }
+ assertTrue(gotException);
+ }
+
static long longCounter = 10;
public void testLongExactOverflowSnippet(long input) {
@@ -138,4 +178,44 @@
assertTrue(code.isValid());
}
}
+
+ public void testLongExactOverflowWithoutUse1(long input) {
+ Math.addExact(longCounter, input);
+ }
+
+ public void testLongExactOverflowWithoutUse2(long input, boolean cond) {
+ if (cond) {
+ Math.addExact(longCounter, input);
+ } else {
+ longCounter = Math.addExact(longCounter, input);
+ }
+ }
+
+ @Test
+ public void testLongExactWithoutUse1() throws InvalidInstalledCodeException {
+ ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowWithoutUse1");
+ InstalledCode code = getCode(method);
+
+ boolean gotException = false;
+ try {
+ code.executeVarargs(this, Long.MAX_VALUE);
+ } catch (ArithmeticException e) {
+ gotException = true;
+ }
+ assertTrue(gotException);
+ }
+
+ @Test
+ public void testLongExactWithoutUse2() throws InvalidInstalledCodeException {
+ ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowWithoutUse2");
+ InstalledCode code = getCode(method);
+
+ boolean gotException = false;
+ try {
+ code.executeVarargs(this, Long.MAX_VALUE, true);
+ } catch (ArithmeticException e) {
+ gotException = true;
+ }
+ assertTrue(gotException);
+ }
}