summaryrefslogtreecommitdiff
path: root/Test/test16/LoopUnroll.bpl
blob: 83bf2686e8a9786e6edc6e85946bd7fb61a54325 (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
procedure P()
{
  var x: int;

  A:
    x := 0;
    goto B, Goner, C;

  B:
    x := 1;
    goto D;

  C:
    x := 2;
    goto D;
  
  Goner:
    x := 5;
    assume false;
    x := 6;
    goto B;

  D:
    x := 3;
    goto LoopHead;

  LoopHead:
    assert x < 100;
    goto LoopBody, LoopDone;

  LoopBody:
    x := x + 1;
    goto LoopHead, LoopBodyMore;

  LoopBodyMore:
    x := x + 2;
    goto LoopHead;

  LoopDone:
    x := 88;
    return;
}

type MyValue;
const SpecialValue: MyValue;

procedure WrongRange(a: [int]MyValue, N: int)
  requires 0 <= N;
{
  var i: int, v: MyValue;

  i := 1;  // bad idea
  while (i <= N)  // also a bad idea
  {
    assert 0 <= i;  // lower bounds check
    assert i < N;  // error: upper bounds check
    v := a[i];
    i := i + 1;
  }
}

procedure ManyIterations(a: [int]MyValue, N: int)
  requires 0 <= N;
  requires a[0] != SpecialValue && a[1] != SpecialValue;
{
  var i: int, v: MyValue;

  i := 0;
  while (i < N)
  {
    assert 0 <= i;  // lower bounds check
    assert i < N;  // upper bounds check
    v := a[i];
    assert a[i] != SpecialValue;  // error: after more than 2 loop unrollings
    i := i + 1;
  }
}

// ERROR:  /printInstrumented seems to erase filename source-location information