Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions regression/contracts/history-index/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <assert.h>

int main()
{
int i, n, x[10];
__CPROVER_assume(x[0] == x[9]);
while(i < n)
__CPROVER_loop_invariant(x[0] == __CPROVER_loop_entry(x[0]))
{
x[0] = x[9] - 1;
x[0]++;
}
assert(x[0] == x[9]);
}
10 changes: 10 additions & 0 deletions regression/contracts/history-index/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--apply-loop-contracts
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^Tracking history of index expressions is not supported yet\.
--
This test checks that `ID_index` expressions are allowed within history variables.
19 changes: 19 additions & 0 deletions regression/contracts/history-invalid/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <assert.h>

int foo(int x)
{
return x;
}

int main()
{
int i, n, x[10];
__CPROVER_assume(x[0] == x[9]);
while(i < n)
__CPROVER_loop_invariant(x[0] == __CPROVER_loop_entry(foo(x[0])))
{
x[0] = x[9] - 1;
x[0]++;
}
assert(x[0] == x[9]);
}
11 changes: 11 additions & 0 deletions regression/contracts/history-invalid/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CORE
main.c
--apply-loop-contracts
^main.c.* error: Tracking history of side_effect expressions is not supported yet.$
^CONVERSION ERROR$
^EXIT=(1|64)$
^SIGNAL=0$
--
--
This test ensures that expressions with side effect, such as function calls,
may not be used in history variables.
12 changes: 12 additions & 0 deletions src/ansi-c/c_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2732,6 +2732,18 @@ exprt c_typecheck_baset::do_special_functions(
throw 0;
}

const auto &param_id = expr.arguments().front().id();
if(!(param_id == ID_dereference || param_id == ID_member ||
param_id == ID_symbol || param_id == ID_ptrmember ||
param_id == ID_constant || param_id == ID_typecast ||
param_id == ID_index))
{
error().source_location = f_op.source_location();
error() << "Tracking history of " << param_id
<< " expressions is not supported yet." << eom;
throw 0;
}

irep_idt id = identifier == CPROVER_PREFIX "old" ? ID_old : ID_loop_entry;

history_exprt old_expr(expr.arguments()[0], id);
Expand Down
3 changes: 2 additions & 1 deletion src/goto-instrument/contracts/contracts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ void code_contractst::replace_history_parameter(
const auto &id = parameter.id();
if(
id == ID_dereference || id == ID_member || id == ID_symbol ||
id == ID_ptrmember || id == ID_constant || id == ID_typecast)
id == ID_ptrmember || id == ID_constant || id == ID_typecast ||
id == ID_index)
{
auto it = parameter2history.find(parameter);

Expand Down