Skip to content

Commit c13efe0

Browse files
author
martin
committed
Strengthen the invariant on what are acceptable function calls.
1 parent 18a64b9 commit c13efe0

File tree

1 file changed

+10
-51
lines changed

1 file changed

+10
-51
lines changed

src/analyses/ai.cpp

+10-51
Original file line numberDiff line numberDiff line change
@@ -403,63 +403,22 @@ bool ai_baset::do_function_call_rec(
403403
{
404404
PRECONDITION(!goto_functions.function_map.empty());
405405

406-
// We can't really do this here -- we rely on
407-
// these being removed by some previous analysis.
408-
PRECONDITION(function.id() != ID_dereference);
409-
410-
// Can't be a function
411-
DATA_INVARIANT(
412-
function.id() != "NULL-object", "Function cannot be null object");
413-
DATA_INVARIANT(function.id() != ID_member, "Function cannot be struct field");
414-
DATA_INVARIANT(function.id() != ID_index, "Function cannot be array element");
406+
// This is quite a strong assumption on the well-formedness of the program.
407+
// It means function pointers must be removed before use.
408+
DATA_INVARIANT(function.id() == ID_symbol);
415409

416410
bool new_data=false;
417411

418-
if(function.id()==ID_symbol)
419-
{
420-
const irep_idt &identifier = to_symbol_expr(function).get_identifier();
412+
const irep_idt &identifier = to_symbol_expr(function).get_identifier();
421413

422-
goto_functionst::function_mapt::const_iterator it=
423-
goto_functions.function_map.find(identifier);
414+
goto_functionst::function_mapt::const_iterator it =
415+
goto_functions.function_map.find(identifier);
424416

425-
if(it==goto_functions.function_map.end())
426-
throw "failed to find function "+id2string(identifier);
417+
if(it == goto_functions.function_map.end())
418+
throw "failed to find function " + id2string(identifier);
427419

428-
new_data=do_function_call(
429-
l_call, l_return,
430-
goto_functions,
431-
it,
432-
arguments,
433-
ns);
434-
}
435-
else if(function.id()==ID_if)
436-
{
437-
DATA_INVARIANT(function.operands().size() != 3, "if has three operands");
438-
439-
bool new_data1=
440-
do_function_call_rec(
441-
l_call, l_return,
442-
function.op1(),
443-
arguments,
444-
goto_functions,
445-
ns);
446-
447-
bool new_data2=
448-
do_function_call_rec(
449-
l_call, l_return,
450-
function.op2(),
451-
arguments,
452-
goto_functions,
453-
ns);
454-
455-
if(new_data1 || new_data2)
456-
new_data=true;
457-
}
458-
else
459-
{
460-
throw "unexpected function_call argument: "+
461-
function.id_string();
462-
}
420+
new_data =
421+
do_function_call(l_call, l_return, goto_functions, it, arguments, ns);
463422

464423
return new_data;
465424
}

0 commit comments

Comments
 (0)