36 expr.
id() == ID_typecast && expr.
type().
id() == ID_pointer &&
37 expr.
operands().at(0).id() == ID_address_of,
38 "target expression must be of the form `cast(address_of(target), empty*)`");
40 return expr.
operands().at(0).operands().at(0).type();
46 std::size_t &nof_targets)
49 !
goto_model.symbol_table.has_symbol(havoc_function_id),
50 "DFCC: havoc function id '" +
id2string(havoc_function_id) +
53 const auto &function_symbol =
57 const typet &write_set_param_type =
64 havoc_function_symbol.
base_name = havoc_function_id;
65 havoc_function_symbol.name = havoc_function_id;
66 havoc_function_symbol.pretty_name = havoc_function_id;
67 havoc_function_symbol.type = havoc_code_type;
68 havoc_function_symbol.mode = function_symbol.mode;
69 havoc_function_symbol.module = function_symbol.module;
70 havoc_function_symbol.location = function_symbol.location;
71 havoc_function_symbol.set_compiled();
72 bool add_function_failed =
goto_model.symbol_table.add(havoc_function_symbol);
75 "DFCC: could not insert havoc function '" +
id2string(havoc_function_id) +
76 "' in the symbol table");
82 "__write_set_to_havoc",
83 write_set_param_type);
85 goto_model.symbol_table.get_writeable_ref(havoc_function_id).type)
87 .set_identifier(write_set_symbol.name);
92 goto_model.goto_functions.function_map[havoc_function_id].copy_from(
93 dummy_havoc_function);
97 goto_model.goto_functions.function_map.at(havoc_function_id).body;
100 goto_model.goto_functions.function_map.at(function_id).body;
105 write_set_symbol.symbol_expr(),
114 std::set<irep_idt> no_body;
115 std::set<irep_idt> missing_function;
116 std::set<irep_idt> recursive_call;
117 std::set<irep_idt> not_enough_arguments;
124 not_enough_arguments,
128 "no body warnings when inlining " +
id2string(havoc_function_id));
130 missing_function.empty(),
131 "missing function warnings when inlining " +
id2string(havoc_function_id));
133 recursive_call.empty(),
134 "recursive calls when inlining " +
id2string(havoc_function_id));
136 not_enough_arguments.empty(),
137 "not enough arguments when inlining " +
id2string(havoc_function_id));
139 goto_model.goto_functions.function_map.at(havoc_function_id).make_hidden();
147 const exprt &write_set_to_havoc,
150 std::size_t &nof_targets)
153 std::size_t next_idx = 0;
159 if(ins_it->is_function_call())
161 if(ins_it->call_function().id() != ID_symbol)
164 "Function pointer calls are not supported in assigns clauses: '" +
165 from_expr(
ns, function_id, ins_it->call_function()) +
166 "' called in function '" +
id2string(function_id) +
"'",
167 ins_it->source_location());
177 auto hook_opt =
library.get_havoc_hook(callee_id);
179 hook_opt.has_value(),
180 "dfcc_spec_functionst::generate_havoc_instructions: function calls "
181 "must be inlined before calling this function");
185 auto hook = hook_opt.value();
187 library.dfcc_fun_symbol.at(hook).symbol_expr(),
188 {write_set_to_havoc, from_integer(next_idx, size_type())});
212 call.
lhs() = target_expr;
215 auto goto_instruction =
221 target_type.id() == ID_pointer)
257 goto_instruction->complete_goto(label);
275 nof_targets = next_idx;
280 std::size_t &nof_targets)
282 auto &goto_function =
goto_model.goto_functions.function_map.at(function_id);
285 const exprt write_set_to_fill =
289 "__write_set_to_fill",
301 goto_model.goto_functions.function_map.at(function_id).make_hidden();
305 const exprt &write_set_to_fill,
308 std::size_t &nof_targets)
312 std::size_t next_idx = 0;
317 if(ins_it->is_function_call())
319 if(ins_it->call_function().id() != ID_symbol)
322 "Function pointer calls are not supported in assigns clauses '" +
325 ins_it->source_location());
336 library.is_front_end_builtin(callee_id),
337 "dfcc_spec_functionst::to_spec_assigns_function: function calls must "
338 "be inlined before calling this function");
340 auto hook =
library.get_hook(callee_id);
342 ins_it->call_function() =
library.dfcc_fun_symbol.at(hook).symbol_expr();
344 ins_it->call_arguments().insert(
347 ins_it->call_arguments().insert(
348 ins_it->call_arguments().begin(), write_set_to_fill);
353 ins_it->call_arguments().pop_back();
358 nof_targets = next_idx;
363 std::size_t &nof_targets)
365 auto &goto_function =
goto_model.goto_functions.function_map.at(function_id);
368 const exprt &write_set_to_fill =
372 "__write_set_to_fill",
384 goto_model.goto_functions.function_map.at(function_id).make_hidden();
388 const exprt &write_set_to_fill,
391 std::size_t &nof_targets)
394 std::size_t next_idx = 0;
397 if(ins_it->is_function_call())
399 if(ins_it->call_function().id() != ID_symbol)
402 "Function pointer calls are not supported in frees clauses: '" +
405 ins_it->source_location());
415 "dfcc_spec_functionst::to_spec_frees_function: function calls must "
416 "be inlined before calling this function");
418 ins_it->call_function() =
421 ins_it->call_arguments().insert(
422 ins_it->call_arguments().begin(), write_set_to_fill);
427 nof_targets = next_idx;
unsignedbv_typet size_type()
pointer_typet pointer_type(const typet &subtype)
goto_instruction_codet representation of a function call statement.
const parameterst & parameters() const
Operator to dereference a pointer.
Class interface to library types and functions defined in cprover_contracts.c.
void to_spec_assigns_function(const irep_idt &function_id, std::size_t &nof_targets)
Transforms (in place) a function.
void to_spec_frees_instructions(const exprt &write_set_to_fill, const irep_idt &language_mode, goto_programt &program, std::size_t &nof_targets)
Rewrites in place program expressed in terms of built-ins specifying freeable targets declaratively u...
void generate_havoc_function(const irep_idt &function_id, const irep_idt &havoc_function_id, std::size_t &nof_targets)
Generates the havoc function for a function contract.
message_handlert & message_handler
void to_spec_assigns_instructions(const exprt &write_set_to_fill, const irep_idt &language_mode, goto_programt &program, std::size_t &nof_targets)
Rewrites in place program expressed in terms of built-ins specifying assignable targets declaratively...
const typet & get_target_type(const exprt &expr)
Extracts the type of an assigns clause target expression The expression must be of the form: expr = c...
void generate_havoc_instructions(const irep_idt &function_id, const goto_programt &original_program, const exprt &write_set_to_havoc, dfcc_ptr_havoc_modet ptr_havoc_mode, goto_programt &havoc_program, std::size_t &nof_targets)
Translates original_program that specifies assignable targets into a program that havocs the targets.
dfcc_spec_functionst(goto_modelt &goto_model, message_handlert &message_handler, dfcc_libraryt &library)
void to_spec_frees_function(const irep_idt &function_id, std::size_t &nof_targets)
Transforms (in place) a function.
Base class for all expressions.
typet & type()
Return the type of the expression.
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
parameter_identifierst parameter_identifiers
The identifiers of the parameters of this function.
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_dead(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_end_function(const source_locationt &l=source_locationt::nil())
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
Thrown when we can't handle something in an input source file.
const irep_idt & id() const
A side_effect_exprt that returns a non-deterministically chosen value.
const irep_idt & get_identifier() const
irep_idt base_name
Base (non-scoped) name.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
Dynamic frame condition checking library loading.
@ WRITE_SET_INSERT_ASSIGNABLE
@ WRITE_SET_HAVOC_GET_ASSIGNABLE_TARGET
@ WRITE_SET_HAVOC_OBJECT_WHOLE
@ CAR_SET_PTR
type of pointers to sets of CAR
@ WRITE_SET_PTR
type of pointers to descriptors of assignable/freeable sets of locations
Translate functions that specify assignable and freeable targets declaratively into active functions ...
dfcc_ptr_havoc_modet
Represents the different ways to havoc pointers.
@ INVALID
havocs the pointer to an invalid pointer
#define forall_goto_program_instructions(it, program)
#define Forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
std::string from_expr_using_mode(const namespacet &ns, const irep_idt &mode, const exprt &expr)
Formats an expression using the given namespace, using the given mode to retrieve the language printe...
#define UNREACHABLE
This should be used to mark dead code.
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
static symbolt & get_function_symbol(symbol_table_baset &, const irep_idt &function_id)
Returns the symbolt for function_id.
static void inline_function(goto_modelt &goto_model, const irep_idt &function_id, message_handlert &message_handler)
Inlines the given function, aborts on recursive calls during inlining.
static const exprt make_null_check_expr(const exprt &ptr)
Returns the expression expr == NULL.
static const symbolt & create_new_parameter_symbol(symbol_table_baset &, const irep_idt &function_id, const std::string &base_name, const typet &type)
Creates a new parameter symbol for the given function_id.
static void add_parameter(goto_modelt &, const symbolt &symbol, const irep_idt &function_id)
Adds the given symbol as parameter to the function symbol's code_type.
static symbol_exprt create_symbol(symbol_table_baset &, const typet &type, const irep_idt &function_id, const std::string &base_name, const source_locationt &source_location)
Adds a new symbol named function_id::base_name of type type with given attributes in the symbol table...