Skip to content

Commit 737848c

Browse files
committed
Handle the case of violation in loop guards in loop-invariant synthesis
In current loop-invariant synthesizer, we synthesize two kinds of clauses separately. 1. `in_clause` that should hold when we enter the loop body---when the loop guard holds, that is ```loop_guard -> in_clause```. 2. `pos_clause` that should hold when we leave the loop---when the loop guard doesn't hold, that is ```!loop_guard -> pos_clause```. We synthesize `in_clause` when the violations happen in the loop body. We synthesize `pos_clause` when the violation happen after the loop. This PR handles the case that the violations happen in the loop guard. In the case, the new clause we synthesize should hold for both of the cases that loop guard holds and loop guards doesn't hold. We introduce a new variable `violation_location` to indicate whether the violation happen in the loop, after the loop, or in the loop guard, and add the new synthesized clause as `in_clause`, `pos_clause`, or both, respectively.
1 parent 96c5167 commit 737848c

File tree

9 files changed

+12
-12
lines changed

9 files changed

+12
-12
lines changed

regression/goto-synthesizer/loop_contracts_synthesis_06/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdlib.h>
12
#define SIZE 80
23

34
void main()

regression/goto-synthesizer/loop_contracts_synthesis_06/test.desc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ main.c
99
^VERIFICATION SUCCESSFUL$
1010
--
1111
--
12-
This test is a variation of strlen. It checks that we can synthesize
13-
loop invariant for checks happen in the loop guard.
12+
Checks whether CBMC synthesizes loop invariants for checks in the loop guard.

regression/goto-synthesizer/loop_contracts_synthesis_06/test_dump.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ main.c
66
loop 1 invariant.*\_\_CPROVER\_POINTER\_OFFSET
77
assigns i
88
--
9-
This test case checks if synthesized contracts are correctly dumped.
9+
Checks if synthesized contracts are dumped correctly.

regression/goto-synthesizer/loop_contracts_synthesis_07/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdlib.h>
12
#define SIZE 80
23

34
void main()

regression/goto-synthesizer/loop_contracts_synthesis_07/test.desc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ main.c
1010
^VERIFICATION SUCCESSFUL$
1111
--
1212
--
13-
This test checks that we can synthesize loop invariant for violation happen
14-
after the loop body.
13+
Checks whether CBMC synthesizes loop invariants for checks located after the loop body.

regression/goto-synthesizer/loop_contracts_synthesis_07/test_dump.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ main.c
66
loop 1 assigns i
77
loop 1 invariant.*\_\_CPROVER\_POINTER\_OFFSET
88
--
9-
This test case checks if synthesized contracts are correctly dumped.
9+
Checks if synthesized contracts are dumped correctly.

src/goto-synthesizer/cegis_verifier.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ bool cegis_verifiert::is_instruction_in_transfomed_loop_condition(
236236
const goto_functiont &function,
237237
unsigned location_number_of_target)
238238
{
239-
// The transformed loop condition are instructions from
239+
// The transformed loop condition is a set of instructions from
240240
// loop havocing instructions
241241
// to
242242
// if(!guard) GOTO EXIT
@@ -245,7 +245,7 @@ bool cegis_verifiert::is_instruction_in_transfomed_loop_condition(
245245
it != function.body.instructions.end();
246246
++it)
247247
{
248-
// Record the location number of the begin of a transformed loop.
248+
// Record the location number of the beginning of a transformed loop.
249249
if(
250250
loop_havoc_set.count(it) &&
251251
original_loop_number_map[it] == loop_id.loop_number)

src/goto-synthesizer/cegis_verifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class cext
6868
exprt checked_pointer;
6969
exprt violated_predicate;
7070

71-
// Location where the violation happen.
71+
// Location where the violation happens
7272
violation_locationt violation_location = violation_locationt::in_loop;
7373

7474
// We collect havoced evaluations of havoced variables and their object sizes

src/goto-synthesizer/enumerative_loop_contracts_synthesizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ invariant_mapt enumerative_loop_contracts_synthesizert::synthesize_all()
408408
return_cex->violation_location ==
409409
cext::violation_locationt::in_condition)
410410
{
411-
// When the violation is happen in the loop guard, the new clause
411+
// When the violation happens in the loop guard, the new clause
412412
// should hold for the both cases of
413413
// 1. loop guard holds --- loop_guard -> in_invariant
414414
// 2. loop guard doesn't hold --- !loop_guard -> pos_invariant
@@ -420,15 +420,15 @@ invariant_mapt enumerative_loop_contracts_synthesizert::synthesize_all()
420420
else if(
421421
return_cex->violation_location == cext::violation_locationt::in_loop)
422422
{
423-
// When the violation is happen in the loop body, the new clause
423+
// When the violation happens in the loop body, the new clause
424424
// should hold for the case of
425425
// loop guard holds --- loop_guard -> in_invariant
426426
in_invariant_clause_map[cause_loop_id] = and_exprt(
427427
in_invariant_clause_map[cause_loop_id], new_invariant_clause);
428428
}
429429
else
430430
{
431-
// When the violation is happen after the loop body, the new clause
431+
// When the violation happens after the loop body, the new clause
432432
// should hold for the case of
433433
// loop guard doesn't hold --- !loop_guard -> pos_invariant
434434
pos_invariant_clause_map[cause_loop_id] = and_exprt(

0 commit comments

Comments
 (0)