63 res +=
"Invalid function-contract mapping";
64 res +=
"\nReason: " +
reason;
74static std::pair<irep_idt, irep_idt>
77 auto const correct_format_message =
78 "the format for function and contract pairs is "
79 "`<function_name>[/<contract_name>]`";
81 std::string cli_flag_str =
id2string(cli_flag);
83 auto split =
split_string(cli_flag_str,
'/',
true,
false);
87 return std::make_pair(cli_flag, cli_flag);
89 else if(split.size() == 2)
91 auto function_name = split[0];
92 if(function_name.empty())
95 "couldn't find function name before '/' in '" + cli_flag_str +
"'",
96 correct_format_message};
98 auto contract_name = split[1];
99 if(contract_name.empty())
102 "couldn't find contract name after '/' in '" + cli_flag_str +
"'",
103 correct_format_message};
105 return std::make_pair(function_name, contract_name);
110 "couldn't parse '" + cli_flag_str +
"'", correct_format_message};
118 const std::optional<irep_idt> &to_check,
119 const bool allow_recursive_calls,
120 const std::set<irep_idt> &to_replace,
122 const std::set<std::string> &to_exclude_from_nondet_static,
125 std::map<irep_idt, irep_idt> to_replace_map;
126 for(
const auto &cli_flag : to_replace)
134 : std::optional<std::pair<irep_idt, irep_idt>>{},
135 allow_recursive_calls,
137 loop_contract_config,
139 to_exclude_from_nondet_static);
146 const std::optional<std::pair<irep_idt, irep_idt>> &
to_check,
148 const std::map<irep_idt, irep_idt> &
to_replace,
199 "' either not found or has no body");
206 "Function to check '" +
id2string(pair.first) +
207 "' either not found or has no body");
215 "' cannot be both be checked against a contract and be the harness");
220 "' cannot be both the contract to check and be the harness");
225 "' cannot be both checked against contract and replaced by a contract");
229 "CPROVER function or builtin '" +
id2string(pair.first) +
230 "' cannot be checked against a contract");
239 "Function to replace '" +
id2string(pair.first) +
"' not found");
247 "' cannot both be replaced with a contract and be the harness");
252 "' cannot both be the contract to use for replacement and be the "
258 std::set<irep_idt> &contract_symbols,
261 std::set<irep_idt> called_functions;
270 const symbolt &symbol = entry.second;
280 contract_symbols.insert(sym_name);
282 else if(called_functions.find(sym_name) != called_functions.end())
293 log.status() <<
"Loading CPROVER C library (" <<
config.ansi_c.arch <<
")"
316 log.status() <<
"Instrumenting harness function '" <<
harness_id <<
"'"
327 std::set<irep_idt> predicates =
329 for(
const auto &predicate : predicates)
342 const auto &pair =
to_check.value();
343 const auto &wrapper_id = pair.first;
344 const auto &contract_id = pair.second;
345 log.status() <<
"Wrapping '" << wrapper_id <<
"' with contract '"
359 const std::size_t assigns_clause_size =
371 const auto &wrapper_id = pair.first;
372 const auto &contract_id = pair.second;
373 log.status() <<
"Wrapping '" << wrapper_id <<
"' with contract '"
385 std::set<irep_idt> swapped;
388 std::set<irep_idt> new_contracts;
392 if(swapped.find(fp_contract) != swapped.end())
409 "' used as contract for function pointer cannot be itself the object "
410 "of a contract check.");
417 found->first == found->second,
419 "' used as contract for function pointer already the object of a "
420 "contract replacement with '" +
422 log.status() <<
"Function pointer contract '" << fp_contract
423 <<
"' already wrapped with itself in REPLACE mode"
431 "Function pointer contract '" + str +
"' not found.");
436 log.status() <<
"Wrapping function pointer contract '" << fp_contract
440 fp_contract, fp_contract, new_contracts);
441 swapped.insert(fp_contract);
485 auto assigns_clause_size =
instrument.get_max_assigns_clause_size();
489 log.status() <<
"Specializing cprover_contracts functions for assigns "
490 "clauses of at most "
494 library.inhibit_front_end_builtins();
513 "assert-false-assume-false",
519 *generate_implementation,
530 std::set<irep_idt> instrumented_functions;
531 instrument.get_instrumented_functions(instrumented_functions);
542 auto &body = init_function.body;
543 auto begin = body.instructions.begin();
545 library.add_instrumented_functions_map_init_instructions(
546 instrumented_functions, begin->source_location(), payload);
547 body.destructive_insert(begin, payload);
void cprover_c_library_factory(const std::set< irep_idt > &functions, const symbol_table_baset &symbol_table, symbol_table_baset &dest_symbol_table, message_handlert &message_handler)
bool generate_ansi_c_start_function(const symbolt &symbol, symbol_table_baset &symbol_table, message_handlert &message_handler, const c_object_factory_parameterst &object_factory_parameters)
Generate a _start function for a specific function.
API to expression classes that are internal to the C frontend.
Classes providing CFG-based information about symbols to guide simplifications in function and loop a...
cprover_exception_baset(std::string reason)
This constructor is marked protected to ensure this class isn't used directly.
std::string reason
The reason this exception was generated.
Entry point into the contracts transformation.
std::set< irep_idt > function_pointer_contracts
std::set< irep_idt > pure_contract_symbols
dfcc_spec_functionst spec_functions
void instrument_harness_function()
void instrument_other_functions()
const loop_contract_configt loop_contract_config
void reinitialize_model()
Re-initialise the GOTO model.
const std::set< std::string > & to_exclude_from_nondet_static
void link_model_and_load_dfcc_library()
dfcct(const optionst &options, goto_modelt &goto_model, const irep_idt &harness_id, const std::optional< std::pair< irep_idt, irep_idt > > &to_check, const bool allow_recursive_calls, const std::map< irep_idt, irep_idt > &to_replace, const loop_contract_configt loop_contract_config, message_handlert &message_handler, const std::set< std::string > &to_exclude_from_nondet_static)
Class constructor.
dfcc_swap_and_wrapt swap_and_wrap
dfcc_lift_memory_predicatest memory_predicates
void wrap_checked_function()
void lift_memory_predicates()
const std::optional< std::pair< irep_idt, irep_idt > > & to_check
void check_transform_goto_model_preconditions()
Checks preconditions on arguments of transform_goto_model.
std::size_t max_assigns_clause_size
Tracks the maximum number of targets in any assigns clause handled in the transformation (used to spe...
void transform_goto_model()
Applies function contracts and loop contracts transformation to GOTO model using the dynamic frame co...
dfcc_instrumentt instrument
void wrap_replaced_functions()
message_handlert & message_handler
const irep_idt & harness_id
dfcc_contract_clauses_codegent contract_clauses_codegen
const bool allow_recursive_calls
std::set< irep_idt > other_symbols
dfcc_contract_handlert contract_handler
const std::map< irep_idt, irep_idt > & to_replace
void partition_function_symbols(std::set< irep_idt > &pure_contract_symbols, std::set< irep_idt > &other_symbols)
Partitions the function symbols of the symbol table into pure contracts and other function symbols sy...
void wrap_discovered_function_pointer_contracts()
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
A generic container class for the GOTO intermediate representation of one function.
Exception thrown for bad function/contract specification pairs passed on the CLI.
invalid_function_contract_pair_exceptiont(std::string reason, std::string correct_format="")
std::string what() const override
A human readable description of what went wrong.
std::string correct_format
const irep_idt & id() const
typet type
Type of symbol.
irep_idt name
The unique identifier.
bool has_prefix(const std::string &s, const std::string &prefix)
static std::pair< irep_idt, irep_idt > parse_function_contract_pair(const irep_idt &cli_flag)
Main class orchestrating the the whole program transformation for function contracts with Dynamic Fra...
Collects all user-defined predicates that call functions is_fresh, pointer_in_range,...
Deprecated expression 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-...
Goto Programs with Functions.
Goto Programs with Functions.
Function Inlining This gives a number of different interfaces to the function inlining functionality ...
void dfcc(const optionst &options, goto_modelt &goto_model, const irep_idt &harness_id, const std::optional< irep_idt > &to_check, const bool allow_recursive_calls, const std::set< irep_idt > &to_replace, const loop_contract_configt loop_contract_config, const std::set< std::string > &to_exclude_from_nondet_static, message_handlert &message_handler)
Applies function contracts transformation to GOTO model, using the dynamic frame condition checking a...
Initialize a Goto Program.
const std::string & id2string(const irep_idt &d)
Abstract interface to support a programming language.
void link_to_library(goto_modelt &goto_model, message_handlert &message_handler, const std::function< void(const std::set< irep_idt > &, const symbol_tablet &, symbol_tablet &, message_handlert &)> &library)
Complete missing function definitions using the library.
API to expression classes for 'mathematical' expressions.
static void nondet_static(const namespacet &ns, goto_modelt &goto_model, const irep_idt &fct_name)
Nondeterministically initializes global scope variables in a goto-function.
Nondeterministically initializes global scope variables, except for constants (such as string literal...
API to expression classes for Pointers.
Various predicates over pointers in programs.
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
void remove_unused_functions(goto_modelt &goto_model, message_handlert &message_handler)
void find_used_functions(const irep_idt &start, goto_functionst &functions, std::set< irep_idt > &seen)
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
void recreate_initialize_function(goto_modelt &goto_model, message_handlert &message_handler)
Regenerates the CPROVER_INITIALIZE function, which initializes all non-function symbols of the goto m...
#define INITIALIZE_FUNCTION
API to expression classes.
void split_string(const std::string &s, char delim, std::vector< std::string > &result, bool strip, bool remove_empty)
static symbolt & get_function_symbol(symbol_table_baset &, const irep_idt &function_id)
Returns the symbolt for function_id.
static bool function_symbol_with_body_exists(const goto_modelt &, const irep_idt &function_id)
static bool function_symbol_exists(const goto_modelt &, const irep_idt &function_id)
Returns true iff the given symbol exists and satisfies requirements.
Loop contract configurations.