CBMC
ssa_step.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Symbolic Execution
4 
5 Author: Romain Brenguier <romain.brenguier@diffblue.com>
6 
7 *******************************************************************/
8 
9 #include "ssa_step.h"
10 
11 #include <util/format_expr.h>
12 #include <util/namespace.h>
13 
14 void SSA_stept::output(std::ostream &out) const
15 {
16  out << "Thread " << source.thread_nr;
17 
18  if(source.pc->source_location().is_not_nil())
19  out << " " << source.pc->source_location() << '\n';
20  else
21  out << '\n';
22 
23  switch(type)
24  {
26  out << "ASSERT " << format(cond_expr) << '\n';
27  break;
29  out << "ASSUME " << format(cond_expr) << '\n';
30  break;
32  out << "LOCATION" << '\n';
33  break;
35  out << "INPUT" << '\n';
36  break;
38  out << "OUTPUT" << '\n';
39  break;
40 
42  out << "DECL" << '\n';
43  out << format(ssa_lhs) << '\n';
44  break;
45 
47  out << "ASSIGNMENT (";
48  switch(assignment_type)
49  {
51  out << "HIDDEN";
52  break;
54  out << "STATE";
55  break;
57  out << "VISIBLE_ACTUAL_PARAMETER";
58  break;
60  out << "HIDDEN_ACTUAL_PARAMETER";
61  break;
63  out << "PHI";
64  break;
66  out << "GUARD";
67  break;
68  default:
69  {
70  }
71  }
72 
73  out << ")\n";
74  break;
75 
77  out << "DEAD\n";
78  break;
80  out << "FUNCTION_CALL\n";
81  break;
83  out << "FUNCTION_RETURN\n";
84  break;
86  out << "CONSTRAINT\n";
87  break;
89  out << "SHARED READ\n";
90  break;
92  out << "SHARED WRITE\n";
93  break;
95  out << "ATOMIC_BEGIN\n";
96  break;
98  out << "AUTOMIC_END\n";
99  break;
101  out << "SPAWN\n";
102  break;
104  out << "MEMORY_BARRIER\n";
105  break;
107  out << "IF " << format(cond_expr) << " GOTO\n";
108  break;
109 
111  UNREACHABLE;
112  }
113 
114  if(is_assert() || is_assume() || is_assignment() || is_constraint())
115  out << format(cond_expr) << '\n';
116 
117  if(is_assert() || is_constraint())
118  out << comment << '\n';
119 
121  out << format(ssa_lhs) << '\n';
122 
123  out << "Guard: " << format(guard) << '\n';
124 }
125 
129 void SSA_stept::validate(const namespacet &ns, const validation_modet vm) const
130 {
131  validate_full_expr(guard, ns, vm);
132 
133  switch(type)
134  {
136  DATA_CHECK(vm, !property_id.empty(), "missing property id in assert step");
140  validate_full_expr(cond_expr, ns, vm);
141  break;
143  validate_full_expr(ssa_lhs, ns, vm);
146  break;
148  validate_full_expr(ssa_lhs, ns, vm);
151  validate_full_expr(ssa_rhs, ns, vm);
152  DATA_CHECK(
153  vm,
155  "Type inequality in SSA assignment\nlhs-type: " +
157  "\nrhs-type: " + ssa_rhs.type().id_string());
158  break;
161  for(const auto &expr : io_args)
162  validate_full_expr(expr, ns, vm);
163  break;
165  for(const auto &expr : ssa_function_arguments)
166  validate_full_expr(expr, ns, vm);
168  {
169  const symbolt *symbol;
170  DATA_CHECK(
171  vm,
172  called_function.empty() || !ns.lookup(called_function, symbol),
173  "unknown function identifier " + id2string(called_function));
174  }
175  break;
185  break;
186  }
187 }
188 
190  symex_targett::sourcet source,
191  exprt _guard,
192  ssa_exprt _ssa_lhs,
193  exprt _ssa_full_lhs,
194  exprt _original_full_lhs,
195  exprt _ssa_rhs,
196  symex_targett::assignment_typet _assignment_type)
197  : SSA_stept(source, goto_trace_stept::typet::ASSIGNMENT)
198 {
199  guard = std::move(_guard);
200  ssa_lhs = std::move(_ssa_lhs);
201  ssa_full_lhs = std::move(_ssa_full_lhs);
202  original_full_lhs = std::move(_original_full_lhs);
203  ssa_rhs = std::move(_ssa_rhs);
204  assignment_type = _assignment_type;
207  assignment_type !=
209 }
SSA_assignment_stept(symex_targett::sourcet source, exprt guard, ssa_exprt ssa_lhs, exprt ssa_full_lhs, exprt original_full_lhs, exprt ssa_rhs, symex_targett::assignment_typet assignment_type)
Definition: ssa_step.cpp:189
Single SSA step in the equation.
Definition: ssa_step.h:47
irep_idt called_function
Definition: ssa_step.h:163
bool is_assume() const
Definition: ssa_step.h:57
void validate(const namespacet &ns, const validation_modet vm) const
Check that the SSA step is well-formed.
Definition: ssa_step.cpp:129
std::vector< exprt > ssa_function_arguments
Definition: ssa_step.h:166
exprt cond_expr
Definition: ssa_step.h:145
symex_targett::assignment_typet assignment_type
Definition: ssa_step.h:142
exprt ssa_full_lhs
Definition: ssa_step.h:140
goto_trace_stept::typet type
Definition: ssa_step.h:50
bool hidden
Definition: ssa_step.h:133
bool is_constraint() const
Definition: ssa_step.h:72
exprt guard
Definition: ssa_step.h:135
bool is_shared_write() const
Definition: ssa_step.h:107
exprt ssa_rhs
Definition: ssa_step.h:141
std::string comment
Definition: ssa_step.h:147
symex_targett::sourcet source
Definition: ssa_step.h:49
exprt original_full_lhs
Definition: ssa_step.h:140
bool is_shared_read() const
Definition: ssa_step.h:102
irep_idt property_id
Definition: ssa_step.h:149
std::list< exprt > io_args
Definition: ssa_step.h:159
void output(std::ostream &out) const
Definition: ssa_step.cpp:14
bool is_assignment() const
Definition: ssa_step.h:62
ssa_exprt ssa_lhs
Definition: ssa_step.h:139
bool is_assert() const
Definition: ssa_step.h:52
bool empty() const
Definition: dstring.h:89
Equality.
Definition: std_expr.h:1361
Base class for all expressions.
Definition: expr.h:56
typet & type()
Return the type of the expression.
Definition: expr.h:84
Step of the trace of a GOTO program.
Definition: goto_trace.h:50
const std::string & id_string() const
Definition: irep.h:391
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Definition: namespace.cpp:148
Expression providing an SSA-renamed symbol of expressions.
Definition: ssa_expr.h:17
const exprt & get_original_expr() const
Definition: ssa_expr.h:33
Symbol table entry.
Definition: symbol.h:28
The type of an expression, extends irept.
Definition: type.h:29
static format_containert< T > format(const T &o)
Definition: format.h:37
const std::string & id2string(const irep_idt &d)
Definition: irep.h:44
#define UNREACHABLE
This should be used to mark dead code.
Definition: invariant.h:525
Identifies source in the context of symbolic execution.
Definition: symex_target.h:37
goto_programt::const_targett pc
Definition: symex_target.h:42
#define DATA_CHECK(vm, condition, message)
This macro takes a condition which denotes a well-formedness criterion on goto programs,...
Definition: validate.h:22
void validate_full_expr(const exprt &expr, const namespacet &ns, const validation_modet vm)
Check that the given expression is well-formed (full check, including checks of all subexpressions an...
validation_modet