CBMC
dfcc_instrument_loop.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Dynamic frame condition checking for loop contracts
4 
5 Author: Qinheping Hu, qinhh@amazon.com
6 
7 Author: Remi Delmas, delmasrd@amazon.com
8 
9 Date: April 2023
10 
11 \*******************************************************************/
12 
16 
17 #ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_INSTRUMENT_LOOP_H
18 #define CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_INSTRUMENT_LOOP_H
19 
20 #include <util/message.h>
21 
23 
25 
27 class dfcc_libraryt;
28 class dfcc_instrumentt;
31 class dfcc_cfg_infot;
32 
36 {
37 public:
48  message_handlert &message_handler,
52 
113  // new_variant = loop_decreases;
132  void operator()(
133  const std::size_t loop_id,
134  const irep_idt &function_id,
135  goto_functiont &goto_function,
136  dfcc_cfg_infot &cfg_info,
137  const std::set<symbol_exprt> &local_statics,
138  std::set<irep_idt> &function_pointer_contracts);
139 
141  std::size_t get_max_assigns_clause_size() const
142  {
144  }
145 
146 protected:
147  // keeps track of the maximum number of assigns clause targets
148  std::size_t max_assigns_clause_size = 0;
155 
196  std::unordered_map<exprt, symbol_exprt, irep_hash> add_prehead_instructions(
197  const std::size_t loop_id,
198  goto_functionst::goto_functiont &goto_function,
199  symbol_table_baset &symbol_table,
200  goto_programt::targett loop_head,
201  goto_programt::targett loop_latch,
202  goto_programt &assigns_instrs,
203  exprt &invariant,
204  const exprt::operandst &assigns,
205  const symbol_exprt &loop_write_set,
206  const symbol_exprt &addr_of_loop_write_set,
207  const symbol_exprt &entered_loop,
208  const symbol_exprt &initial_invariant,
209  const symbol_exprt &in_base_case,
210  const irep_idt &symbol_mode);
211 
245  const std::size_t loop_id,
246  const std::size_t cbmc_loop_id,
247  const irep_idt &function_id,
248  goto_functionst::goto_functiont &goto_function,
249  symbol_table_baset &symbol_table,
250  goto_programt::targett loop_head,
251  goto_programt::targett loop_latch,
252  goto_programt &havoc_instrs,
253  exprt &invariant,
254  const exprt::operandst &decreases_clauses,
255  const symbol_exprt &loop_write_set,
256  const exprt &outer_write_set,
257  const symbol_exprt &initial_invariant,
258  const symbol_exprt &in_base_case,
259  const std::vector<symbol_exprt> &old_decreases_vars);
260 
293  const std::size_t loop_id,
294  const std::size_t cbmc_loop_id,
295  goto_functionst::goto_functiont &goto_function,
296  symbol_table_baset &symbol_table,
297  goto_programt::targett loop_head,
298  goto_programt::targett loop_latch,
299  exprt &invariant,
300  const exprt::operandst &decreases_clauses,
301  const symbol_exprt &entered_loop,
302  const symbol_exprt &in_base_case,
303  const std::vector<symbol_exprt> &old_decreases_vars,
304  const std::vector<symbol_exprt> &new_decreases_vars,
305  const goto_programt::instructiont::targett &step_case_target,
306  const irep_idt &symbol_mode);
307 
339  const std::size_t loop_id,
340  const std::size_t cbmc_loop_id,
341  goto_functionst::goto_functiont &goto_function,
342  goto_programt::targett loop_head,
343  const symbol_exprt &loop_write_set,
344  const symbol_exprt &addr_of_loop_write_set,
345  const std::unordered_map<exprt, symbol_exprt, irep_hash> &history_var_map,
346  const symbol_exprt &entered_loop,
347  const symbol_exprt &initial_invariant,
348  const symbol_exprt &in_base_case,
349  const std::vector<symbol_exprt> &old_decreases_vars,
350  const std::vector<symbol_exprt> &new_decreases_vars);
351 };
352 
353 #endif
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.
void add_exit_instructions(const std::size_t loop_id, const std::size_t cbmc_loop_id, goto_functionst::goto_functiont &goto_function, goto_programt::targett loop_head, const symbol_exprt &loop_write_set, const symbol_exprt &addr_of_loop_write_set, const std::unordered_map< exprt, symbol_exprt, irep_hash > &history_var_map, const symbol_exprt &entered_loop, const symbol_exprt &initial_invariant, const symbol_exprt &in_base_case, const std::vector< symbol_exprt > &old_decreases_vars, const std::vector< symbol_exprt > &new_decreases_vars)
Adds instructions of the exit block.
dfcc_spec_functionst & spec_functions
dfcc_instrument_loopt(goto_modelt &goto_model, message_handlert &message_handler, dfcc_libraryt &library, dfcc_spec_functionst &spec_functions, dfcc_contract_clauses_codegent &contract_clauses_codegen)
Constructor for the loop contract instrumentation class.
void add_body_instructions(const std::size_t loop_id, const std::size_t cbmc_loop_id, goto_functionst::goto_functiont &goto_function, symbol_table_baset &symbol_table, goto_programt::targett loop_head, goto_programt::targett loop_latch, exprt &invariant, const exprt::operandst &decreases_clauses, const symbol_exprt &entered_loop, const symbol_exprt &in_base_case, const std::vector< symbol_exprt > &old_decreases_vars, const std::vector< symbol_exprt > &new_decreases_vars, const goto_programt::instructiont::targett &step_case_target, const irep_idt &symbol_mode)
Adds instructions of the body block.
std::unordered_map< exprt, symbol_exprt, irep_hash > add_prehead_instructions(const std::size_t loop_id, goto_functionst::goto_functiont &goto_function, symbol_table_baset &symbol_table, goto_programt::targett loop_head, goto_programt::targett loop_latch, goto_programt &assigns_instrs, exprt &invariant, const exprt::operandst &assigns, const symbol_exprt &loop_write_set, const symbol_exprt &addr_of_loop_write_set, const symbol_exprt &entered_loop, const symbol_exprt &initial_invariant, const symbol_exprt &in_base_case, const irep_idt &symbol_mode)
Adds instructions of prehead block, and return history variables.
std::size_t get_max_assigns_clause_size() const
Maximum number of assigns clause targets.
void operator()(const std::size_t loop_id, const irep_idt &function_id, goto_functiont &goto_function, dfcc_cfg_infot &cfg_info, const std::set< symbol_exprt > &local_statics, std::set< irep_idt > &function_pointer_contracts)
Replaces a loop by a base + step abstraction generated from its contract.
goto_programt::instructiont::targett add_step_instructions(const std::size_t loop_id, const std::size_t cbmc_loop_id, const irep_idt &function_id, goto_functionst::goto_functiont &goto_function, symbol_table_baset &symbol_table, goto_programt::targett loop_head, goto_programt::targett loop_latch, goto_programt &havoc_instrs, exprt &invariant, const exprt::operandst &decreases_clauses, const symbol_exprt &loop_write_set, const exprt &outer_write_set, const symbol_exprt &initial_invariant, const symbol_exprt &in_base_case, const std::vector< symbol_exprt > &old_decreases_vars)
Adds instructions of the step block, and returns the STEP jump target so that it can be used to jump ...
dfcc_contract_clauses_codegent & contract_clauses_codegen
This class instruments GOTO functions or instruction sequences for frame condition checking and loop ...
Class interface to library types and functions defined in cprover_contracts.c.
Definition: dfcc_library.h:154
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
std::vector< exprt > operandst
Definition: expr.h:58
::goto_functiont goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:24
std::list< instructiont >::iterator targett
The target for gotos and for start_thread nodes.
Definition: goto_program.h:381
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
instructionst::iterator targett
Definition: goto_program.h:614
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
Expression to hold a symbol (variable)
Definition: std_expr.h:131
The symbol table base class interface.
Symbol Table + CFG.
Field-insensitive, location-sensitive may-alias analysis.