CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dfcc_instrument.h
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Dynamic frame condition checking for function contracts
4
5Author: Remi Delmas, delmasrd@amazon.com
6
7\*******************************************************************/
8
11
12#ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_INSTRUMENT_H
13#define CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_INSTRUMENT_H
14
15#include <util/arith_tools.h>
16#include <util/c_types.h>
17#include <util/message.h>
18#include <util/namespace.h>
19#include <util/std_expr.h>
20#include <util/std_types.h>
21
23
25
26#include "dfcc_contract_mode.h"
28
29#include <map>
30#include <set>
31
32class goto_modelt;
34class symbolt;
36class dfcc_libraryt;
39class dfcc_cfg_infot;
40
44{
45public:
52
54 bool is_internal_symbol(const irep_idt &id) const;
55
58 bool do_not_instrument(const irep_idt &id) const;
59
83 const irep_idt &function_id,
84 const loop_contract_configt &loop_contract_config,
85 std::set<irep_idt> &function_pointer_contracts);
86
104 const irep_idt &function_id,
105 const loop_contract_configt &loop_contract_config,
106 std::set<irep_idt> &function_pointer_contracts);
107
131 const loop_contract_configt &loop_contract_config,
132 std::set<irep_idt> &function_pointer_contracts);
133
152 const irep_idt &function_id,
153 goto_programt &goto_program,
154 const exprt &write_set,
155 std::set<irep_idt> &function_pointer_contracts);
156
159 void get_instrumented_functions(std::set<irep_idt> &dest) const;
160
163 std::size_t get_max_assigns_clause_size() const;
164
165protected:
174
177 static std::set<irep_idt> function_cache;
178
182 std::set<irep_idt> internal_symbols;
183
188 std::set<symbol_exprt> get_local_statics(const irep_idt &function_id);
189
204 const irep_idt &function_id,
205 const exprt &write_set,
206 const symbol_exprt &symbol_expr,
208 goto_programt &goto_program);
209
224 const irep_idt &function_id,
225 const exprt &write_set,
226 const symbol_exprt &symbol_expr,
228 goto_programt &goto_program);
229
234 const irep_idt &function_id,
235 goto_functiont &goto_function,
236 const exprt &write_set,
237 const std::set<symbol_exprt> &local_statics,
238 const loop_contract_configt &loop_contract_config,
239 std::set<irep_idt> &function_pointer_contracts);
240
254 const irep_idt &function_id,
255 goto_programt &goto_program,
257 const goto_programt::targett &last_instruction, // excluding the last
258 dfcc_cfg_infot &cfg_info,
259 std::set<irep_idt> &function_pointer_contracts);
260
263 void instrument_decl(
264 const irep_idt &function_id,
266 goto_programt &goto_program,
267 dfcc_cfg_infot &cfg_info);
268
271 void instrument_dead(
272 const irep_idt &function_id,
274 goto_programt &goto_program,
275 dfcc_cfg_infot &cfg_info);
276
279 void instrument_lhs(
280 const irep_idt &function_id,
282 const exprt &lhs,
283 goto_programt &goto_program,
284 dfcc_cfg_infot &cfg_info);
285
292 const irep_idt &function_id,
294 goto_programt &goto_program,
295 dfcc_cfg_infot &cfg_info);
296
301 const exprt &write_set,
303 goto_programt &goto_program);
304
314 const exprt &write_set,
316 goto_programt &goto_program);
317
322 const irep_idt &function_id,
323 const exprt &write_set,
325 goto_programt &goto_program);
326
332 const irep_idt &function_id,
334 goto_programt &goto_program,
335 dfcc_cfg_infot &cfg_info);
336
341 void instrument_other(
342 const irep_idt &function_id,
344 goto_programt &goto_program,
345 dfcc_cfg_infot &cfg_info);
346
353 const irep_idt &function_id,
354 goto_functiont &goto_function,
355 dfcc_cfg_infot &cfg_info,
356 const loop_contract_configt &loop_contract_config,
357 const std::set<symbol_exprt> &local_statics,
358 std::set<irep_idt> &function_pointer_contracts);
359};
360
361#endif
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
A class for an expression that represents a conditional target or a list of targets sharing a common ...
Definition c_expr.h:233
Computes natural loops, enforces normal form conditions, computes the nesting graph,...
Translates assigns and frees clauses of a function contract or loop contract into GOTO programs that ...
This class applies the loop contract transformation to a loop in a goto function.
This class instruments GOTO functions or instruction sequences for frame condition checking and loop ...
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...
dfcc_contract_clauses_codegent & contract_clauses_codegen
dfcc_libraryt & library
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...
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.
goto_modelt & goto_model
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.
dfcc_spec_functionst & spec_functions
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...
Class interface to library types and functions defined in cprover_contracts.c.
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.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:56
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
A generic container class for the GOTO intermediate representation of one function.
instructionst::iterator targett
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:154
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
Expression to hold a symbol (variable)
Definition std_expr.h:131
Symbol table entry.
Definition symbol.h:28
Enum type representing the contract checking and replacement modes.
This class applies the loop contract transformation to a loop in a goto function.
Concrete Goto Program.
Config for loop contract.
API to expression classes.
Pre-defined types.
Loop contract configurations.