Skip to content

Commit 28ba192

Browse files
author
martin
committed
Strengthen the invariant on what are acceptable function calls.
1 parent 773bc86 commit 28ba192

File tree

1 file changed

+12
-50
lines changed

1 file changed

+12
-50
lines changed

src/analyses/ai.cpp

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -394,63 +394,25 @@ bool ai_baset::do_function_call_rec(
394394
{
395395
PRECONDITION(!goto_functions.function_map.empty());
396396

397-
// We can't really do this here -- we rely on
398-
// these being removed by some previous analysis.
399-
PRECONDITION(function.id() != ID_dereference);
400-
401-
// Can't be a function
397+
// This is quite a strong assumption on the well-formedness of the program.
398+
// It means function pointers must be removed before use.
402399
DATA_INVARIANT(
403-
function.id() != "NULL-object", "Function cannot be null object");
404-
DATA_INVARIANT(function.id() != ID_member, "Function cannot be struct field");
405-
DATA_INVARIANT(function.id() != ID_index, "Function cannot be array element");
400+
function.id() == ID_symbol,
401+
"Function pointers and indirect calls must be removed before analysis.");
406402

407403
bool new_data=false;
408404

409-
if(function.id()==ID_symbol)
410-
{
411-
const irep_idt &identifier = to_symbol_expr(function).get_identifier();
405+
const irep_idt &identifier = to_symbol_expr(function).get_identifier();
412406

413-
goto_functionst::function_mapt::const_iterator it=
414-
goto_functions.function_map.find(identifier);
407+
goto_functionst::function_mapt::const_iterator it =
408+
goto_functions.function_map.find(identifier);
415409

416-
if(it==goto_functions.function_map.end())
417-
throw "failed to find function "+id2string(identifier);
410+
DATA_INVARIANT(
411+
it != goto_functions.function_map.end(),
412+
"Function " + id2string(identifier) + "not in function map");
418413

419-
new_data=do_function_call(
420-
l_call, l_return,
421-
goto_functions,
422-
it,
423-
arguments,
424-
ns);
425-
}
426-
else if(function.id()==ID_if)
427-
{
428-
DATA_INVARIANT(function.operands().size() != 3, "if has three operands");
429-
430-
bool new_data1=
431-
do_function_call_rec(
432-
l_call, l_return,
433-
function.op1(),
434-
arguments,
435-
goto_functions,
436-
ns);
437-
438-
bool new_data2=
439-
do_function_call_rec(
440-
l_call, l_return,
441-
function.op2(),
442-
arguments,
443-
goto_functions,
444-
ns);
445-
446-
if(new_data1 || new_data2)
447-
new_data=true;
448-
}
449-
else
450-
{
451-
throw "unexpected function_call argument: "+
452-
function.id_string();
453-
}
414+
new_data =
415+
do_function_call(l_call, l_return, goto_functions, it, arguments, ns);
454416

455417
return new_data;
456418
}

0 commit comments

Comments
 (0)