Skip to content

Commit 51b157f

Browse files
authored
Merge pull request #8380 from tautschnig/bugfixes/contract-scope-8337
C front-end: place requires and ensures in designated scope
2 parents c7d7704 + f008664 commit 51b157f

File tree

3 files changed

+50
-4
lines changed

3 files changed

+50
-4
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#define C 8
2+
3+
typedef unsigned st[C];
4+
5+
// clang-format off
6+
void init_st(st dst)
7+
__CPROVER_requires(__CPROVER_is_fresh(dst, sizeof(st)))
8+
__CPROVER_assigns(__CPROVER_object_whole(dst))
9+
__CPROVER_ensures(__CPROVER_forall {
10+
unsigned i; (0 <= i && i < C) ==> dst[i] == 0
11+
});
12+
// clang-format on
13+
14+
void init_st(st dst)
15+
{
16+
__CPROVER_size_t i;
17+
for(i = 0; i < C; i++)
18+
{
19+
dst[i] = 0;
20+
}
21+
}
22+
23+
int main()
24+
{
25+
st dest;
26+
27+
init_st(dest);
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
^warning: ignoring
8+
^CONVERSION ERROR$

src/ansi-c/parser.y

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3337,17 +3337,27 @@ parameter_abstract_declarator:
33373337
;
33383338

33393339
cprover_function_contract:
3340-
TOK_CPROVER_ENSURES '(' ACSL_binding_expression ')'
3340+
TOK_CPROVER_ENSURES
3341+
{
3342+
PARSER.new_scope("ensures::");
3343+
}
3344+
'(' ACSL_binding_expression ')'
33413345
{
33423346
$$=$1;
33433347
set($$, ID_C_spec_ensures);
3344-
mto($$, $3);
3348+
mto($$, $4);
3349+
PARSER.pop_scope();
33453350
}
3346-
| TOK_CPROVER_REQUIRES '(' ACSL_binding_expression ')'
3351+
| TOK_CPROVER_REQUIRES
3352+
{
3353+
PARSER.new_scope("requires::");
3354+
}
3355+
'(' ACSL_binding_expression ')'
33473356
{
33483357
$$=$1;
33493358
set($$, ID_C_spec_requires);
3350-
mto($$, $3);
3359+
mto($$, $4);
3360+
PARSER.pop_scope();
33513361
}
33523362
| cprover_contract_assigns
33533363
| cprover_contract_frees

0 commit comments

Comments
 (0)