File tree Expand file tree Collapse file tree 18 files changed +220
-26
lines changed
history-pointer-replace-03
loop-history-variables-01
loop-history-variables-02
loop-history-variables-03
loop-history-variables-04
goto-instrument/contracts Expand file tree Collapse file tree 18 files changed +220
-26
lines changed Original file line number Diff line number Diff line change 3
3
--replace-all-calls-with-contracts
4
4
^EXIT=(1|64)$
5
5
^SIGNAL=0$
6
+ ^main.c.* error: __CPROVER_old expressions are not allowed in this context$
6
7
^CONVERSION ERROR$
7
- error: __CPROVER_old expressions are not allowed in __CPROVER_requires clauses
8
8
--
9
9
--
10
10
Verification:
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stdlib.h>
3
+
4
+ typedef struct
5
+ {
6
+ int * n ;
7
+ } s ;
8
+
9
+ void main ()
10
+ {
11
+ int * x1 , y1 , z1 ;
12
+ * x1 = & z1 ;
13
+
14
+ while (y1 > 0 )
15
+ __CPROVER_loop_invariant (* x1 == __CPROVER_loop_entry (* x1 ))
16
+ {
17
+ -- y1 ;
18
+ * x1 = * x1 + 1 ;
19
+ * x1 = * x1 - 1 ;
20
+ }
21
+ assert (* x1 == & z1 );
22
+
23
+ int x2 , y2 , z2 ;
24
+ x2 = z2 ;
25
+
26
+ while (y2 > 0 )
27
+ __CPROVER_loop_invariant (x2 == __CPROVER_loop_entry (x2 ))
28
+ {
29
+ -- y2 ;
30
+ x2 = x2 + 1 ;
31
+ x2 = x2 - 1 ;
32
+ }
33
+ assert (x2 == z2 );
34
+
35
+ int y3 ;
36
+ s * s1 , * s2 ;
37
+ s2 -> n = malloc (sizeof (int ));
38
+ s1 -> n = s2 -> n ;
39
+
40
+ while (y3 > 0 )
41
+ __CPROVER_loop_invariant (* s1 == __CPROVER_loop_entry (* s1 ))
42
+ {
43
+ -- y3 ;
44
+ s1 -> n = s1 -> n + 1 ;
45
+ s1 -> n = s1 -> n - 1 ;
46
+ }
47
+
48
+ assert (s1 -> n == s2 -> n );
49
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --apply-loop-contracts
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7
+ ^\[main.2\] .* Check that loop invariant is preserved: SUCCESS$
8
+ ^\[main.assertion.1\] .* assertion \*x1 == &z1: SUCCESS$
9
+ ^\[main.3\] .* Check loop invariant before entry: SUCCESS$
10
+ ^\[main.4\] .* Check that loop invariant is preserved: SUCCESS$
11
+ ^\[main.assertion.2\] .* assertion x2 == z2: SUCCESS$
12
+ ^\[main.5\] .* Check loop invariant before entry: SUCCESS$
13
+ ^\[main.6\] .* Check that loop invariant is preserved: SUCCESS$
14
+ ^\[main.assertion.3\] .* assertion s1->n == s2->n: SUCCESS$
15
+ ^VERIFICATION SUCCESSFUL$
16
+ --
17
+ --
18
+ This test checks that __CPROVER_loop_entry is supported.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ void main ()
4
+ {
5
+ int * x , y , z ;
6
+
7
+ * x = & z ;
8
+
9
+ while (y > 0 )
10
+ __CPROVER_loop_invariant (* x == __CPROVER_old (* x ))
11
+ {
12
+ -- y ;
13
+ * x = * x + 1 ;
14
+ * x = * x - 1 ;
15
+ }
16
+ assert (* x == & z );
17
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --apply-loop-contracts
4
+ ^main.c.* error: __CPROVER_old expressions are not allowed in this context$
5
+ ^CONVERSION ERROR$
6
+ ^EXIT=(1|64)$
7
+ ^SIGNAL=0$
8
+ --
9
+ --
10
+ This test ensures that __CPROVER_old cannot be used for loop contracts.
Original file line number Diff line number Diff line change
1
+ void foo (int * x ) __CPROVER_assigns (* x )
2
+ __CPROVER_ensures (* x == __CPROVER_loop_entry (* x ) + 5 )
3
+ {
4
+ * x = * x + 5 ;
5
+ }
6
+
7
+ int main ()
8
+ {
9
+ int n ;
10
+ foo (& n );
11
+
12
+ return 0 ;
13
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --enforce-all-contracts
4
+ ^main.c.* error: __CPROVER_loop_entry expressions are not allowed in this context$
5
+ ^CONVERSION ERROR$
6
+ ^EXIT=(1|64)$
7
+ ^SIGNAL=0$
8
+ --
9
+ --
10
+ This test ensures that __CPROVER_loop_entry cannot be
11
+ used for function contracts.
Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+
3
+ void main ()
4
+ {
5
+ int x , y , z ;
6
+ x = z ;
7
+
8
+ while (y > 0 )
9
+ __CPROVER_loop_invariant (x == __CPROVER_loop_entry (x ))
10
+ {
11
+ -- y ;
12
+ x = x + 1 ;
13
+ x = x - 2 ;
14
+ }
15
+ assert (x == z );
16
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+ --apply-loop-contracts
4
+ ^EXIT=(10|6)$
5
+ ^SIGNAL=0$
6
+ ^\[main.1\] .* Check loop invariant before entry: SUCCESS$
7
+ ^\[main.2\] .* Check that loop invariant is preserved: FAILURE$
8
+ ^\[main.assertion.1\] .* assertion x == z: SUCCESS$
9
+ ^VERIFICATION FAILED$
10
+ --
11
+ --
12
+ This test checks that __CPROVER_loop_entry is sound.
Original file line number Diff line number Diff line change @@ -202,10 +202,11 @@ inline side_effect_expr_overflowt &to_side_effect_expr_overflow(exprt &expr)
202
202
203
203
// / \brief A class for an expression that indicates the pre-function-call
204
204
// / value of an expression passed as a parameter to a function
205
- class old_exprt : public unary_exprt
205
+ class history_exprt : public unary_exprt
206
206
{
207
207
public:
208
- explicit old_exprt (exprt variable) : unary_exprt(ID_old, std::move(variable))
208
+ explicit history_exprt (exprt variable, const irep_idt &id)
209
+ : unary_exprt(id, std::move(variable))
209
210
{
210
211
}
211
212
@@ -215,10 +216,12 @@ class old_exprt : public unary_exprt
215
216
}
216
217
};
217
218
218
- inline const old_exprt &to_old_expr (const exprt &expr)
219
+ inline const history_exprt &
220
+ to_history_expr (const exprt &expr, const irep_idt &id)
219
221
{
220
- PRECONDITION (expr.id () == ID_old);
221
- auto &ret = static_cast <const old_exprt &>(expr);
222
+ PRECONDITION (id == ID_old || id == ID_loop_entry);
223
+ PRECONDITION (expr.id () == id);
224
+ auto &ret = static_cast <const history_exprt &>(expr);
222
225
validate_expr (ret);
223
226
return ret;
224
227
}
You can’t perform that action at this time.
0 commit comments