File: main.c

package info (click to toggle)
cbmc 6.6.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,852 kB
  • sloc: cpp: 386,459; ansic: 114,466; java: 28,405; python: 6,003; yacc: 4,552; makefile: 4,041; lex: 2,487; xml: 2,388; sh: 2,050; perl: 557; pascal: 184; javascript: 163; ada: 36
file content (128 lines) | stat: -rw-r--r-- 3,308 bytes parent folder | download
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
#include <assert.h>
#include <stdlib.h>

struct STRUCTNAME
{
  int x1;
  int B1[3];
};

void f_int_val(int x)
{
  // x has its own shadow memory
  assert(__CPROVER_get_field(&x, "field1") == 0);
  __CPROVER_set_field(&x, "field1", 1);
  assert(__CPROVER_get_field(&x, "field1") == 1);
}

void f_intptr_ptr0(int *x)
{
  // we access the argument's shadow memory
  assert(__CPROVER_get_field(x, "field1") == 255);
  __CPROVER_set_field(x, "field1", 1);
  assert(__CPROVER_get_field(x, "field1") == 1);
}

void f_intptr_ptr1(int *x)
{
  // we access the argument's shadow memory
  assert(__CPROVER_get_field(x, "field1") == 1);
  __CPROVER_set_field(x, "field1", 2);
  assert(__CPROVER_get_field(x, "field1") == 2);
}

void f_intptr_val(int *x)
{
  // x has its own shadow memory
  assert(__CPROVER_get_field(&x, "field1") == 0);
  __CPROVER_set_field(&x, "field1", 3);
  assert(__CPROVER_get_field(&x, "field1") == 3);
}

void f_intarray_ptr0(int x[])
{
  // we access the argument's shadow memory
  assert(__CPROVER_get_field(&(x[0]), "field1") == 255);
  __CPROVER_set_field(&(x[0]), "field1", 1);
  assert(__CPROVER_get_field(&(x[0]), "field1") == 1);
}

void f_intarray_ptr1(int x[])
{
  // we access the argument's shadow memory
  assert(__CPROVER_get_field(&(x[0]), "field1") == 1);
  __CPROVER_set_field(&(x[0]), "field1", 2);
  assert(__CPROVER_get_field(&(x[0]), "field1") == 2);
}

void f_struct_val(struct STRUCTNAME x)
{
  // x has its own shadow memory
  assert(__CPROVER_get_field(&(x.B1[2]), "field1") == 0);
  __CPROVER_set_field(&(x.B1[2]), "field1", 5);
  assert(__CPROVER_get_field(&(x.B1[2]), "field1") == 5);
}

void f_structptr_ptr0(struct STRUCTNAME *x)
{
  // we access the argument's shadow memory
  assert(__CPROVER_get_field(&(x->B1[2]), "field1") == 255);
  __CPROVER_set_field(&(x->B1[2]), "field1", 1);
  assert(__CPROVER_get_field(&(x->B1[2]), "field1") == 1);
}

void f_structptr_ptr1(struct STRUCTNAME *x)
{
  // we access the argument's shadow memory
  assert(__CPROVER_get_field(&(x->B1[2]), "field1") == 1);
  __CPROVER_set_field(&(x->B1[2]), "field1", 2);
  assert(__CPROVER_get_field(&(x->B1[2]), "field1") == 2);
}

void f_structptr_val(struct STRUCTNAME *x)
{
  // x has its own shadow memory
  assert(__CPROVER_get_field(&x, "field1") == 0);
  __CPROVER_set_field(&x, "field1", 7);
  assert(__CPROVER_get_field(&x, "field1") == 7);
}

void f_int_local(int rec, int value)
{
  // locals in each recursive call instance have their own shadow memory
  int x;
  assert(__CPROVER_get_field(&x, "field1") == 0);
  __CPROVER_set_field(&x, "field1", value);
  assert(__CPROVER_get_field(&x, "field1") == value);
  if(rec)
  {
    f_int_local(0, value + 1);
    assert(__CPROVER_get_field(&x, "field1") == value);
  }
}

int main()
{
  __CPROVER_field_decl_local("field1", (unsigned char)0);
  int x;
  __CPROVER_set_field(&x, "field1", 255);
  f_int_val(x);
  f_int_val(x);
  f_intptr_ptr0(&x);
  f_intptr_ptr1(&x);
  f_intptr_val(&x);
  f_intptr_val(&x);
  int y[1];
  __CPROVER_set_field(&y[0], "field1", 255);
  f_intarray_ptr0(y);
  f_intarray_ptr1(y);
  struct STRUCTNAME z;
  __CPROVER_set_field(&z, "field1", 255);
  f_struct_val(z);
  f_struct_val(z);
  f_structptr_ptr0(&z);
  f_structptr_ptr1(&z);
  f_structptr_val(&z);
  f_structptr_val(&z);
  f_int_local(1, 1);
}