Java: Add another overflow check pattern to UselessComparisonTest.

This commit is contained in:
Anders Schack-Mulligen
2019-10-04 14:28:46 +02:00
parent 48dee29620
commit 066a2f0d12
2 changed files with 39 additions and 12 deletions

View File

@@ -121,6 +121,26 @@ public class A {
}
}
static final long VAL = 100L;
long overflowAwareIncrease(long x) {
if (x + VAL > x) {
return x + VAL;
} else {
overflow();
return Long.MAX_VALUE;
}
}
long overflowAwareDecrease(long x) {
if (x - VAL < x) {
return x - VAL;
} else {
overflow();
return Long.MIN_VALUE;
}
}
void overflow() { }
void unreachableCode() {