cprover
string_abstraction.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: String Abstraction
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_PROGRAMS_STRING_ABSTRACTION_H
13 #define CPROVER_GOTO_PROGRAMS_STRING_ABSTRACTION_H
14 
15 #include <util/symbol_table.h>
16 #include <util/message.h>
17 #include <util/config.h>
18 #include <util/std_expr.h>
19 
20 #include "goto_model.h"
21 
28 {
29 public:
31  symbol_tablet &_symbol_table,
32  message_handlert &_message_handler);
33 
34  void operator()(goto_programt &dest);
35  void operator()(goto_functionst &dest);
36 
37 protected:
38  const std::string arg_suffix;
39  std::string sym_suffix;
43 
44  typedef ::std::map< typet, typet > abstraction_types_mapt;
46 
47  ::std::set< irep_idt > current_args;
48 
49  static bool has_string_macros(const exprt &expr);
50 
52  exprt &expr,
53  bool lhs,
54  const source_locationt &);
55 
56  void move_lhs_arithmetic(exprt &lhs, exprt &rhs);
57 
58  bool is_char_type(const typet &type) const
59  {
60  if(type.id()!=ID_signedbv &&
61  type.id()!=ID_unsignedbv)
62  return false;
63 
65  }
66 
67  bool is_ptr_string_struct(const typet &type) const;
68 
69  void make_type(exprt &dest, const typet &type)
70  {
71  if(dest.is_not_nil() &&
72  ns.follow(dest.type())!=ns.follow(type))
73  dest = typecast_exprt(dest, type);
74  }
75 
76  goto_programt::targett abstract(
84 
86  goto_programt &dest,
88  const exprt &new_lhs,
89  const exprt &lhs,
90  const exprt &rhs);
91 
93 
96  const exprt &lhs, const exprt &rhs);
97 
99  goto_programt &dest,
100  goto_programt::targett target,
101  const exprt &lhs, const if_exprt &rhs);
102 
104  goto_programt &dest,
105  goto_programt::targett target,
106  const exprt &lhs, const exprt &rhs);
107 
108  enum class whatt { IS_ZERO, LENGTH, SIZE };
109 
110  static typet build_type(whatt what);
111  exprt build(
112  const exprt &pointer,
113  whatt what,
114  bool write,
115  const source_locationt &);
116 
117  bool build(const exprt &object, exprt &dest, bool write);
118  bool build_wrap(const exprt &object, exprt &dest, bool write);
119  bool build_if(const if_exprt &o_if, exprt &dest, bool write);
120  bool build_array(const array_exprt &object, exprt &dest, bool write);
121  bool build_symbol(const symbol_exprt &sym, exprt &dest);
122  bool build_symbol_constant(const mp_integer &zero_length,
123  const mp_integer &buf_size, exprt &dest);
124 
125  exprt build_unknown(whatt what, bool write);
126  exprt build_unknown(const typet &type, bool write);
127  const typet &build_abstraction_type(const typet &type);
128  const typet &build_abstraction_type_rec(const typet &type,
129  const abstraction_types_mapt &known);
130  bool build_pointer(const exprt &object, exprt &dest, bool write);
131  void build_new_symbol(const symbolt &symbol,
132  const irep_idt &identifier, const typet &type);
133 
134  exprt member(const exprt &a, whatt what);
135 
138 
139  typedef std::unordered_map<irep_idt, irep_idt> localst;
141 
142  void abstract(goto_programt &dest);
143 
144  void add_str_arguments(
145  const irep_idt &name,
147 
148  void add_argument(
149  code_typet::parameterst &str_args,
150  const symbolt &fct_symbol,
151  const typet &type,
152  const irep_idt &base_name,
153  const irep_idt &identifier);
154 
156  const irep_idt &identifier, const irep_idt &source_sym);
157 
159  goto_programt::targett ref_instr,
160  const symbolt &symbol, const typet &source_type);
161 
163  goto_programt &dest,
164  goto_programt::targett ref_instr,
165  const symbolt &symbol,
166  const irep_idt &component_name,
167  const typet &type,
168  const typet &source_type);
169 
171 };
172 
173 // keep track of length of strings
174 
175 void string_abstraction(
176  goto_modelt &,
177  message_handlert &);
178 
179 void string_abstraction(
180  symbol_tablet &,
182  goto_functionst &);
183 
184 #endif // CPROVER_GOTO_PROGRAMS_STRING_ABSTRACTION_H
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:37
string_abstractiont::string_abstractiont
string_abstractiont(symbol_tablet &_symbol_table, message_handlert &_message_handler)
Definition: string_abstraction.cpp:93
symbol_tablet
The symbol table.
Definition: symbol_table.h:20
string_abstractiont::member
exprt member(const exprt &a, whatt what)
Definition: string_abstraction.cpp:1320
string_abstractiont::build_type
static typet build_type(whatt what)
Definition: string_abstraction.cpp:113
string_abstractiont::build
exprt build(const exprt &pointer, whatt what, bool write, const source_locationt &)
Definition: string_abstraction.cpp:626
string_abstractiont::abstract_assign
goto_programt::targett abstract_assign(goto_programt &dest, goto_programt::targett it)
Definition: string_abstraction.cpp:493
string_abstraction
void string_abstraction(goto_modelt &, message_handlert &)
Definition: string_abstraction.cpp:83
typet
The type of an expression, extends irept.
Definition: type.h:29
code_typet::parameterst
std::vector< parametert > parameterst
Definition: std_types.h:738
string_abstractiont::build_pointer
bool build_pointer(const exprt &object, exprt &dest, bool write)
Definition: string_abstraction.cpp:865
string_abstractiont::abstraction_types_map
abstraction_types_mapt abstraction_types_map
Definition: string_abstraction.h:45
mp_integer
BigInt mp_integer
Definition: mp_arith.h:19
if_exprt
The trinary if-then-else operator.
Definition: std_expr.h:2964
string_abstractiont::string_struct
typet string_struct
Definition: string_abstraction.h:136
string_abstractiont::whatt::LENGTH
@ LENGTH
string_abstractiont::locals
localst locals
Definition: string_abstraction.h:140
string_abstractiont::current_args
::std::set< irep_idt > current_args
Definition: string_abstraction.h:47
goto_model.h
Symbol Table + CFG.
exprt
Base class for all expressions.
Definition: expr.h:53
goto_modelt
Definition: goto_model.h:26
string_abstractiont::build_abstraction_type_rec
const typet & build_abstraction_type_rec(const typet &type, const abstraction_types_mapt &known)
Definition: string_abstraction.cpp:679
configt::ansi_c
struct configt::ansi_ct ansi_c
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:82
string_abstractiont::is_ptr_string_struct
bool is_ptr_string_struct(const typet &type) const
Definition: string_abstraction.cpp:55
string_abstractiont::abstract_function_call
void abstract_function_call(goto_programt::targett it)
Definition: string_abstraction.cpp:525
string_abstractiont::abstract_char_assign
goto_programt::targett abstract_char_assign(goto_programt &dest, goto_programt::targett it)
Definition: string_abstraction.cpp:1104
string_abstractiont::value_assignments
goto_programt::targett value_assignments(goto_programt &dest, goto_programt::targett it, const exprt &lhs, const exprt &rhs)
Definition: string_abstraction.cpp:1202
string_abstractiont::make_type
void make_type(exprt &dest, const typet &type)
Definition: string_abstraction.h:69
configt::ansi_ct::char_width
std::size_t char_width
Definition: config.h:34
string_abstractiont::is_char_type
bool is_char_type(const typet &type) const
Definition: string_abstraction.h:58
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:92
string_abstractiont::whatt
whatt
Definition: string_abstraction.h:108
string_abstractiont::sym_suffix
std::string sym_suffix
Definition: string_abstraction.h:39
exprt::type
typet & type()
Return the type of the expression.
Definition: expr.h:81
string_abstractiont::abstraction_types_mapt
::std::map< typet, typet > abstraction_types_mapt
Definition: string_abstraction.h:44
irept::is_not_nil
bool is_not_nil() const
Definition: irep.h:402
string_abstractiont::has_string_macros
static bool has_string_macros(const exprt &expr)
Definition: string_abstraction.cpp:581
string_abstractiont::symbol_table
symbol_tablet & symbol_table
Definition: string_abstraction.h:40
string_abstractiont
Replace all uses of char * by a struct that carries that string, and also the underlying allocation a...
Definition: string_abstraction.h:28
string_abstractiont::build_unknown
exprt build_unknown(whatt what, bool write)
Definition: string_abstraction.cpp:897
string_abstractiont::whatt::SIZE
@ SIZE
string_abstractiont::declare_define_locals
void declare_define_locals(goto_programt &dest)
Definition: string_abstraction.cpp:241
string_abstractiont::make_val_or_dummy_rec
exprt make_val_or_dummy_rec(goto_programt &dest, goto_programt::targett ref_instr, const symbolt &symbol, const typet &source_type)
Definition: string_abstraction.cpp:306
string_abstractiont::add_dummy_symbol_and_value
symbol_exprt add_dummy_symbol_and_value(goto_programt &dest, goto_programt::targett ref_instr, const symbolt &symbol, const irep_idt &component_name, const typet &type, const typet &source_type)
Definition: string_abstraction.cpp:376
string_abstractiont::ns
namespacet ns
Definition: string_abstraction.h:41
string_abstractiont::build_new_symbol
void build_new_symbol(const symbolt &symbol, const irep_idt &identifier, const typet &type)
Definition: string_abstraction.cpp:975
string_abstractiont::build_abstraction_type
const typet & build_abstraction_type(const typet &type)
Definition: string_abstraction.cpp:660
irept::id
const irep_idt & id() const
Definition: irep.h:418
message_handlert
Definition: message.h:28
string_abstractiont::char_assign
goto_programt::targett char_assign(goto_programt &dest, goto_programt::targett target, const exprt &new_lhs, const exprt &lhs, const exprt &rhs)
Definition: string_abstraction.cpp:1169
string_abstractiont::value_assignments_if
goto_programt::targett value_assignments_if(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const if_exprt &rhs)
Definition: string_abstraction.cpp:1249
string_abstractiont::initialization
goto_programt initialization
Definition: string_abstraction.h:137
string_abstractiont::build_wrap
bool build_wrap(const exprt &object, exprt &dest, bool write)
Definition: string_abstraction.cpp:25
string_abstractiont::replace_string_macros
void replace_string_macros(exprt &expr, bool lhs, const source_locationt &)
Definition: string_abstraction.cpp:595
config
configt config
Definition: config.cpp:24
source_locationt
Definition: source_location.h:20
bitvector_typet::get_width
std::size_t get_width() const
Definition: std_types.h:1041
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition: goto_functions.h:25
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:23
string_abstractiont::abstract_pointer_assign
goto_programt::targett abstract_pointer_assign(goto_programt &dest, goto_programt::targett it)
Definition: string_abstraction.cpp:1062
namespace_baset::follow
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
Definition: namespace.cpp:51
string_abstractiont::temporary_counter
unsigned temporary_counter
Definition: string_abstraction.h:42
symbolt
Symbol table entry.
Definition: symbol.h:28
string_abstractiont::build_symbol_constant
bool build_symbol_constant(const mp_integer &zero_length, const mp_integer &buf_size, exprt &dest)
Definition: string_abstraction.cpp:1007
string_abstractiont::make_decl_and_def
void make_decl_and_def(goto_programt &dest, goto_programt::targett ref_instr, const irep_idt &identifier, const irep_idt &source_sym)
Definition: string_abstraction.cpp:276
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
string_abstractiont::whatt::IS_ZERO
@ IS_ZERO
config.h
string_abstractiont::build_array
bool build_array(const array_exprt &object, exprt &dest, bool write)
Definition: string_abstraction.cpp:839
string_abstractiont::add_str_arguments
void add_str_arguments(const irep_idt &name, goto_functionst::goto_functiont &fct)
Definition: string_abstraction.cpp:162
string_abstractiont::move_lhs_arithmetic
void move_lhs_arithmetic(exprt &lhs, exprt &rhs)
Definition: string_abstraction.cpp:1050
symbol_table.h
Author: Diffblue Ltd.
typecast_exprt
Semantic type conversion.
Definition: std_expr.h:2013
message.h
string_abstractiont::arg_suffix
const std::string arg_suffix
Definition: string_abstraction.h:38
string_abstractiont::build_if
bool build_if(const if_exprt &o_if, exprt &dest, bool write)
Definition: string_abstraction.cpp:811
string_abstractiont::localst
std::unordered_map< irep_idt, irep_idt > localst
Definition: string_abstraction.h:139
std_expr.h
API to expression classes.
string_abstractiont::operator()
void operator()(goto_programt &dest)
Definition: string_abstraction.cpp:152
array_exprt
Array constructor from list of elements.
Definition: std_expr.h:1432
string_abstractiont::build_symbol
bool build_symbol(const symbol_exprt &sym, exprt &dest)
Definition: string_abstraction.cpp:948
string_abstractiont::add_argument
void add_argument(code_typet::parameterst &str_args, const symbolt &fct_symbol, const typet &type, const irep_idt &base_name, const irep_idt &identifier)
Definition: string_abstraction.cpp:198
goto_programt::targett
instructionst::iterator targett
Definition: goto_program.h:579
to_bitvector_type
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
Definition: std_types.h:1089
string_abstractiont::value_assignments_string_struct
goto_programt::targett value_assignments_string_struct(goto_programt &dest, goto_programt::targett target, const exprt &lhs, const exprt &rhs)
Definition: string_abstraction.cpp:1280