File: OscillatingLoops.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (66 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import org.checkerframework.common.value.qual.IntRange;
import org.checkerframework.common.value.qual.IntVal;

// Because the analysis of loops isn't precise enough, the Value Checker issues
// warnings on this test case. So, suppress those warnings, but run the tests
// to make sure that dataflow reaches a fixed point.
@SuppressWarnings("value")
public class OscillatingLoops {

    void oscillatesDoWhile() {
        int i = 0;
        int d = 0;
        do {
            i++;
            if (d > 4566) {
                d = 0;
            } else {
                d++;
            }
        } while (i < Integer.MAX_VALUE);
        @IntRange(from = 0, to = 4567) int after = d;
        @IntVal(Integer.MAX_VALUE) int afterI = i;
    }

    void oscillatesWhile() {
        int i = 0;
        int d = 1;
        while (i < Integer.MAX_VALUE) {
            i++;
            if (d > 4566) {
                d = 0;
            } else {
                d++;
            }
        }
        @IntRange(from = 0, to = 4567) int after = d;
        @IntVal(Integer.MAX_VALUE) int afterI = i;
    }

    void oscillatesDoWhile2() {
        int i = 0;
        int d = 0;
        do {
            if (d > 4566) {
                d = 0;
            } else {
                d++;
            }
            i++;
        } while (i < Integer.MAX_VALUE);
        @IntRange(from = -128, to = 32767) int after = d;
        @IntVal(Integer.MAX_VALUE) int afterI = i;
    }

    void oscillatesFor() {
        int d = 0;
        for (int i = 0; i < Integer.MAX_VALUE; i++) {
            if (d > 4566) {
                d = 0;
            } else {
                d++;
            }
        }
        @IntRange(from = -128, to = 32767) int after = d;
    }
}