Skip to content

Commit 3674dcc

Browse files
committed
Clean-up harnesses in testing symbol init-ability
also add mode to memory-snapshot.
1 parent 32cde1b commit 3674dcc

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Author: Diffblue Ltd.
1111
#include <util/allocate_objects.h>
1212
#include <util/arith_tools.h>
1313
#include <util/exception_utils.h>
14-
#include <util/prefix.h>
1514
#include <util/std_code.h>
1615
#include <util/std_expr.h>
1716
#include <util/string2int.h>
@@ -213,10 +212,7 @@ void function_call_harness_generatort::implt::generate_nondet_globals(
213212
for(const auto &symbol_table_entry : *symbol_table)
214213
{
215214
const auto &symbol = symbol_table_entry.second;
216-
if(
217-
symbol.is_static_lifetime && symbol.is_lvalue &&
218-
symbol.type.id() != ID_code &&
219-
!has_prefix(id2string(symbol.name), CPROVER_PREFIX))
215+
if(recursive_initialization->is_initialization_allowed(symbol))
220216
{
221217
globals.push_back(symbol.symbol_expr());
222218
}

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(
231231
for(auto pair : snapshot)
232232
{
233233
const auto name = id2string(pair.first);
234-
if(name.find(CPROVER_PREFIX) != 0)
234+
if(!has_prefix(name, CPROVER_PREFIX))
235235
ordered_snapshot_symbols.push_back(pair);
236236
}
237237

@@ -249,7 +249,22 @@ code_blockt memory_snapshot_harness_generatort::add_assignments_to_globals(
249249
pointer_depth(right.second.symbol_expr().type());
250250
});
251251

252-
code_blockt code;
252+
code_blockt code{};
253+
254+
// add initialization for existing globals
255+
for(const auto &pair : goto_model.symbol_table)
256+
{
257+
const auto &global_symbol = pair.second;
258+
if(
259+
global_symbol.is_static_lifetime && global_symbol.is_lvalue &&
260+
global_symbol.type.id() != ID_code)
261+
{
262+
auto symeexr = global_symbol.symbol_expr();
263+
if(symeexr.type() == global_symbol.value.type())
264+
code.add(code_assignt{symeexr, global_symbol.value});
265+
}
266+
}
267+
253268
for(const auto &pair : ordered_snapshot_symbols)
254269
{
255270
const symbolt &snapshot_symbol = pair.second;
@@ -374,6 +389,7 @@ void memory_snapshot_harness_generatort::generate(
374389

375390
const symbolt *called_function_symbol =
376391
symbol_table.lookup(entry_location.function_name);
392+
recursive_initialization_config.mode = called_function_symbol->mode;
377393

378394
// introduce a symbol for a Boolean variable to indicate the point at which
379395
// the function initialisation is completed

src/goto-harness/recursive_initialization.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Diffblue Ltd.
1616
#include <util/expr.h>
1717
#include <util/message.h>
1818
#include <util/optional.h>
19+
#include <util/prefix.h>
1920
#include <util/std_types.h>
2021

2122
#include "function_harness_generator_options.h"
@@ -71,6 +72,14 @@ class recursive_initializationt
7172
const recursion_sett &known_tags,
7273
code_blockt &body);
7374

75+
bool is_initialization_allowed(const symbolt &symbol)
76+
{
77+
return (
78+
symbol.is_static_lifetime && symbol.is_lvalue &&
79+
symbol.type.id() != ID_code &&
80+
!has_prefix(id2string(symbol.name), CPROVER_PREFIX));
81+
}
82+
7483
private:
7584
const recursive_initialization_configt initialization_config;
7685
goto_modelt &goto_model;

0 commit comments

Comments
 (0)