Skip to content

Commit b10d219

Browse files
committed
Re-implement remove_function_pointers
Using the new candidate-collecting function.
1 parent 4bd28ae commit b10d219

File tree

1 file changed

+6
-61
lines changed

1 file changed

+6
-61
lines changed

src/goto-programs/remove_function_pointers.cpp

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -422,56 +422,22 @@ remove_function_pointerst::get_function_pointer_targets(
422422
}
423423
return functions;
424424
}
425+
425426
void remove_function_pointerst::remove_function_pointer(
426427
goto_programt &goto_program,
427428
const irep_idt &function_id,
428429
goto_programt::targett target)
429430
{
430-
const code_function_callt &code = target->get_function_call();
431-
432-
const auto &function = to_dereference_expr(code.function());
433-
434-
// this better have the right type
435-
code_typet call_type=to_code_type(function.type());
431+
goto_programt::const_targett const_target = target;
432+
const auto functions =
433+
get_function_pointer_targets(goto_program, const_target);
436434

437-
// refine the type in case the forward declaration was incomplete
438-
if(call_type.has_ellipsis() &&
439-
call_type.parameters().empty())
440-
{
441-
call_type.remove_ellipsis();
442-
forall_expr(it, code.arguments())
443-
call_type.parameters().push_back(
444-
code_typet::parametert(it->type()));
445-
}
446-
447-
bool found_functions;
448-
449-
const exprt &pointer = function.pointer();
450-
remove_const_function_pointerst::functionst functions;
451-
does_remove_constt const_removal_check(goto_program, ns);
452-
const auto does_remove_const = const_removal_check();
453-
if(does_remove_const.first)
435+
if(does_remove_const_first)
454436
{
455-
log.warning().source_location = does_remove_const.second;
456-
log.warning() << "cast from const to non-const pointer found, "
457-
<< "only worst case function pointer removal will be done."
458-
<< messaget::eom;
459-
found_functions=false;
460437
}
461438
else
462439
{
463-
remove_const_function_pointerst fpr(
464-
log.get_message_handler(), ns, symbol_table);
465-
466-
found_functions=fpr(pointer, functions);
467-
468-
// if found_functions is false, functions should be empty
469-
// however, it is possible for found_functions to be true and functions
470-
// to be empty (this happens if the pointer can only resolve to the null
471-
// pointer)
472-
CHECK_RETURN(found_functions || functions.empty());
473-
474-
if(functions.size()==1)
440+
if(functions.size() == 1)
475441
{
476442
auto call = target->get_function_call();
477443
call.function() = *functions.cbegin();
@@ -492,27 +458,6 @@ void remove_function_pointerst::remove_function_pointer(
492458
// Since we don't want to do that, we abort.
493459
return;
494460
}
495-
496-
bool return_value_used=code.lhs().is_not_nil();
497-
498-
// get all type-compatible functions
499-
// whose address is ever taken
500-
for(const auto &t : type_map)
501-
{
502-
// address taken?
503-
if(address_taken.find(t.first)==address_taken.end())
504-
continue;
505-
506-
// type-compatible?
507-
if(!is_type_compatible(return_value_used, call_type, t.second))
508-
continue;
509-
510-
if(t.first=="pthread_mutex_cleanup")
511-
continue;
512-
513-
symbol_exprt expr(t.first, t.second);
514-
functions.insert(expr);
515-
}
516461
}
517462

518463
remove_function_pointer(goto_program, function_id, target, functions);

0 commit comments

Comments
 (0)