@@ -422,56 +422,22 @@ remove_function_pointerst::get_function_pointer_targets(
422
422
}
423
423
return functions;
424
424
}
425
+
425
426
void remove_function_pointerst::remove_function_pointer (
426
427
goto_programt &goto_program,
427
428
const irep_idt &function_id,
428
429
goto_programt::targett target)
429
430
{
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);
436
434
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)
454
436
{
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 ;
460
437
}
461
438
else
462
439
{
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 )
475
441
{
476
442
auto call = target->get_function_call ();
477
443
call.function () = *functions.cbegin ();
@@ -492,27 +458,6 @@ void remove_function_pointerst::remove_function_pointer(
492
458
// Since we don't want to do that, we abort.
493
459
return ;
494
460
}
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
- }
516
461
}
517
462
518
463
remove_function_pointer (goto_program, function_id, target, functions);
0 commit comments