CBMC
is_threaded.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Over-approximate Concurrency for Threaded Goto Programs
4 
5 Author: Daniel Kroening
6 
7 Date: October 2012
8 
9 \*******************************************************************/
10 
13 
14 #include "is_threaded.h"
15 
16 #include "ai.h"
17 
19 {
20 public:
21  bool reachable;
23 
25  reachable(false),
26  is_threaded(false)
27  {
28  // this is bottom
29  }
30 
32  {
33  INVARIANT(src.reachable,
34  "Abstract states are only merged at reachable locations");
35 
36  bool old_reachable=reachable;
37  bool old_is_threaded=is_threaded;
38 
39  reachable=true;
41 
42  return old_reachable!=reachable ||
43  old_is_threaded!=is_threaded;
44  }
45 
46  void transform(
47  const irep_idt &,
48  trace_ptrt trace_from,
49  const irep_idt &,
50  trace_ptrt,
51  ai_baset &,
52  const namespacet &) override
53  {
54  locationt from{trace_from->current_location()};
55 
57  "Transformers are only applied at reachable locations");
58 
59  if(from->is_start_thread())
60  is_threaded=true;
61  }
62 
63  void make_bottom() final override
64  {
65  reachable=false;
66  is_threaded=false;
67  }
68 
69  void make_top() final override
70  {
71  reachable=true;
72  is_threaded=true;
73  }
74 
75  void make_entry() final override
76  {
77  reachable=true;
78  is_threaded=false;
79  }
80 
81  bool is_bottom() const override final
82  {
84  "A location cannot be threaded if it is not reachable.");
85 
86  return !reachable;
87  }
88 
89  bool is_top() const override final
90  {
91  return reachable && is_threaded;
92  }
93 };
94 
95 void is_threadedt::compute(const goto_functionst &goto_functions)
96 {
97  // the analysis doesn't actually use the namespace, fake one
98  symbol_tablet symbol_table;
99  const namespacet ns(symbol_table);
100 
101  ait<is_threaded_domaint> is_threaded_analysis;
102 
103  is_threaded_analysis(goto_functions, ns);
104 
105  for(const auto &gf_entry : goto_functions.function_map)
106  {
107  forall_goto_program_instructions(i_it, gf_entry.second.body)
108  {
109  auto domain_ptr = is_threaded_analysis.abstract_state_before(i_it);
110  if(static_cast<const is_threaded_domaint &>(*domain_ptr).is_threaded)
111  is_threaded_set.insert(i_it);
112  }
113  }
114 }
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
symbol_tablet
The symbol table.
Definition: symbol_table.h:13
is_threaded_domaint::make_bottom
void make_bottom() final override
no states
Definition: is_threaded.cpp:63
is_threaded_domaint::make_top
void make_top() final override
all states – the analysis doesn't use this, and domains may refuse to implement it.
Definition: is_threaded.cpp:69
is_threaded_domaint::is_threaded_domaint
is_threaded_domaint()
Definition: is_threaded.cpp:24
ait
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition: ai.h:563
ai_baset::abstract_state_before
virtual cstate_ptrt abstract_state_before(locationt l) const
Get a copy of the abstract state before the given instruction, without needing to know what kind of d...
Definition: ai.h:223
is_threaded_domaint::make_entry
void make_entry() final override
Make this domain a reasonable entry-point state.
Definition: is_threaded.cpp:75
goto_functionst::function_map
function_mapt function_map
Definition: goto_functions.h:29
ai_domain_baset::trace_ptrt
ai_history_baset::trace_ptrt trace_ptrt
Definition: ai_domain.h:74
is_threaded_domaint
Definition: is_threaded.cpp:18
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
DATA_INVARIANT
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
Definition: invariant.h:510
is_threaded_domaint::is_bottom
bool is_bottom() const override final
Definition: is_threaded.cpp:81
is_threaded_domaint::merge
bool merge(const is_threaded_domaint &src, trace_ptrt, trace_ptrt)
Definition: is_threaded.cpp:31
is_threaded.h
is_threadedt::compute
void compute(const goto_functionst &goto_functions)
Definition: is_threaded.cpp:95
is_threadedt::is_threaded_set
is_threaded_sett is_threaded_set
Definition: is_threaded.h:48
ai.h
is_threaded_domaint::transform
void transform(const irep_idt &, trace_ptrt trace_from, const irep_idt &, trace_ptrt, ai_baset &, const namespacet &) override
how function calls are treated: a) there is an edge from each call site to the function head b) there...
Definition: is_threaded.cpp:46
is_threaded_domaint::is_top
bool is_top() const override final
Definition: is_threaded.cpp:89
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:24
ai_domain_baset::locationt
goto_programt::const_targett locationt
Definition: ai_domain.h:73
ai_baset
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition: ai.h:118
is_threaded_domaint::reachable
bool reachable
Definition: is_threaded.cpp:21
is_threaded_domaint::is_threaded
bool is_threaded
Definition: is_threaded.cpp:22
ai_domain_baset
The interface offered by a domain, allows code to manipulate domains without knowing their exact type...
Definition: ai_domain.h:54
forall_goto_program_instructions
#define forall_goto_program_instructions(it, program)
Definition: goto_program.h:1229
validation_modet::INVARIANT
@ INVARIANT