Skip to content

Commit 9ac4f29

Browse files
author
Sonny Martin
committed
Improved function call check
1 parent 6ce3d9b commit 9ac4f29

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/goto-programs/validate_goto_model.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,28 +169,40 @@ void validate_goto_modelt::check_called_functions()
169169
class test_for_function_addresst : public const_expr_visitort
170170
{
171171
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+
}
174178
void operator()(const exprt &expr) override
175179
{
176180
if(expr.id() == ID_address_of)
177181
{
178-
const exprt &pointee = to_address_of_expr(expr).object();
182+
const auto &pointee = to_address_of_expr(expr).object();
179183
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+
}
181192
}
182193
}
183194

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);
189200

190201
for(const auto &fun : function_map)
191202
{
192203
for(auto &instr : fun.second.body.instructions)
193204
{
205+
// check functions that are called
194206
if(instr.is_function_call())
195207
{
196208
const auto &function_call = to_code_function_call(instr.code);
@@ -203,18 +215,9 @@ void validate_goto_modelt::check_called_functions()
203215
"every function call callee must be in the function map");
204216
}
205217

218+
// check functions of which the address is taken
206219
const exprt &src{instr.code};
207220
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();
218221
}
219222
}
220223
}

0 commit comments

Comments
 (0)