Skip to content

Commit 889a84b

Browse files
authored
Merge pull request #7680 from tautschnig/cleanup/recreate-init
Factor out re-creating __CPROVER_initialize into a function
2 parents dd8e64a + 1909f3e commit 889a84b

11 files changed

+43
-88
lines changed

src/goto-cc/linker_script_merge.cpp

+4-13
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,11 @@ 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)
87+
88+
if(original_goto_model->can_produce_function(INITIALIZE_FUNCTION))
9089
{
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();
90+
recreate_initialize_function(
91+
*original_goto_model, log.get_message_handler());
10192
}
10293

10394
fail=goto_and_object_mismatch(linker_defined_symbols, linker_values);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ void dfcct::reinitialize_model()
560560
swap_and_wrap.get_swapped_functions(instrumented_functions);
561561

562562
log.status() << "Updating init function" << messaget::eom;
563-
utils.create_initialize_function();
564-
goto_model.goto_functions.update();
563+
if(goto_model.can_produce_function(INITIALIZE_FUNCTION))
564+
recreate_initialize_function(goto_model, message_handler);
565565
nondet_static(goto_model, to_exclude_from_nondet_static);
566566

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

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

-16
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

-4
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

+2-12
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,8 @@ 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+
if(goto_model.can_produce_function(INITIALIZE_FUNCTION))
214+
recreate_initialize_function(goto_model, message_handler);
225215
}
226216

227217
void is_fresh_baset::update_fn_call(

src/goto-instrument/stack_depth.cpp

+2-12
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,8 @@ 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+
if(goto_model.can_produce_function(INITIALIZE_FUNCTION))
44+
recreate_initialize_function(goto_model, message_handler);
5545

5646
return new_symbol.symbol_expr();
5747
}

src/goto-programs/link_to_library.cpp

+2-13
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,8 @@ void link_to_library(
159159
break;
160160
}
161161

162-
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-
}
162+
if(need_reinit && goto_model.can_produce_function(INITIALIZE_FUNCTION))
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

+2-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Date: December 2016
2222

2323
#include <linking/static_lifetime_init.h>
2424

25-
#include "goto_convert_functions.h"
2625
#include "goto_functions.h"
2726
#include "goto_model.h"
2827

@@ -132,18 +131,6 @@ void slice_global_inits(
132131
}
133132
}
134133

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-
}
134+
if(changed && goto_model.can_produce_function(INITIALIZE_FUNCTION))
135+
recreate_initialize_function(goto_model, message_handler);
149136
}

src/linking/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ add_library(linking ${sources})
33

44
generic_includes(linking)
55

6-
target_link_libraries(linking util)
6+
target_link_libraries(linking goto-programs util)

src/linking/static_lifetime_init.cpp

+21
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+
auto unloaded = goto_model.unload(INITIALIZE_FUNCTION);
169+
PRECONDITION(unloaded == 1);
170+
171+
static_lifetime_init(
172+
goto_model.symbol_table,
173+
goto_model.symbol_table.lookup_ref(INITIALIZE_FUNCTION).location);
174+
goto_convert(
175+
INITIALIZE_FUNCTION,
176+
goto_model.symbol_table,
177+
goto_model.goto_functions,
178+
message_handler);
179+
goto_model.goto_functions.update();
180+
}

src/linking/static_lifetime_init.h

+7
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. It is an
28+
/// error 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)