package org.graalvm.compiler.replacements.test;
import org.junit.Assert;
import org.junit.Test;
import org.graalvm.compiler.core.common.type.IntegerStamp;
import org.graalvm.compiler.core.common.type.StampFactory;
public class IntegerSubOverflowsTest {
@Test
public void testOverflowCheck() {
long a = Integer.MIN_VALUE;
long b = -1;
Assert.assertFalse(IntegerStamp.subtractionOverflows(a, b, 32));
}
@Test
public void testOverflowCheck01() {
long a = Integer.MAX_VALUE;
long b = Integer.MAX_VALUE;
Assert.assertFalse(IntegerStamp.subtractionOverflows(a, b, 32));
}
@Test
public void testOverflowCheck02() {
long a = Integer.MIN_VALUE;
long b = Integer.MIN_VALUE;
Assert.assertFalse(IntegerStamp.subtractionOverflows(a, b, 32));
}
@Test
public void testOverflowCheck03() {
long a = Integer.MIN_VALUE;
long b = 1;
Assert.assertTrue(IntegerStamp.subtractionOverflows(a, b, 32));
}
@Test
public void testOverflowCheck04() {
long a = Integer.MAX_VALUE;
long b = 1;
Assert.assertFalse(IntegerStamp.subtractionOverflows(a, b, 32));
}
@Test
public void testOverflowCheck05() {
long a = Integer.MAX_VALUE;
long b = Integer.MIN_VALUE;
Assert.assertTrue(IntegerStamp.subtractionOverflows(a, b, 32));
}
@Test
public void testOverflowCheck06() {
long a = Integer.MAX_VALUE;
long b = Integer.MAX_VALUE;
Assert.assertFalse(IntegerStamp.subtractionOverflows(a, b, 64));
}
@Test
public void testOverflowCheck07() {
long a = Long.MAX_VALUE;
long b = 2;
Assert.assertFalse(IntegerStamp.subtractionOverflows(a, b, 64));
}
@Test
public void testOverflowCheck08() {
long a = Long.MAX_VALUE;
long b = Long.MAX_VALUE;
Assert.assertFalse(IntegerStamp.subtractionOverflows(a, b, 64));
}
@Test
public void testOverflowCheck09() {
long a = -Long.MAX_VALUE;
long b = Long.MAX_VALUE;
Assert.assertTrue(IntegerStamp.subtractionOverflows(a, b, 64));
}
@Test
public void testOverflowCheck10() {
long a = -Long.MAX_VALUE;
long b = -Long.MAX_VALUE;
Assert.assertFalse(IntegerStamp.subtractionOverflows(a, b, 64));
}
@Test
public void testOverflowCheck11() {
long a = Long.MAX_VALUE;
long b = -Long.MAX_VALUE;
Assert.assertTrue(IntegerStamp.subtractionOverflows(a, b, 64));
}
@Test
public void testOverflowCheckStamp() {
IntegerStamp s1 = StampFactory.forInteger(32, Integer.MIN_VALUE, Integer.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(32, -1, -1);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp01() {
IntegerStamp s1 = StampFactory.forInteger(32, Integer.MAX_VALUE, Integer.MAX_VALUE);
IntegerStamp s2 = StampFactory.forInteger(32, Integer.MAX_VALUE, Integer.MAX_VALUE);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp02() {
IntegerStamp s1 = StampFactory.forInteger(32, Integer.MIN_VALUE, Integer.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(32, Integer.MIN_VALUE, Integer.MIN_VALUE);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp03() {
IntegerStamp s1 = StampFactory.forInteger(32, Integer.MIN_VALUE, Integer.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(32, 1, 1);
Assert.assertTrue(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp04() {
IntegerStamp s1 = StampFactory.forInteger(8, Byte.MIN_VALUE, Byte.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(8, -1, -1);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp05() {
IntegerStamp s1 = StampFactory.forInteger(8, Byte.MAX_VALUE, Byte.MAX_VALUE);
IntegerStamp s2 = StampFactory.forInteger(8, Byte.MAX_VALUE, Byte.MAX_VALUE);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp06() {
IntegerStamp s1 = StampFactory.forInteger(8, Byte.MIN_VALUE, Byte.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(8, Byte.MIN_VALUE, Byte.MIN_VALUE);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp07() {
IntegerStamp s1 = StampFactory.forInteger(8, Byte.MIN_VALUE, Byte.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(8, 1, 1);
Assert.assertTrue(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp08() {
IntegerStamp s1 = StampFactory.forInteger(64, Long.MIN_VALUE, Long.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(64, -1, -1);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp09() {
IntegerStamp s1 = StampFactory.forInteger(64, Long.MAX_VALUE, Long.MAX_VALUE);
IntegerStamp s2 = StampFactory.forInteger(64, Long.MAX_VALUE, Long.MAX_VALUE);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp10() {
IntegerStamp s1 = StampFactory.forInteger(64, Long.MIN_VALUE, Long.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(64, Long.MIN_VALUE, Long.MIN_VALUE);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowCheckStamp11() {
IntegerStamp s1 = StampFactory.forInteger(64, Long.MIN_VALUE, Long.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(64, 1, 1);
Assert.assertTrue(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowBIgStamps01() {
IntegerStamp s1 = StampFactory.forInteger(64, Long.MIN_VALUE, Long.MAX_VALUE);
IntegerStamp s2 = StampFactory.forInteger(64, Long.MIN_VALUE, Long.MAX_VALUE);
Assert.assertTrue(IntegerStamp.subtractionCanOverflow(s1, s2));
}
@Test
public void testOverflowBIgStamps02() {
IntegerStamp s1 = StampFactory.forInteger(64, Long.MIN_VALUE, Long.MAX_VALUE);
IntegerStamp s2 = StampFactory.forInteger(64, Long.MIN_VALUE, Long.MIN_VALUE);
Assert.assertTrue(IntegerStamp.subtractionCanOverflow(s1, s2));
}
}