summaryrefslogtreecommitdiff
path: root/Test/test2/Where.bpl
blob: 96ffcf044af21bfa35307c671cae2c1119eb8ed7 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
procedure P0()
{
  var x: int where 0 <= x;
  var y: int where x <= y;

  assert 0 <= x;
  assert x <= y;
  assert y < 5;  // error
}

procedure P1()
{
  var x: int where 0 <= x;
  var y: int where x <= y;

  x := 5;
  havoc y;
  assert 5 <= y;

  havoc x;
  assert 0 <= x;
  assert x <= y;  // error
}

procedure P2()
{
  var x: int where 0 <= x;
  var y: int where x <= y;

  havoc y;  // y first
  havoc x;
  assert x <= y;  // error
}

procedure P3()
{
  var x: int where 0 <= x;
  var y: int where x <= y;

  x := 5;
  havoc x;  // this time, x first
  havoc y;
  assert x <= y;  // yeah!
  assert 5 <= y;  // error
}

procedure P4()
{
  var x: int where 0 <= x;
  var y: int where x <= y;

  havoc x, y;  // both at the same time
  assert 0 <= x && x <= y;
  havoc y, x;  // or in the other order
  assert 0 <= x && x <= y;

  assert x == 7;  // error
}

procedure R0() returns (wProc: int where wProc == xProc,
                        xProc: int where 0 <= xProc,
                        yProc: int where xProc <= yProc);
implementation R0() returns (w: int, x: int, y: int)
{
  while (*) {
    assert w == x;
    assert 0 <= x;
    assert x <= y;
  }
  while (*) {
    assert w == x;
    assert 0 <= x;
    assert x <= y;
    // the following makes w, x, y loop targets
    w := w + 1;
    havoc x;
    y := w;
  }
  assert w == x;
  assert 0 <= x;
  assert x <= y;
}

procedure R1()
{
  var a: int;
  var b: int;
  var c: int;

  call a, b, c := R0();
  assert a == b;
  assert 0 <= b;
  assert b <= c;
}

procedure R2()
{
  var w: int where w == x;
  var x: int where 0 <= x;
  var y: int where x <= y;

  x := 5;
  y := 10;
  while (*) {
    w := w + 1;
    assert w == 6;
    y := y + 2;
    assert 7 <= y;
  }
  assert x == 5 && 0 <= y - w;
  assert y == 10;  // error
}

procedure R3()
{
  var w: int where w == x;
  var x: int where 0 <= x;
  var y: int where x <= y;

  // change w and x
  y := 10;
  while (*) {
    w := w;  x := x;
  }
  assert w == x;
  assert 0 <= x;
  assert y == 10;
  assert w <= 10;  // error
}

procedure R4()
{
  var w: int where w == x;
  var x: int where 0 <= x;
  var y: int where x <= y;

  // change x and y
  w := 12;
  while (*) {
    x := x;  y := y;
  }
  assert 0 <= x;
  assert x <= y;
  assert w == 12;
  assert 8 <= y;  // error
}

procedure R5(K: int)
{
  var w: int where w == x;
  var x: int where 0 <= x;
  var y: int where x <= y;

  // change w and y
  x := K;
  while (*) {
    w := w;  y := y;
  }
  assert w == K;
  assert K <= y;
  assert x == K;
  assert 0 <= x;  // error
}