19
19
#include " link_goto_model.h"
20
20
21
21
// / Try to add \p missing_function from \p library to \p goto_model.
22
- static optionalt<replace_symbolt::expr_mapt> add_one_function (
22
+ static std::pair< optionalt<replace_symbolt::expr_mapt>, bool > add_one_function (
23
23
goto_modelt &goto_model,
24
24
message_handlert &message_handler,
25
25
const std::function<void (
@@ -49,6 +49,7 @@ static optionalt<replace_symbolt::expr_mapt> add_one_function(
49
49
}
50
50
51
51
// check whether additional initialization may be required
52
+ bool init_required = false ;
52
53
if (
53
54
goto_model.goto_functions .function_map .find (INITIALIZE_FUNCTION) !=
54
55
goto_model.goto_functions .function_map .end ())
@@ -60,13 +61,15 @@ static optionalt<replace_symbolt::expr_mapt> add_one_function(
60
61
!entry.second .is_macro && entry.second .type .id () != ID_code &&
61
62
!goto_model.symbol_table .has_symbol (entry.first ))
62
63
{
63
- goto_model. unload (INITIALIZE_FUNCTION) ;
64
+ init_required = true ;
64
65
break ;
65
66
}
66
67
}
67
68
}
68
69
69
- return link_goto_model (goto_model, std::move (library_model), message_handler);
70
+ return {
71
+ link_goto_model (goto_model, std::move (library_model), message_handler),
72
+ init_required};
70
73
}
71
74
72
75
// / Complete missing function definitions using the \p library.
@@ -95,9 +98,7 @@ void link_to_library(
95
98
// forward declarations, or perhaps even cases of missing forward
96
99
// declarations) may result in type changes to objects.
97
100
replace_symbolt::expr_mapt object_type_updates;
98
- const bool had_init =
99
- goto_model.goto_functions .function_map .find (INITIALIZE_FUNCTION) !=
100
- goto_model.goto_functions .function_map .end ();
101
+ bool need_reinit = false ;
101
102
102
103
while (true )
103
104
{
@@ -125,8 +126,10 @@ void link_to_library(
125
126
changed = true ;
126
127
added_functions.insert (id);
127
128
128
- auto updates_opt =
129
+ auto one_result =
129
130
add_one_function (goto_model, message_handler, library, id);
131
+ auto updates_opt = one_result.first ;
132
+ need_reinit |= one_result.second ;
130
133
if (!updates_opt.has_value ())
131
134
{
132
135
messaget log {message_handler};
@@ -143,11 +146,9 @@ void link_to_library(
143
146
break ;
144
147
}
145
148
146
- if (
147
- had_init &&
148
- goto_model.goto_functions .function_map .find (INITIALIZE_FUNCTION) ==
149
- goto_model.goto_functions .function_map .end ())
149
+ if (need_reinit)
150
150
{
151
+ goto_model.unload (INITIALIZE_FUNCTION);
151
152
static_lifetime_init (
152
153
goto_model.symbol_table ,
153
154
goto_model.symbol_table .lookup_ref (INITIALIZE_FUNCTION).location );
0 commit comments