Skip to content

Commit 0780955

Browse files
committed
Factor out re-creating __CPROVER_initialize into a function
This avoids repeating the almost-same code in several places, and moves a helper that is not DFCC-specific to the global context.
1 parent 82c698a commit 0780955

File tree

10 files changed

+36
-87
lines changed

10 files changed

+36
-87
lines changed

src/goto-cc/linker_script_merge.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,8 @@ int linker_script_merget::add_linker_script_definitions()
8484
<< messaget::eom;
8585
return fail;
8686
}
87-
if(
88-
original_goto_model->goto_functions.function_map.erase(
89-
INITIALIZE_FUNCTION) != 0)
90-
{
91-
static_lifetime_init(
92-
original_goto_model->symbol_table,
93-
original_goto_model->symbol_table.lookup_ref(INITIALIZE_FUNCTION)
94-
.location);
95-
goto_convert(
96-
INITIALIZE_FUNCTION,
97-
original_goto_model->symbol_table,
98-
original_goto_model->goto_functions,
99-
log.get_message_handler());
100-
original_goto_model->goto_functions.update();
101-
}
87+
88+
recreate_initialize_function(*original_goto_model, log.get_message_handler());
10289

10390
fail=goto_and_object_mismatch(linker_defined_symbols, linker_values);
10491
if(fail!=0)

src/goto-instrument/contracts/dynamic-frames/dfcc.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,7 @@ void dfcct::reinitialize_model()
539539
swap_and_wrap.get_swapped_functions(instrumented_functions);
540540

541541
log.status() << "Updating init function" << messaget::eom;
542-
utils.create_initialize_function();
543-
goto_model.goto_functions.update();
542+
recreate_initialize_function(goto_model, message_handler);
544543
nondet_static(goto_model, to_exclude_from_nondet_static);
545544

546545
// Initialize the map of instrumented functions by adding extra instructions

src/goto-instrument/contracts/dynamic-frames/dfcc_utils.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,6 @@ const symbolt &dfcc_utilst::create_static_symbol(
140140
return symbol;
141141
}
142142

143-
void dfcc_utilst::create_initialize_function()
144-
{
145-
if(goto_model.goto_functions.function_map.erase(INITIALIZE_FUNCTION) != 0)
146-
{
147-
static_lifetime_init(
148-
goto_model.symbol_table,
149-
goto_model.symbol_table.lookup_ref(INITIALIZE_FUNCTION).location);
150-
goto_convert(
151-
INITIALIZE_FUNCTION,
152-
goto_model.symbol_table,
153-
goto_model.goto_functions,
154-
message_handler);
155-
goto_model.goto_functions.update();
156-
}
157-
}
158-
159143
void dfcc_utilst::fix_parameters_symbols(const irep_idt &function_id)
160144
{
161145
auto &function_symbol = get_function_symbol(function_id);

src/goto-instrument/contracts/dynamic-frames/dfcc_utils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ class dfcc_utilst
8282
const exprt &initial_value,
8383
const bool no_nondet_initialization = true);
8484

85-
/// Regenerates the CPROVER_INITIALIZE function which defines all global
86-
/// statics of the goto model.
87-
void create_initialize_function();
88-
8985
/// Creates a new parameter symbol for the given function_id
9086
const symbolt &create_new_parameter_symbol(
9187
const irep_idt &function_id,

src/goto-instrument/contracts/memory_predicates.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,7 @@ void is_fresh_baset::add_declarations(const std::string &decl_string)
210210
}
211211
}
212212

213-
if(goto_model.goto_functions.function_map.erase(INITIALIZE_FUNCTION) != 0)
214-
{
215-
static_lifetime_init(
216-
goto_model.symbol_table,
217-
goto_model.symbol_table.lookup_ref(INITIALIZE_FUNCTION).location);
218-
goto_convert(
219-
INITIALIZE_FUNCTION,
220-
goto_model.symbol_table,
221-
goto_model.goto_functions,
222-
log.get_message_handler());
223-
goto_model.goto_functions.update();
224-
}
213+
recreate_initialize_function(goto_model, message_handler);
225214
}
226215

227216
void is_fresh_baset::update_fn_call(

src/goto-instrument/stack_depth.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,7 @@ static symbol_exprt add_stack_depth_symbol(
4040
bool failed = goto_model.symbol_table.add(new_symbol);
4141
CHECK_RETURN(!failed);
4242

43-
if(goto_model.goto_functions.function_map.erase(INITIALIZE_FUNCTION) != 0)
44-
{
45-
static_lifetime_init(
46-
goto_model.symbol_table,
47-
goto_model.symbol_table.lookup_ref(INITIALIZE_FUNCTION).location);
48-
goto_convert(
49-
INITIALIZE_FUNCTION,
50-
goto_model.symbol_table,
51-
goto_model.goto_functions,
52-
message_handler);
53-
goto_model.goto_functions.update();
54-
}
43+
recreate_initialize_function(goto_model, message_handler);
5544

5645
return new_symbol.symbol_expr();
5746
}

src/goto-programs/link_to_library.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,7 @@ void link_to_library(
160160
}
161161

162162
if(need_reinit)
163-
{
164-
goto_model.unload(INITIALIZE_FUNCTION);
165-
static_lifetime_init(
166-
goto_model.symbol_table,
167-
goto_model.symbol_table.lookup_ref(INITIALIZE_FUNCTION).location);
168-
goto_convert(
169-
INITIALIZE_FUNCTION,
170-
goto_model.symbol_table,
171-
goto_model.goto_functions,
172-
message_handler);
173-
goto_model.goto_functions.update();
174-
}
163+
recreate_initialize_function(goto_model, message_handler);
175164

176165
if(!object_type_updates.empty())
177166
finalize_linking(goto_model, object_type_updates);

src/goto-programs/slice_global_inits.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,6 @@ void slice_global_inits(
132132
}
133133
}
134134

135-
if(
136-
changed &&
137-
goto_model.goto_functions.function_map.erase(INITIALIZE_FUNCTION) != 0)
138-
{
139-
static_lifetime_init(
140-
goto_model.symbol_table,
141-
goto_model.symbol_table.lookup_ref(INITIALIZE_FUNCTION).location);
142-
goto_convert(
143-
INITIALIZE_FUNCTION,
144-
goto_model.symbol_table,
145-
goto_model.goto_functions,
146-
message_handler);
147-
goto_model.goto_functions.update();
148-
}
135+
if(changed)
136+
recreate_initialize_function(goto_model, message_handler);
149137
}

src/linking/static_lifetime_init.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Author: Daniel Kroening, [email protected]
1616
#include <util/std_code.h>
1717
#include <util/symbol_table_base.h>
1818

19+
#include <goto-programs/goto_convert_functions.h>
20+
#include <goto-programs/goto_model.h>
21+
1922
#include <set>
2023

2124
static optionalt<codet> static_lifetime_init(
@@ -157,3 +160,21 @@ void static_lifetime_init(
157160
}
158161
}
159162
}
163+
164+
void recreate_initialize_function(
165+
goto_modelt &goto_model,
166+
message_handlert &message_handler)
167+
{
168+
if(goto_model.unload(INITIALIZE_FUNCTION) != 0)
169+
{
170+
static_lifetime_init(
171+
goto_model.symbol_table,
172+
goto_model.symbol_table.lookup_ref(INITIALIZE_FUNCTION).location);
173+
goto_convert(
174+
INITIALIZE_FUNCTION,
175+
goto_model.symbol_table,
176+
goto_model.goto_functions,
177+
message_handler);
178+
goto_model.goto_functions.update();
179+
}
180+
}

src/linking/static_lifetime_init.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Author: Daniel Kroening, [email protected]
1212

1313
#include <util/cprover_prefix.h>
1414

15+
class goto_modelt;
16+
class message_handlert;
1517
class source_locationt;
1618
class symbol_table_baset;
1719

@@ -21,4 +23,9 @@ void static_lifetime_init(
2123

2224
#define INITIALIZE_FUNCTION CPROVER_PREFIX "initialize"
2325

26+
/// Regenerates the CPROVER_INITIALIZE function, which initializes all
27+
/// non-function symbols of the goto model that have static lifetime. This is a
28+
/// no-op if CPROVER_INITIALIZE was not present beforehand.
29+
void recreate_initialize_function(goto_modelt &, message_handlert &);
30+
2431
#endif // CPROVER_LINKING_STATIC_LIFETIME_INIT_H

0 commit comments

Comments
 (0)