File tree 3 files changed +48
-0
lines changed
regression/contracts-dfcc/reject_history_expr_in_assertions
3 files changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include <assert.h>
2
+ #include <stdbool.h>
3
+ #include <stddef.h>
4
+
5
+ #define N 16
6
+
7
+ void f (int r [N ])
8
+ {
9
+ for (int j = 0 ; j < N ; j ++ )
10
+ {
11
+ int t = r [j ];
12
+ __CPROVER_assert (t == __CPROVER_loop_entry (r [j ]), "Initial value of r[j]" );
13
+ r [j ] = t + 1 ;
14
+ }
15
+ }
16
+
17
+ void main ()
18
+ {
19
+ int x [N ];
20
+ f (x );
21
+ }
Original file line number Diff line number Diff line change
1
+ CORE
2
+ main.c
3
+
4
+ ^main.c.*error: __CPROVER_loop_entry is not allowed in assume/assert.$
5
+ ^CONVERSION ERROR$
6
+ ^EXIT=(1|64)$
7
+ ^SIGNAL=0$
8
+ --
9
+ --
10
+ This test checks that __CPROVER_loop_entry occurrences in assertions
11
+ are detected and rejected.
Original file line number Diff line number Diff line change @@ -106,6 +106,14 @@ void c_typecheck_baset::typecheck_code(codet &code)
106
106
else if (statement==ID_static_assert)
107
107
{
108
108
PRECONDITION (code.operands ().size () == 2 );
109
+ disallow_subexpr_by_id (
110
+ code.op0 (),
111
+ ID_old,
112
+ CPROVER_PREFIX " old is not allowed in static assert." );
113
+ disallow_subexpr_by_id (
114
+ code.op0 (),
115
+ ID_loop_entry,
116
+ CPROVER_PREFIX " loop_entry is not allowed in static assert." );
109
117
110
118
typecheck_expr (code.op0 ());
111
119
typecheck_expr (code.op1 ());
@@ -142,6 +150,14 @@ void c_typecheck_baset::typecheck_code(codet &code)
142
150
// but we allow them for the benefit of other users
143
151
// of the typechecker.
144
152
PRECONDITION (code.operands ().size () == 1 );
153
+ disallow_subexpr_by_id (
154
+ code.op0 (),
155
+ ID_old,
156
+ CPROVER_PREFIX " old is not allowed in assume/assert." );
157
+ disallow_subexpr_by_id (
158
+ code.op0 (),
159
+ ID_loop_entry,
160
+ CPROVER_PREFIX " loop_entry is not allowed in static assume/assert." );
145
161
typecheck_expr (code.op0 ());
146
162
}
147
163
else
You can’t perform that action at this time.
0 commit comments