@@ -169,28 +169,40 @@ void validate_goto_modelt::check_called_functions()
169
169
class test_for_function_addresst : public const_expr_visitort
170
170
{
171
171
public:
172
- std::set<irep_idt> identifiers;
173
-
172
+ test_for_function_addresst (
173
+ const function_mapt &function_map,
174
+ const validation_modet &vm)
175
+ : function_map{function_map}, vm{vm}
176
+ {
177
+ }
174
178
void operator ()(const exprt &expr) override
175
179
{
176
180
if (expr.id () == ID_address_of)
177
181
{
178
- const exprt &pointee = to_address_of_expr (expr).object ();
182
+ const auto &pointee = to_address_of_expr (expr).object ();
179
183
if (pointee.id () == ID_symbol)
180
- identifiers.insert (to_symbol_expr (pointee).get_identifier ());
184
+ {
185
+ const auto &identifier = to_symbol_expr (pointee).get_identifier ();
186
+ DATA_CHECK (
187
+ vm,
188
+ function_map.find (identifier) != function_map.end (),
189
+ " every function whose address is taken must be in the "
190
+ " function map" );
191
+ }
181
192
}
182
193
}
183
194
184
- void clear ()
185
- {
186
- identifiers. clear () ;
187
- }
188
- } test_for_function_address;
195
+ private:
196
+ const function_mapt &function_map;
197
+ const validation_modet &vm ;
198
+ };
199
+ test_for_function_addresst test_for_function_address (function_map, vm) ;
189
200
190
201
for (const auto &fun : function_map)
191
202
{
192
203
for (auto &instr : fun.second .body .instructions )
193
204
{
205
+ // check functions that are called
194
206
if (instr.is_function_call ())
195
207
{
196
208
const auto &function_call = to_code_function_call (instr.code );
@@ -203,18 +215,9 @@ void validate_goto_modelt::check_called_functions()
203
215
" every function call callee must be in the function map" );
204
216
}
205
217
218
+ // check functions of which the address is taken
206
219
const exprt &src{instr.code };
207
220
src.visit (test_for_function_address);
208
- if (!test_for_function_address.identifiers .empty ())
209
- {
210
- for (auto &identifier : test_for_function_address.identifiers )
211
- DATA_CHECK (
212
- vm,
213
- function_map.find (identifier) != function_map.end (),
214
- " every function whose address is taken must be in the "
215
- " function map" );
216
- }
217
- test_for_function_address.clear ();
218
221
}
219
222
}
220
223
}
0 commit comments