Skip to content

Commit 3864e9e

Browse files
committed
Documenting semantic of loop invariant synthesizers
1 parent 175a609 commit 3864e9e

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[CPROVER Manual TOC](../)
2+
3+
## Loop Invariant Synthesis with goto-instrument
4+
5+
This is a loop invariant synthesizer built in goto-instrument that
6+
synthesize [loop invariants](contracts-invariants.md) for a
7+
pre-existing GOTO binary, annotate the invariant clause into
8+
the GOTO binary, and produce an annotated binary as output.
9+
10+
All synthesized loop invariants must be inductive, i.e.,
11+
all [loop-invariant checks](contracts-invariants.md#semantics)
12+
succeed in the instrumented GOTO binary.
13+
14+
For different synthesis strategies, there are different guarantees
15+
beyond the inductiveness on the synthesized loop invariants,
16+
summarized in the following table.
17+
18+
Strategy | Flag | Guarantees
19+
-----------------|------------------------------------------------|----
20+
Enumerative | --synthesize-loop-invariants-enumerative | All checks will succeeded in the annotated GOTO binary
21+
22+
### Enumerative Synthesizer
23+
24+
This synthesizer is designed for GOTO binary that contains only checks instrumented
25+
with the flag ```--pointer-check```, and synthesizes loop invariants that make
26+
all checks succeeded. The idea of the synthesizer is first inferring a clause,
27+
using the idea of weakest preconditions, for each violated check to make it succeed,
28+
and then enumerating a strengthening clause to make the inferred clause inductive.
29+
30+
If the input GOTO binary contains a violated check that is not a pointer check,
31+
the synthesizer will skip the inferring step and simply enumerate predicate that
32+
is inductive and can make the check succeed.
33+
34+
## Additional Resources
35+
36+
- [Loop Contracts](contracts-loops.md)
37+
- [Inductive Invariant Generation via Abductive Inference](https://www.cs.utexas.edu/~isil/oopsla13.pdf)

regression/contracts/loop_invariant_synthesis_01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
--synthesize-loop-invariants --apply-loop-contracts
3+
--synthesize-loop-invariants-enumerative --apply-loop-contracts
44
^EXIT=0$
55
^SIGNAL=0$
66
^\[main\.\d+\] line 10 Check loop invariant before entry: SUCCESS$

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ void goto_instrument_parse_optionst::instrument_goto_program()
11461146
goto_model.goto_functions.update();
11471147
}
11481148

1149-
if(cmdline.isset("synthesize-loop-invariants"))
1149+
if(cmdline.isset("synthesize-loop-invariants-enumerative"))
11501150
{
11511151
log.warning() << "Loop invariant synthesizer is still work in progress. "
11521152
"It only generates TRUE as invariants."

src/goto-instrument/synthesizer/enumerative_loop_invariant_synthesizer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ Author: Qinheping Hu
2121
class messaget;
2222

2323
/// Enumerative loop invariant synthesizers.
24-
/// It handles `goto_model` containing only checks instrumented by
25-
/// `goto-instrument` with the `--pointer-check` flag.
24+
/// It is designed for `goto_model` containing only checks instrumented by
25+
/// `goto-instrument` with the `--pointer-check` flag. H
26+
/// When other checks present, it will just enumerate candidates and check
27+
/// if they are valid.
2628
class enumerative_loop_invariant_synthesizert
2729
: public loop_invariant_synthesizer_baset
2830
{
@@ -34,6 +36,8 @@ class enumerative_loop_invariant_synthesizert
3436
{
3537
}
3638

39+
/// This synthesizer guarantees that, with the synthesized loop invariants,
40+
/// all checks in the annotated GOTO program pass.
3741
invariant_mapt synthesize_all() override;
3842
exprt synthesize(loop_idt loop_id) override;
3943

src/goto-instrument/synthesizer/loop_invariant_synthesizer_base.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ Author: Qinheping Hu
1616

1717
#include "synthesizer_utils.h"
1818

19-
#define OPT_SYNTHESIZE_LOOP_INVARIANTS "(synthesize-loop-invariants)"
19+
#define OPT_SYNTHESIZE_LOOP_INVARIANTS \
20+
"(synthesize-loop-invariants-enumerative)"
2021
#define HELP_LOOP_INVARIANT_SYNTHESIZER \
21-
" --synthesize-loop-invariants\n" \
22+
" --synthesize-loop-invariants-enumerative\n" \
2223
" synthesize and apply loop invariants\n"
2324

2425
class messaget;
@@ -38,12 +39,13 @@ class loop_invariant_synthesizer_baset
3839
}
3940
virtual ~loop_invariant_synthesizer_baset() = default;
4041

41-
/// Synthesize loop invariants with which all checks in `goto_model`
42-
/// succeed. The result is a map from `loop_idt` ids of loops to `exprt`
43-
/// the goto-expression representation of synthesized invariants.
42+
/// Synthesize loop invariants that are inductive in the given GOTO program.
43+
///
44+
/// The result is a map from `loop_idt` ids of loops to `exprt`
45+
/// the GOTO-expression representation of synthesized invariants.
4446
virtual invariant_mapt synthesize_all() = 0;
4547

46-
/// Synthesize loop invariant for a specified loop in the `goto_model`
48+
/// Synthesize loop invariant for a specified loop in the `goto_model`.
4749
virtual exprt synthesize(loop_idt) = 0;
4850

4951
protected:

0 commit comments

Comments
 (0)