Skip to content

Commit 467fa22

Browse files
committed
Code contracts: match up introducing/removing parameter map modifications
Code contracts that introduce local declarations result in nested typecheck_declaration calls. The artificial __CPROVER_return_value symbol must then be added/removed by a single call only.
1 parent 3d8e181 commit 467fa22

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// clang-format off
2+
int foo()
3+
__CPROVER_ensures(__CPROVER_forall {int i; 1 == 1})
4+
// clang-format on
5+
{
6+
return 1;
7+
}
8+
9+
// clang-format off
10+
int bar()
11+
__CPROVER_ensures(__CPROVER_forall {int i; 1 == 1} &&
12+
__CPROVER_return_value == 1)
13+
// clang-format on
14+
{
15+
return 1;
16+
}
17+
18+
int main()
19+
{
20+
foo();
21+
bar();
22+
}
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$

regression/contracts/function_check_02/main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// function_check_02
22

33
// This test checks the use of quantifiers in ensures clauses.
4-
// A known bug (resolved in PR #2278) causes the use of quantifiers
5-
// in ensures to fail.
64

75
int initialize(int *arr)
86
__CPROVER_ensures(
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
KNOWNBUG
1+
CORE
22
main.c
3-
--check-code-contracts
3+
--apply-code-contracts
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$
77
--
8-
--
9-
Ensures statements currently do not allow quantified predicates unless the
10-
function has void return type.

src/ansi-c/c_typecheck_base.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,15 @@ void c_typecheck_baset::typecheck_declaration(
748748
typet ret_type = void_type();
749749
if(new_symbol.type.id()==ID_code)
750750
ret_type=to_code_type(new_symbol.type).return_type();
751-
assert(parameter_map.empty());
752751
if(ret_type.id()!=ID_empty)
752+
{
753+
DATA_INVARIANT(
754+
parameter_map.empty(), "parameter map should be cleared");
753755
parameter_map[CPROVER_PREFIX "return_value"] = ret_type;
756+
}
754757
typecheck_spec_expr(static_cast<codet &>(contract), ID_C_spec_ensures);
755-
parameter_map.clear();
758+
if(ret_type.id() != ID_empty)
759+
parameter_map.clear();
756760

757761
irept assigns_to_add = contract.find(ID_C_spec_assigns);
758762
if(assigns_to_add.is_not_nil())

0 commit comments

Comments
 (0)