@@ -19,7 +19,7 @@ Author: Daniel Kroening, kroening@kroening.com
1919#include " link_goto_model.h"
2020
2121// / 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 (
2323 goto_modelt &goto_model,
2424 message_handlert &message_handler,
2525 const std::function<void (
@@ -49,6 +49,7 @@ static optionalt<replace_symbolt::expr_mapt> add_one_function(
4949 }
5050
5151 // check whether additional initialization may be required
52+ bool init_required = false ;
5253 if (
5354 goto_model.goto_functions .function_map .find (INITIALIZE_FUNCTION) !=
5455 goto_model.goto_functions .function_map .end ())
@@ -60,13 +61,15 @@ static optionalt<replace_symbolt::expr_mapt> add_one_function(
6061 !entry.second .is_macro && entry.second .type .id () != ID_code &&
6162 !goto_model.symbol_table .has_symbol (entry.first ))
6263 {
63- goto_model. unload (INITIALIZE_FUNCTION) ;
64+ init_required = true ;
6465 break ;
6566 }
6667 }
6768 }
6869
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};
7073}
7174
7275// / Complete missing function definitions using the \p library.
@@ -95,9 +98,7 @@ void link_to_library(
9598 // forward declarations, or perhaps even cases of missing forward
9699 // declarations) may result in type changes to objects.
97100 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 ;
101102
102103 while (true )
103104 {
@@ -125,8 +126,10 @@ void link_to_library(
125126 changed = true ;
126127 added_functions.insert (id);
127128
128- auto updates_opt =
129+ auto one_result =
129130 add_one_function (goto_model, message_handler, library, id);
131+ auto updates_opt = one_result.first ;
132+ need_reinit |= one_result.second ;
130133 if (!updates_opt.has_value ())
131134 {
132135 messaget log{message_handler};
@@ -143,11 +146,9 @@ void link_to_library(
143146 break ;
144147 }
145148
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)
150150 {
151+ goto_model.unload (INITIALIZE_FUNCTION);
151152 static_lifetime_init (
152153 goto_model.symbol_table ,
153154 goto_model.symbol_table .lookup_ref (INITIALIZE_FUNCTION).location );
0 commit comments