Skip to content

Commit aede6f9

Browse files
committed
Enforce __CPROVER_loop_invariant contracts
Loop invariant annotations were being silently ignored when goto-instrument was invoked with `--enforce-contracts` or `--enforce-contract`. These flags now enforce both function and loop invariant contracts.
1 parent 1b2cdc6 commit aede6f9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/goto-instrument/code_contracts.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,8 @@ bool code_contractst::enforce_contracts()
933933
{
934934
if(has_contract(goto_function.first))
935935
funs_to_enforce.insert(id2string(goto_function.first));
936+
else
937+
apply_loop_contract(goto_function.second);
936938
}
937939
return enforce_contracts(funs_to_enforce);
938940
}
@@ -943,14 +945,24 @@ bool code_contractst::enforce_contracts(
943945
bool fail = false;
944946
for(const auto &fun : funs_to_enforce)
945947
{
946-
if(!has_contract(fun))
948+
auto goto_function = goto_functions.function_map.find(fun);
949+
if(goto_function == goto_functions.function_map.end())
947950
{
948951
fail = true;
949952
log.error() << "Could not find function '" << fun
950953
<< "' in goto-program; not enforcing contracts."
951954
<< messaget::eom;
952955
continue;
953956
}
957+
apply_loop_contract(goto_function->second);
958+
959+
if(!has_contract(fun))
960+
{
961+
fail = true;
962+
log.error() << "Could not find any contracts within function '" << fun
963+
<< "'; nothing to enforce." << messaget::eom;
964+
continue;
965+
}
954966

955967
if(!fail)
956968
fail = enforce_contract(fun);

0 commit comments

Comments
 (0)