Skip to content

Commit f1185fb

Browse files
Petr BauchPetr Bauch
Petr Bauch
authored and
Petr Bauch
committed
Add building fresh symbols for snapshot temporaries
This is needed for example when referring to malloc(ed) variables. These are build as pointing to `tmp` variables.
1 parent 80a1bb5 commit f1185fb

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ void memory_snapshot_harness_generatort::add_init_section(
200200
: start_it)));
201201
}
202202

203+
const symbolt &memory_snapshot_harness_generatort::fresh_symbol_copy(
204+
const symbolt &snapshot_symbol,
205+
symbol_tablet &symbol_table) const
206+
{
207+
symbolt &tmp_symbol = get_fresh_aux_symbol(
208+
snapshot_symbol.type,
209+
"",
210+
id2string(snapshot_symbol.base_name),
211+
snapshot_symbol.location,
212+
snapshot_symbol.mode,
213+
symbol_table);
214+
tmp_symbol.is_static_lifetime = true;
215+
tmp_symbol.value = snapshot_symbol.value;
216+
217+
return tmp_symbol;
218+
}
219+
203220
code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(
204221
const symbol_tablet &snapshot,
205222
goto_modelt &goto_model) const
@@ -210,10 +227,16 @@ code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(
210227
code_blockt code;
211228
for(const auto &pair : snapshot)
212229
{
213-
const symbolt &symbol = pair.second;
214-
if(!symbol.is_static_lifetime)
230+
const symbolt &snapshot_symbol = pair.second;
231+
if(!snapshot_symbol.is_static_lifetime)
215232
continue;
216233

234+
symbol_tablet &symbol_table = goto_model.symbol_table;
235+
const symbolt &symbol =
236+
(symbol_table.lookup(snapshot_symbol.base_name) != nullptr)
237+
? snapshot_symbol
238+
: fresh_symbol_copy(snapshot_symbol, symbol_table);
239+
217240
if(variables_to_havoc.count(symbol.base_name) == 0)
218241
{
219242
code.add(code_assignt{symbol.symbol_expr(), symbol.value});

src/goto-harness/memory_snapshot_harness_generator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class memory_snapshot_harness_generatort : public goto_harness_generatort
117117
/// \param goto_model: Model where the modification takes place
118118
void add_init_section(goto_modelt &goto_model) const;
119119

120+
const symbolt &fresh_symbol_copy(
121+
const symbolt &snapshot_symbol,
122+
symbol_tablet &symbol_table) const;
123+
120124
/// For each global symbol in the \p snapshot symbol table either:
121125
/// 1) add \ref code_assignt assigning a value from the \p snapshot to the
122126
/// symbol

0 commit comments

Comments
 (0)