Skip to content

Commit c5bebfa

Browse files
committed
Use local alias analysis in loop assigns synthesis
1 parent d9978b4 commit c5bebfa

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/goto-synthesizer/enumerative_loop_contracts_synthesizer.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ Author: Qinheping Hu
1919
#include <util/replace_symbol.h>
2020
#include <util/simplify_expr.h>
2121

22+
#include <analyses/local_may_alias.h>
2223
#include <analyses/natural_loops.h>
24+
#include <goto-instrument/contracts/cfg_info.h>
25+
#include <goto-instrument/contracts/utils.h>
2326
#include <goto-instrument/havoc_utils.h>
27+
#include <goto-instrument/loop_utils.h>
2428

2529
#include "cegis_verifier.h"
2630
#include "expr_enumerator.h"
@@ -82,17 +86,21 @@ void enumerative_loop_contracts_synthesizert::init_candidates()
8286
{
8387
for(auto &function_p : goto_model.goto_functions.function_map)
8488
{
85-
natural_loopst natural_loops;
89+
natural_loops_mutablet natural_loops;
8690
natural_loops(function_p.second.body);
8791

92+
// TODO: use global may alias instead.
93+
local_may_aliast local_may_alias(function_p.second);
94+
8895
// Initialize invariants for unannotated loops as true
8996
for(const auto &loop_head_and_content : natural_loops.loop_map)
9097
{
9198
goto_programt::const_targett loop_end =
92-
get_loop_end_from_loop_head_and_content(
99+
get_loop_end_from_loop_head_and_content_mutable(
93100
loop_head_and_content.first, loop_head_and_content.second);
94101

95102
loop_idt new_id(function_p.first, loop_end->loop_number);
103+
loop_cfg_infot cfg_info(function_p.second, loop_head_and_content.second);
96104

97105
log.debug() << "Initialize candidates for the loop at "
98106
<< loop_end->source_location() << messaget::eom;
@@ -116,6 +124,17 @@ void enumerative_loop_contracts_synthesizert::init_candidates()
116124
if(loop_end->condition().find(ID_C_spec_assigns).is_nil())
117125
{
118126
assigns_map[new_id] = {};
127+
128+
// Infer loop assigns using alias analysis.
129+
get_assigns(
130+
local_may_alias, loop_head_and_content.second, assigns_map[new_id]);
131+
132+
// remove loop-local symbols from the inferred set
133+
cfg_info.erase_locals(assigns_map[new_id]);
134+
135+
// If the set contains pairs (i, a[i]),
136+
// we widen them to (i, __CPROVER_POINTER_OBJECT(a))
137+
widen_assigns(assigns_map[new_id], ns);
119138
}
120139
}
121140
}
@@ -127,7 +146,6 @@ void enumerative_loop_contracts_synthesizert::synthesize_assigns(
127146
const exprt &checked_pointer,
128147
const std::list<loop_idt> cause_loop_ids)
129148
{
130-
namespacet ns(goto_model.symbol_table);
131149
auto new_assign = checked_pointer;
132150

133151
// Add the new assigns target to the most-inner loop that doesn't contain
@@ -242,7 +260,6 @@ exprt enumerative_loop_contracts_synthesizert::synthesize_strengthening_clause(
242260
// | StartBool <= StartBool | StartBool < StartBool
243261
// Start -> Start + Start | terminal_symbols
244262
// where a0, and a1 are symbol expressions.
245-
namespacet ns(goto_model.symbol_table);
246263
enumerator_factoryt factory = enumerator_factoryt(ns);
247264
recursive_enumerator_placeholdert start_bool_ph(factory, "StartBool", ns);
248265
recursive_enumerator_placeholdert start_ph(factory, "Start", ns);

src/goto-synthesizer/enumerative_loop_contracts_synthesizer.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class enumerative_loop_contracts_synthesizert
3131
enumerative_loop_contracts_synthesizert(
3232
goto_modelt &goto_model,
3333
messaget &log)
34-
: loop_contracts_synthesizer_baset(goto_model, log)
34+
: loop_contracts_synthesizer_baset(goto_model, log),
35+
ns(goto_model.symbol_table)
3536
{
3637
}
3738

@@ -45,6 +46,8 @@ class enumerative_loop_contracts_synthesizert
4546
return assigns_map;
4647
}
4748

49+
namespacet ns;
50+
4851
private:
4952
/// Initialize invariants as true for all unannotated loops.
5053
void init_candidates();

0 commit comments

Comments
 (0)