Skip to content

Commit f86d17b

Browse files
author
martin
committed
Create a new kind of abstract interpreter that does function-local analysis
1 parent 8346a3f commit f86d17b

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

src/analyses/ai.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ bool ai_baset::visit_edge(
405405
return return_value;
406406
}
407407

408-
bool ai_baset::visit_edge_function_call(
408+
bool ai_localt::visit_edge_function_call(
409409
const irep_idt &calling_function_id,
410410
trace_ptrt p_call,
411411
locationt l_return,
@@ -416,11 +416,11 @@ bool ai_baset::visit_edge_function_call(
416416
const namespacet &ns)
417417
{
418418
messaget log(message_handler);
419-
log.progress() << "ai_baset::visit_edge_function_call from "
419+
log.progress() << "ai_localt::visit_edge_function_call from "
420420
<< p_call->current_location()->location_number << " to "
421421
<< l_return->location_number << messaget::eom;
422422

423-
// The default implementation is not interprocedural
423+
// This implementation is not interprocedural
424424
// so the effects of the call are approximated but nothing else
425425
return visit_edge(
426426
calling_function_id,
@@ -531,6 +531,27 @@ bool ai_baset::visit_end_function(
531531
return false;
532532
}
533533

534+
void ai_localt::
535+
operator()(const goto_functionst &goto_functions, const namespacet &ns)
536+
{
537+
initialize(goto_functions);
538+
for(const auto &gf_entry : goto_functions.function_map)
539+
{
540+
if(gf_entry.second.body_available())
541+
{
542+
trace_ptrt p = entry_state(gf_entry.second.body);
543+
fixedpoint(p, gf_entry.first, gf_entry.second.body, goto_functions, ns);
544+
}
545+
}
546+
finalize();
547+
}
548+
549+
void ai_localt::operator()(const abstract_goto_modelt &goto_model)
550+
{
551+
const namespacet ns(goto_model.get_symbol_table());
552+
operator()(goto_model.get_goto_functions(), ns);
553+
}
554+
534555
void ai_recursive_interproceduralt::
535556
operator()(const goto_functionst &goto_functions, const namespacet &ns)
536557
{

src/analyses/ai.h

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ class ai_baset
469469
working_sett &working_set,
470470
const goto_programt &callee,
471471
const goto_functionst &goto_functions,
472-
const namespacet &ns);
472+
const namespacet &ns) = 0;
473473

474474
/// For creating history objects
475475
std::unique_ptr<ai_history_factory_baset> history_factory;
@@ -505,6 +505,40 @@ class ai_baset
505505
message_handlert &message_handler;
506506
};
507507

508+
// Perform function local analysis on all functions in a program.
509+
// No interprocedural analysis other than what a domain does when
510+
// visit()'ing an edge that skips a function call.
511+
class ai_localt : public ai_baset
512+
{
513+
public:
514+
ai_localt(
515+
std::unique_ptr<ai_history_factory_baset> &&hf,
516+
std::unique_ptr<ai_domain_factory_baset> &&df,
517+
std::unique_ptr<ai_storage_baset> &&st,
518+
message_handlert &mh)
519+
: ai_baset(std::move(hf), std::move(df), std::move(st), mh)
520+
{
521+
}
522+
523+
// Handle every function independently
524+
void operator()(const goto_functionst &goto_functions, const namespacet &ns)
525+
override;
526+
void operator()(const abstract_goto_modelt &goto_model) override;
527+
528+
protected:
529+
// Implement the function that handles a single function call edge
530+
// by a single edge that gets the domain to approximate the whole function call
531+
bool visit_edge_function_call(
532+
const irep_idt &calling_function_id,
533+
trace_ptrt p_call,
534+
locationt l_return,
535+
const irep_idt &callee_function_id,
536+
working_sett &working_set,
537+
const goto_programt &callee,
538+
const goto_functionst &goto_functions,
539+
const namespacet &ns) override;
540+
};
541+
508542
// Perform interprocedural analysis by simply recursing in the interpreter
509543
// This can lead to a call stack overflow if the domain has a large height
510544
class ai_recursive_interproceduralt : public ai_baset
@@ -525,7 +559,8 @@ class ai_recursive_interproceduralt : public ai_baset
525559
void operator()(const abstract_goto_modelt &goto_model) override;
526560

527561
protected:
528-
// Override the function that handles a single function call edge
562+
// Implement the function that handles a single function call edge
563+
// by a recursive call to fixpoint
529564
bool visit_edge_function_call(
530565
const irep_idt &calling_function_id,
531566
trace_ptrt p_call,

0 commit comments

Comments
 (0)