Debian Codegraph @

framework/tests/value-ignore-range-overflow/ValueNoOverflow.java

raw
1 import org.checkerframework.common.value.qual.*;
2
3 class ValueNoOverflow {
4
5 // This file contains a series of simple smoke tests for IntRange and ArrayLenRange with no
6 // overflow.
7
8 void test_plus(@IntRange(from = 0) int x, @IntRange(from = -1) int z) {
9 @IntRange(from = 1) int y = x + 1; // IntRange(from = 0) to IntRange(from = 1)
10 @IntRange(from = 0) int w = z + 1; // GTEN1 to NN
11 }
12
13 void test_minus(@IntRange(to = 0) int x, @IntRange(to = 1) int z) {
14 @IntRange(to = -1) int y = x - 1; // IntRange(from = 0) to GTEN1
15 @IntRange(to = 0) int w = z - 1; // Pos to NN
16 }
17
18 void test_mult(@IntRange(from = 0) int x, @IntRange(from = 1) int z) {
19 @IntRange(from = 0) int y = x * z;
20 @IntRange(from = 1) int w = z * z;
21 }
22
23 void testLong_plus(@IntRange(from = 0) long x, @IntRange(from = -1) long z) {
24 @IntRange(from = 1) long y = x + 1; // IntRange(from = 0) to IntRange(from = 1)
25 @IntRange(from = 0) long w = z + 1; // GTEN1 to NN
26 }
27
28 void testLong_minus(@IntRange(to = 0) long x, @IntRange(to = 1) long z) {
29 @IntRange(to = -1) long y = x - 1; // IntRange(from = 0) to GTEN1
30 @IntRange(to = 0) long w = z - 1; // Pos to NN
31 }
32
33 void testLong_mult(@IntRange(from = 0) long x, @IntRange(from = 1) long z) {
34 @IntRange(from = 0) long y = x * z;
35 @IntRange(from = 1) long w = z * z;
36 }
37
38 void testShort_plus(@IntRange(from = 0) short x, @IntRange(from = -1) short z) {
39 @IntRange(from = 1) short y = (short) (x + 1); // IntRange(from = 0) to IntRange(from = 1)
40 @IntRange(from = 0) short w = (short) (z + 1); // GTEN1 to NN
41 }
42
43 void testShort_minus(@IntRange(to = 0) short x, @IntRange(to = 1) short z) {
44 @IntRange(to = -1) short y = (short) (x - 1); // IntRange(from = 0) to GTEN1
45 @IntRange(to = 0) short w = (short) (z - 1); // Pos to NN
46 }
47
48 void testShort_mult(@IntRange(from = 0) short x, @IntRange(from = 1) short z) {
49 @IntRange(from = 0) short y = (short) (x * z);
50 @IntRange(from = 1) short w = (short) (z * z);
51 }
52
53 void testChar_plus(@IntRange(from = 0) char x) {
54 @IntRange(from = 1) char y = (char) (x + 1); // IntRange(from = 0) to IntRange(from = 1)
55 }
56
57 void testChar_minus(@IntRange(to = 65534) char z) {
58 @IntRange(to = 65533) char w = (char) (z - 1); // IntRange(to = 65535) to IntRange(to = 65535)
59 }
60
61 void testChar_mult(@IntRange(from = 0) char x, @IntRange(from = 1) char z) {
62 @IntRange(from = 0) char y = (char) (x * z);
63 @IntRange(from = 1) char w = (char) (z * z);
64 }
65
66 void testByte_plus(@IntRange(from = 0) byte x, @IntRange(from = -1) byte z) {
67 @IntRange(from = 1) byte y = (byte) (x + 1); // IntRange(from = 0) to IntRange(from = 1)
68 @IntRange(from = 0) byte w = (byte) (z + 1); // GTEN1 to NN
69 }
70
71 void testByte_minus(@IntRange(to = 0) byte x, @IntRange(to = 1) byte z) {
72 @IntRange(to = -1) byte y = (byte) (x - 1); // IntRange(from = 0) to GTEN1
73 @IntRange(to = 0) byte w = (byte) (z - 1); // Pos to NN
74 }
75
76 void testByte_mult(@IntRange(from = 0) byte x, @IntRange(from = 1) byte z) {
77 @IntRange(from = 0) byte y = (byte) (x * z);
78 @IntRange(from = 1) byte w = (byte) (z * z);
79 }
80
81 void test_casting(@IntRange(from = 0) int i) {
82 @IntRange(from = 1, to = ((long) Integer.MAX_VALUE) + 1)
83 long x = i + 1;
84 }
85
86 // Include ArrayLenRange tests once ArrayLenRange is merged.
87
88 void arraylenrange_test(int @ArrayLenRange(from = 5) [] a) {
89 int @ArrayLenRange(from = 7) [] b = new int[a.length + 2];
90 }
91
92 void arraylenrange_test2(int @ArrayLenRange(to = 5) [] a) {
93 int @ArrayLenRange(from = 0, to = 0) [] b = new int[a.length - 5];
94 }
95 }