55 : goto_model(goto_model),
56 message_handler(message_handler),
59 spec_functions(spec_functions),
60 contract_clauses_codegen(contract_clauses_codegen),
66 contract_clauses_codegen),
67 ns(goto_model.symbol_table)
103 std::set<irep_idt> &dest)
const
175 static std::set<irep_idt> alloca_builtins = {"alloca", "__builtin_alloca"};
178 static std::set<std::string> builtins_with_cprover_impl = {
179 "__builtin_ia32_sfence",
180 "__builtin_ia32_lfence",
181 "__builtin_ia32_mfence",
185 "__builtin_ia32_vec_ext_v4hi",
186 "__builtin_ia32_vec_ext_v8hi",
187 "__builtin_ia32_vec_ext_v4si",
188 "__builtin_ia32_vec_ext_v2di",
189 "__builtin_ia32_vec_ext_v16qi",
190 "__builtin_ia32_vec_ext_v4sf",
191 "__builtin_ia32_psubsw128",
192 "__builtin_ia32_psubusw128",
193 "__builtin_ia32_paddsw",
194 "__builtin_ia32_psubsw",
195 "__builtin_ia32_vec_init_v4hi",
196 "__builtin_flt_rounds",
208 "__builtin_huge_valf",
209 "__builtin_huge_val",
210 "__builtin_huge_vall",
217 "__builtin___strcpy_chk",
218 "__builtin___strcat_chk",
219 "__builtin___strncat_chk",
220 "__builtin___strncpy_chk",
221 "__builtin___memcpy_chk",
223 "__builtin___memset_chk",
224 "__builtin___memmove_chk"};
242 std::set<irep_idt> &function_pointer_contracts)
252 "Function '" +
id2string(function_id) +
"' must exist in the model.");
264 "__write_set_to_check",
276 loop_contract_config,
277 function_pointer_contracts);
279 auto &body = goto_function.
body;
299std::set<symbol_exprt>
306 if(
sym.is_static_lifetime)
308 const auto &loc =
sym.location;
309 if(!loc.get_function().empty() && loc.get_function() == function_id)
321 std::set<irep_idt> &function_pointer_contracts)
331 "Function '" +
id2string(function_id) +
"' must exist in the model.");
336 "__write_set_to_check",
349 loop_contract_config,
350 function_pointer_contracts);
357 std::set<irep_idt> &function_pointer_contracts)
369 "' must exist in the model.");
374 "__write_set_to_check",
387 loop_contract_config,
388 function_pointer_contracts);
395 std::set<irep_idt> &function_pointer_contracts)
417 body.instructions.begin(),
418 body.instructions.end(),
420 function_pointer_contracts);
423 goto_program.
clear();
435 std::set<irep_idt> &function_pointer_contracts)
440 std::string options =
"assert-false-assume-false";
449 auto &body = goto_function.
body;
457 loop_contract_config,
466 body.instructions.
begin(),
467 body.instructions.end(),
469 function_pointer_contracts);
480 loop_contract_config,
482 function_pointer_contracts);
486 auto begin = body.instructions.begin();
487 auto end = std::prev(body.instructions.end());
507 if(top_level_tracked.find(
param_id) != top_level_tracked.end())
527 std::set<irep_idt> &function_pointer_contracts)
556 function_pointer_contracts);
564 if(target->is_decl())
568 if(target->is_dead())
572 else if(target->is_assign())
576 else if(target->is_function_call())
580 else if(target->is_other())
606 auto label_instruction =
608 goto_instruction->complete_goto(label_instruction);
627 const auto &decl_symbol = target->decl_symbol();
632 function_id,
write_set, decl_symbol, target, goto_program);
653 auto label_instruction =
656 goto_instruction->complete_goto(label_instruction);
676 const auto &decl_symbol = target->dead_symbol();
679 function_id,
write_set, decl_symbol, target, goto_program);
719 "__check_lhs_assignment",
737 auto label_instruction =
739 goto_instruction->complete_goto(label_instruction);
750 const auto &lhs = target->assign_lhs();
751 const auto &rhs = target->assign_rhs();
781 auto label_instruction =
783 goto_instruction->complete_goto(label_instruction);
814 const auto &
callf = target->call_function();
825 target->call_lhs(), target->call_function(), target->call_arguments());
833 target->call_lhs(), target->call_function(), target->call_arguments());
838 target->turn_into_skip();
847 if(target->is_function_call())
849 if(target->call_function().id() ==
ID_symbol)
856 target->call_arguments().push_back(
write_set);
876 INVARIANT(target->is_function_call(),
"target must be a function call");
878 target->call_function().id() ==
ID_symbol &&
904 "__check_deallocate",
909 const auto &ptr = target->call_arguments().at(0);
932 auto label_instruction =
934 goto_instruction->complete_goto(label_instruction);
946 target->is_function_call(),
947 "the target must be a function call instruction");
952 if(target->call_lhs().is_not_nil() && cfg_info.
must_check_lhs(target))
955 function_id, target, target->call_lhs(), goto_program, cfg_info);
958 const auto &call_function = target->call_function();
980 auto &statement = target->get_other().get_statement();
1007 is_array_set ?
"__check_array_set" :
"__check_array_copy",
1012 const auto &dest = target->get_other().operands().at(0);
1029 ", ...) is allowed by the assigns clause";
1035 auto label_instruction =
1037 goto_instruction->complete_goto(label_instruction);
1062 "__check_array_replace",
1067 const auto &dest = target->get_other().operands().at(0);
1068 const auto &src = target->get_other().operands().at(1);
1078 std::string
comment =
"Check that array_replace(" +
1080 ", ...) is allowed by the assigns clause";
1086 auto label_instruction =
1088 goto_instruction->complete_goto(label_instruction);
1111 "__check_havoc_object",
1116 const auto &ptr = target->get_other().operands().at(0);
1126 std::string
comment =
"Check that havoc_object(" +
1128 ") is allowed by the assigns clause";
1134 auto label_instruction =
1136 goto_instruction->complete_goto(label_instruction);
1165 log.
warning() <<
"dfcc_instrument::instrument_other: statement type '"
1166 << statement <<
"' is not supported, analysis may be unsound"
1177 std::set<irep_idt> &function_pointer_contracts)
1188 if(loop.must_skip())
1191 log.
warning() <<
"loop " << function_id <<
"." << loop.cbmc_loop_id
1192 <<
" does not have a contract, skipping instrumentation"
1203 function_pointer_contracts);
1205 id2string(function_id) +
"." + std::to_string(loop.cbmc_loop_id) +
":2");
API to expression classes that are internal to the C frontend.
pointer_typet pointer_type(const typet &subtype)
unsignedbv_typet unsigned_char_type()
Operator to return the address of an object.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
goto_instruction_codet representation of a function call statement.
Computes natural loops, enforces normal form conditions, computes the nesting graph,...
const std::unordered_set< irep_idt > & get_top_level_tracked()
Returns the set of top level symbols that must be tracked explicitly in the top level write set of th...
const dfcc_loop_infot & get_loop_info(const std::size_t loop_id) const
Returns the loop info for that loop_id.
const std::vector< std::size_t > & get_loops_toposorted() const
bool must_check_lhs(goto_programt::const_targett target) const
True iff the lhs of an assignment must be checked against the ambient write set.
const exprt & get_write_set(goto_programt::const_targett target) const
Returns the write set variable to use for the given instruction Returns the write set for the loop,...
bool must_track_decl_or_dead(goto_programt::const_targett target) const
True iff a DECL ident must be tracked in the write set of the loop that contains the DECL.
Translates assigns and frees clauses of a function contract or loop contract into GOTO programs that ...
std::size_t get_max_assigns_clause_size() const
Maximum number of assigns clause targets.
void instrument_function(const irep_idt &function_id, const loop_contract_configt &loop_contract_config, std::set< irep_idt > &function_pointer_contracts)
Instruments a GOTO function by adding an extra write set parameter and instrumenting its body instruc...
void instrument_goto_program(const irep_idt &function_id, goto_programt &goto_program, const exprt &write_set, std::set< irep_idt > &function_pointer_contracts)
Instruments a GOTO program against a given write set variable.
void instrument_call_instruction(const exprt &write_set, goto_programt::targett &target, goto_programt &goto_program)
Adds the write_set as extra argument to a function of function pointer call instruction.
void instrument_lhs(const irep_idt &function_id, goto_programt::targett &target, const exprt &lhs, goto_programt &goto_program, dfcc_cfg_infot &cfg_info)
Instruments the LHS of an assignment instruction instruction by adding an inclusion check of lhs in w...
void instrument_other(const irep_idt &function_id, goto_programt::targett &target, goto_programt &goto_program, dfcc_cfg_infot &cfg_info)
Instruments a OTHER statement; instruction.
void instrument_assign(const irep_idt &function_id, goto_programt::targett &target, goto_programt &goto_program, dfcc_cfg_infot &cfg_info)
Instrument the lhs of an ASSIGN lhs := rhs instruction by adding an inclusion check of lhs in write_s...
void instrument_deallocate_call(const irep_idt &function_id, const exprt &write_set, goto_programt::targett &target, goto_programt &goto_program)
Inserts deallocation checks and a write set update before a call to the __CPROVER_deallocate function...
std::set< irep_idt > internal_symbols
Set of internal symbols which implementation is generated and inlined into the model at conversion or...
dfcc_instrument_loopt instrument_loop
void get_instrumented_functions(std::set< irep_idt > &dest) const
Adds the names of instrumented functions to dest.
message_handlert & message_handler
static std::set< irep_idt > function_cache
Keeps track of instrumented functions, so that no function gets instrumented more than once.
void instrument_goto_function(const irep_idt &function_id, goto_functiont &goto_function, const exprt &write_set, const std::set< symbol_exprt > &local_statics, const loop_contract_configt &loop_contract_config, std::set< irep_idt > &function_pointer_contracts)
Instruments the body of a GOTO function against a given write set.
void instrument_function_call(const irep_idt &function_id, goto_programt::targett &target, goto_programt &goto_program, dfcc_cfg_infot &cfg_info)
Instruments a CALL lhs := function(params) instruction by adding an inclusion check of lhs in write_s...
void instrument_wrapped_function(const irep_idt &wrapped_function_id, const irep_idt &initial_function_id, const loop_contract_configt &loop_contract_config, std::set< irep_idt > &function_pointer_contracts)
Instruments a GOTO function by adding an extra write set parameter and inserting frame condition chec...
void instrument_instructions(const irep_idt &function_id, goto_programt &goto_program, goto_programt::targett first_instruction, const goto_programt::targett &last_instruction, dfcc_cfg_infot &cfg_info, std::set< irep_idt > &function_pointer_contracts)
Instruments the instructions found between first_instruction and last_instruction in the instructions...
dfcc_instrumentt(goto_modelt &goto_model, message_handlert &message_handler, dfcc_libraryt &library, dfcc_spec_functionst &spec_functions, dfcc_contract_clauses_codegent &contract_clauses_codegen)
void instrument_decl(const irep_idt &function_id, goto_programt::targett &target, goto_programt &goto_program, dfcc_cfg_infot &cfg_info)
Instruments a DECL x instruction.
std::size_t get_max_assigns_clause_size() const
bool do_not_instrument(const irep_idt &id) const
True iff the symbol must not be instrumented because it is an internal symbol or a CPROVER symbol.
void apply_loop_contracts(const irep_idt &function_id, goto_functiont &goto_function, dfcc_cfg_infot &cfg_info, const loop_contract_configt &loop_contract_config, const std::set< symbol_exprt > &local_statics, std::set< irep_idt > &function_pointer_contracts)
Applies loop contracts transformations to the given GOTO function, using the given cfg_info instance ...
void instrument_dead(const irep_idt &function_id, goto_programt::targett &target, goto_programt &goto_program, dfcc_cfg_infot &cfg_info)
Instruments a DEAD x instruction.
void instrument_harness_function(const irep_idt &function_id, const loop_contract_configt &loop_contract_config, std::set< irep_idt > &function_pointer_contracts)
Instruments a GOTO function used as a proof harness.
void insert_record_dead_call(const irep_idt &function_id, const exprt &write_set, const symbol_exprt &symbol_expr, goto_programt::targett &target, goto_programt &goto_program)
Generates a guarded call to record the death of a local symbol and inserts it in the goto_program at ...
std::set< symbol_exprt > get_local_statics(const irep_idt &function_id)
Returns the set of names from the symbol table that have the static flag set to true and have a sourc...
bool is_internal_symbol(const irep_idt &id) const
True iff the symbol an internal symbol.
void insert_add_decl_call(const irep_idt &function_id, const exprt &write_set, const symbol_exprt &symbol_expr, goto_programt::targett &target, goto_programt &goto_program)
Generates a guarded call to record a locally allocated symbol and inserts it in the goto_program at t...
void instrument_fptr_call_instruction_dynamic_lookup(const exprt &write_set, goto_programt::targett &target, goto_programt &goto_program)
Before calling a function pointer, performs a dynamic lookup into the map of instrumented function pr...
Rewrites calls to is_freeable and was_freed predicates in goto programs encoding pre and post conditi...
Rewrites calls to is_fresh predicates into calls to the library implementation.
Class interface to library types and functions defined in cprover_contracts.c.
const code_function_callt write_set_record_dead_call(const exprt &write_set_ptr, const exprt &ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_record_dead.
const code_function_callt write_set_check_assignment_call(const exprt &check_var, const exprt &write_set_ptr, const exprt &ptr, const exprt &size, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_assignment.
const code_function_callt write_set_record_deallocated_call(const exprt &write_set_ptr, const exprt &ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_record_deallocated.
const code_function_callt write_set_add_decl_call(const exprt &write_set_ptr, const exprt &ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_add_decl.
const code_function_callt write_set_check_array_copy_call(const exprt &check_var, const exprt &write_set_ptr, const exprt &dest, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_array_copy.
const code_function_callt write_set_add_allocated_call(const exprt &write_set_ptr, const exprt &ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_add_allocated.
const symbolt & get_instrumented_functions_map_symbol()
Returns the "__dfcc_instrumented_functions" symbol or creates it if it does not exist already.
const code_function_callt write_set_check_array_set_call(const exprt &check_var, const exprt &write_set_ptr, const exprt &dest, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_array_set.
const code_function_callt write_set_check_array_replace_call(const exprt &check_var, const exprt &write_set_ptr, const exprt &dest, const exprt &src, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_array_replace.
const code_function_callt write_set_check_deallocate_call(const exprt &check_var, const exprt &write_set_ptr, const exprt &ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_deallocate.
std::map< dfcc_typet, typet > dfcc_type
Maps enum values to the actual types (dynamically loaded)
const code_function_callt write_set_check_havoc_object_call(const exprt &check_var, const exprt &write_set_ptr, const exprt &ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_havoc_object.
Rewrites calls to obeys_contract predicates into calls to the library implementation.
Rewrites calls to pointer_equals predicates into calls to the library implementation.
Rewrites calls to pointer_in_range predicates into calls to the library implementation.
This class rewrites GOTO functions that use the built-ins:
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
std::string::const_iterator begin() const
Base class for all expressions.
function_mapt function_map
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
bool body_available() const
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
A generic container class for the GOTO intermediate representation of one function.
void copy_from(const goto_programt &src)
Copy a full goto program, preserving targets.
void clear()
Clear the goto program.
static instructiont make_dead(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
instructionst::iterator targett
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
source_locationt source_location
message_handlert & get_message_handler()
mstreamt & warning() const
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
The null pointer constant.
Expression to hold a symbol (variable)
The Boolean constant true.
static exprt conditional_cast(const exprt &expr, const typet &type)
bool has_prefix(const std::string &s, const std::string &prefix)
Class that computes CFG information about the loop structure of a GOTO function for the purpose of dy...
Translates assigns and frees clauses of a function contract or loop contract into goto programs that ...
Add instrumentation to a goto program to perform frame condition checks.
This class applies the loop contract transformation to a loop in a goto function.
bool dfcc_is_cprover_function_symbol(const irep_idt &id)
Returns true iff id is one of the known CPROVER functions or starts with __VERIFIER or nondet.
Instruments occurrences of is_freeable predicates in programs encoding requires and ensures clauses o...
Instruments occurrences of is_fresh predicates in programs encoding requires and ensures clauses of c...
static const std::map< dfcc_funt, int > to_unwind
set of functions that need to be unwound to assigns clause size with corresponding loop identifiers.
Dynamic frame condition checking library loading.
@ WRITE_SET_PTR
type of pointers to descriptors of assignable/freeable sets of locations
Instruments occurrences of obeys_contract predicates in programs encoding requires and ensures clause...
Instruments occurrences of pointer_equals predicates in programs encoding requires and ensures clause...
Instruments occurrences of pointer_in_range predicates in programs encoding requires and ensures clau...
Translate functions that specify assignable and freeable targets declaratively into active functions ...
Dynamic frame condition checking utility functions.
Fresh auxiliary symbol creation.
std::unique_ptr< generate_function_bodiest > generate_function_bodies_factory(const std::string &options, const c_object_factory_parameterst &object_factory_parameters, const symbol_tablet &symbol_table, message_handlert &message_handler)
Create the type that actually generates the functions.
void generate_function_bodies(const std::regex &functions_regex, const generate_function_bodiest &generate_function_body, goto_modelt &model, message_handlert &message_handler)
Generate function bodies with some default behavior: assert-false, assume-false, assert-false-assume-...
const std::string & id2string(const irep_idt &d)
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...
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
exprt pointer_object(const exprt &p)
Various predicates over pointers in programs.
static std::string comment(const rw_set_baset::entryt &entry, bool write)
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
#define PRECONDITION(CONDITION)
#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 const exprt make_null_check_expr(const exprt &ptr)
Returns the expression expr == NULL.
static exprt make_sizeof_expr(const exprt &expr, const namespacet &)
Returns the expression sizeof(expr).
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...
Loop contract configurations.
bool unwind_transformed_loops
bool apply_loop_contracts
void insert_before_swap_and_advance(goto_programt &destination, goto_programt::targett &target, goto_programt &payload)
Insert a goto program before a target instruction iterator and advance the iterator.