Skip to content

Commit 4802245

Browse files
committed
postcondition messages now include condition
1 parent 278c301 commit 4802245

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int x, y;
2+
3+
void my_function()
4+
__CPROVER_ensures(x == 10) // passes
5+
__CPROVER_ensures(y == 20) // fails
6+
__CPROVER_assigns(x, y)
7+
{
8+
x = 10;
9+
y = 10;
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
check_postcondition4.c
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[my_function\.postcondition\.2\] line \d+ postcondition x == 10: SUCCESS$
7+
^\[my_function\.postcondition\.1\] line \d+ postcondition y == 20: REFUTED$
8+
--

src/cprover/instrument_contracts.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,14 @@ void instrument_contract_checks(
229229

230230
for(auto &assertion : contract.ensures())
231231
{
232+
std::string comment = "postcondition";
233+
if(contract.ensures().size() >= 2)
234+
comment += " " + expr2text(assertion, ns);
235+
232236
auto location = assertion.source_location();
233237
location.set_function(f.first); // seems to be missing
234238
location.set_property_class(ID_postcondition);
235-
location.set_comment("postcondition");
239+
location.set_comment(comment);
236240

237241
auto replaced_assertion = replace_old(assertion, f.first, old_exprs);
238242

0 commit comments

Comments
 (0)