cprover
Loading...
Searching...
No Matches
dfcc_library.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_LIBRARY_H
13#define CPROVER_GOTO_INSTRUMENT_CONTRACTS_DYNAMIC_FRAMES_DFCC_LIBRARY_H
14
15#include <util/irep.h>
16#include <util/message.h>
17#include <util/optional.h>
18
20
21#include <map>
22#include <set>
23
27enum class dfcc_typet
28{
30 CAR,
32 CAR_SET,
36 OBJ_SET,
43};
44
143
144class goto_modelt;
145class goto_functiont;
146class goto_programt;
147class message_handlert;
148class symbolt;
149class symbol_exprt;
150class typet;
151
155{
156public:
159 message_handlert &lmessage_handler);
160
161protected:
163 static bool loaded;
164
166 static bool inlined;
167
170 static bool specialized;
171
173 static bool malloc_free_fixed;
174
178
181 std::set<irep_idt> get_missing_funs();
182
184 void inline_functions();
185
190
191private:
193 const std::map<dfcc_typet, irep_idt> dfcc_type_to_name;
194
196 const std::map<irep_idt, dfcc_typet> dfcc_name_to_type;
197
199 const std::map<dfcc_funt, irep_idt> dfcc_fun_to_name;
200
201 // Swapped dfcc_fun_to_name
202 const std::map<irep_idt, dfcc_funt> dfcc_name_to_fun;
203
205 const std::map<irep_idt, dfcc_funt> dfcc_hook;
206
208 const std::map<irep_idt, dfcc_funt> havoc_hook;
209
211 const std::set<irep_idt> assignable_builtin_names;
212
213public:
215 std::map<dfcc_typet, typet> dfcc_type;
216
218 std::map<dfcc_funt, symbolt> dfcc_fun_symbol;
219
223 void load(std::set<irep_idt> &to_instrument);
224
227
229 const irep_idt &get_dfcc_fun_name(dfcc_funt fun) const;
230
232 bool is_dfcc_library_symbol(const irep_idt &id) const;
233
237 void specialize(const std::size_t contract_assigns_size_hint);
238
249
252 void disable_checks();
253
257 bool is_front_end_builtin(const irep_idt &function_id) const;
258
262 dfcc_funt get_hook(const irep_idt &function_id) const;
263
267 optionalt<dfcc_funt> get_havoc_hook(const irep_idt &function_id) const;
268
277
281 const std::set<irep_idt> &instrumented_functions,
282 const source_locationt &source_location,
283 goto_programt &dest);
284
287 const exprt &write_set_ptr,
288 const exprt &contract_assigns_size,
289 const exprt &contract_frees_size,
290 const exprt &assume_requires_ctx,
291 const exprt &assert_requires_ctx,
292 const exprt &assume_ensures_ctx,
293 const exprt &assert_ensures_ctx,
294 const exprt &allow_allocate,
295 const exprt &allow_deallocate,
296 const source_locationt &source_location);
297
300 const exprt &write_set_ptr,
301 const exprt &contract_assigns_size,
302 const source_locationt &source_location);
303
306 const exprt &write_set_ptr,
307 const source_locationt &source_location);
308
311 const exprt &write_set_ptr,
312 const exprt &ptr,
313 const source_locationt &source_location);
314
317 const exprt &write_set_ptr,
318 const exprt &ptr,
319 const source_locationt &source_location);
320
323 const exprt &write_set_ptr,
324 const exprt &ptr,
325 const source_locationt &source_location);
326
330 const exprt &write_set_ptr,
331 const exprt &ptr,
332 const source_locationt &source_location);
333
337 const exprt &check_var,
338 const exprt &write_set_ptr,
339 const source_locationt &source_location);
340
344 const exprt &check_var,
345 const exprt &write_set_ptr,
346 const exprt &ptr,
347 const exprt &size,
348 const source_locationt &source_location);
349
353 const exprt &check_var,
354 const exprt &write_set_ptr,
355 const exprt &dest,
356 const source_locationt &source_location);
357
361 const exprt &check_var,
362 const exprt &write_set_ptr,
363 const exprt &dest,
364 const source_locationt &source_location);
365
369 const exprt &check_var,
370 const exprt &write_set_ptr,
371 const exprt &dest,
372 const exprt &src,
373 const source_locationt &source_location);
374
378 const exprt &check_var,
379 const exprt &write_set_ptr,
380 const exprt &ptr,
381 const source_locationt &source_location);
382
386 const exprt &check_var,
387 const exprt &write_set_ptr,
388 const exprt &ptr,
389 const source_locationt &source_location);
390
394 const exprt &check_var,
395 const exprt &reference_write_set_ptr,
396 const exprt &candidate_write_set_ptr,
397 const source_locationt &source_location);
398
402 const exprt &check_var,
403 const exprt &reference_write_set_ptr,
404 const exprt &candidate_write_set_ptr,
405 const source_locationt &source_location);
406
410 const exprt &write_set_ptr,
411 const exprt &target_write_set_ptr,
412 const source_locationt &source_location);
413
417 const exprt &write_set_ptr,
418 const exprt &is_fresh_obj_set_ptr,
419 const source_locationt &source_location);
420
424 const exprt &write_set_postconditions_ptr,
425 const exprt &write_set_to_link_ptr,
426 const source_locationt &source_location);
427
431 const exprt &write_set_postconditions_ptr,
432 const exprt &write_set_to_link_ptr,
433 const source_locationt &source_location);
434
438 const exprt &ptr,
439 const exprt &write_set_ptr,
440 const source_locationt &source_location);
441
445 const exprt &obj_set_ptr,
446 const source_locationt &source_location);
447
451 const exprt &obj_set_ptr,
452 const source_locationt &source_location);
453};
454
455#endif
goto_instruction_codet representation of a function call statement.
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 std::map< irep_idt, dfcc_funt > havoc_hook
Maps front-end functions to library functions giving their havoc semantics.
const code_function_callt write_set_check_allocated_deallocated_is_empty_call(const exprt &check_var, const exprt &write_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_allocated_deallocated_is_empty.
const code_function_callt obj_set_create_indexed_by_object_id_call(const exprt &obj_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_obj_set_create_indexed_by_object_id.
static bool inlined
True iff the library functions are inlined.
const std::map< irep_idt, dfcc_funt > dfcc_hook
Maps built-in function names to enums to use for instrumentation.
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.
static bool loaded
True iff the contracts library symbols are loaded.
dfcc_libraryt(goto_modelt &goto_model, message_handlert &lmessage_handler)
Class constructor.
void fix_malloc_free_calls()
Fixes function calls to malloc and free in library functions.
static bool malloc_free_fixed
True iff the library functions uses of malloc and free are fixed.
bool is_front_end_builtin(const irep_idt &function_id) const
Returns true iff the given function_id is one of __CPROVER_assignable, __CPROVER_object_whole,...
const code_function_callt link_allocated_call(const exprt &write_set_postconditions_ptr, const exprt &write_set_to_link_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_link_allocated.
const std::map< irep_idt, dfcc_typet > dfcc_name_to_type
Swapped dfcc_type_to_name.
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.
void inline_functions()
Inlines library functions that need to be inlined before use.
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 std::set< irep_idt > assignable_builtin_names
All built-in function names (front-end and instrumentation hooks)
void add_instrumented_functions_map_init_instructions(const std::set< irep_idt > &instrumented_functions, const source_locationt &source_location, goto_programt &dest)
Generates instructions to initialize the instrumented function map symbol from the given set of instr...
const std::map< dfcc_typet, irep_idt > dfcc_type_to_name
Enum to type name mapping.
const symbolt & get_instrumented_functions_map_symbol()
Returns the "__dfcc_instrumented_functions" symbol or creates it if it does not exist already.
const std::map< dfcc_funt, irep_idt > dfcc_fun_to_name
enum to function name mapping
const std::map< irep_idt, dfcc_funt > dfcc_name_to_fun
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_release_call(const exprt &write_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_release.
void inhibit_front_end_builtins()
Adds an ASSERT(false) body to all front-end functions __CPROVER_object_whole __CPROVER_object_upto __...
const code_function_callt obj_set_release_call(const exprt &obj_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_obj_set_release.
const irep_idt & get_dfcc_fun_name(dfcc_funt fun) const
Returns the name of the given dfcc_funt.
dfcc_funt get_hook(const irep_idt &function_id) const
Returns the library instrumentation hook for the given front-end function.
bool is_dfcc_library_symbol(const irep_idt &id) const
True iff the given id is one of the library symbols.
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.
const code_function_callt link_deallocated_call(const exprt &write_set_postconditions_ptr, const exprt &write_set_to_link_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_link_deallocated.
goto_modelt & goto_model
const code_function_callt write_set_check_assigns_clause_inclusion_call(const exprt &check_var, const exprt &reference_write_set_ptr, const exprt &candidate_write_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_assigns_clause_inclusion.
const code_function_callt link_is_fresh_call(const exprt &write_set_ptr, const exprt &is_fresh_obj_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_link_is_fresh.
message_handlert & message_handler
std::map< dfcc_typet, typet > dfcc_type
Maps enum values to the actual types (dynamically loaded)
std::set< irep_idt > get_missing_funs()
Collects the names of all library functions currently missing from the goto_model into missing.
const code_function_callt write_set_create_call(const exprt &write_set_ptr, const exprt &contract_assigns_size, const exprt &contract_frees_size, const exprt &assume_requires_ctx, const exprt &assert_requires_ctx, const exprt &assume_ensures_ctx, const exprt &assert_ensures_ctx, const exprt &allow_allocate, const exprt &allow_deallocate, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_create.
const code_function_callt write_set_check_frees_clause_inclusion_call(const exprt &check_var, const exprt &reference_write_set_ptr, const exprt &candidate_write_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_check_frees_clause_inclusion.
optionalt< dfcc_funt > get_dfcc_fun(const irep_idt &id) const
Returns the dfcc_funt that corresponds to the given id if any.
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.
void disable_checks()
Adds "checked" pragmas to instructions of all library functions instructions.
const code_function_callt check_replace_ensures_was_freed_preconditions_call(const exprt &ptr, const exprt &write_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_check_replace_ensures_was_freed_preconditions.
const code_function_callt write_set_deallocate_freeable_call(const exprt &write_set_ptr, const exprt &target_write_set_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_write_set_deallocate_freeable.
void specialize(const std::size_t contract_assigns_size_hint)
Specializes the library by unwinding loops in library functions to the given assigns clause size.
optionalt< dfcc_funt > get_havoc_hook(const irep_idt &function_id) const
Returns the library instrumentation hook for the given built-in.
std::map< dfcc_funt, symbolt > dfcc_fun_symbol
Maps enum values to the actual function symbols (dynamically loaded)
void load(std::set< irep_idt > &to_instrument)
After calling this function, all library types and functions are present in the the goto_model.
static bool specialized
True iff the library functions are specialized to a particular contract.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:39
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.
Class that provides messages with a built-in verbosity 'level'.
Definition message.h:155
Expression to hold a symbol (variable)
Definition std_expr.h:113
Symbol table entry.
Definition symbol.h:28
The type of an expression, extends irept.
Definition type.h:29
dfcc_funt
One enum value per function defined by the cprover_dfcc.c library file.
@ WRITE_SET_INSERT_OBJECT_UPTO
@ CAR_SET_CONTAINS
@ WRITE_SET_CHECK_ASSIGNMENT
@ WRITE_SET_INSERT_ASSIGNABLE
@ WRITE_SET_CHECK_FREES_CLAUSE_INCLUSION
@ POINTER_IN_RANGE_DFCC
@ OBJ_SET_CREATE_APPEND
@ WRITE_SET_RELEASE
@ WRITE_SET_INSERT_OBJECT_WHOLE
@ WRITE_SET_DEALLOCATE_FREEABLE
@ WRITE_SET_CHECK_ARRAY_REPLACE
@ LINK_DEALLOCATED
@ WRITE_SET_CHECK_HAVOC_OBJECT
@ OBJ_SET_CREATE_INDEXED_BY_OBJECT_ID
@ WRITE_SET_CHECK_DEALLOCATE
@ WRITE_SET_CHECK_ALLOCATED_DEALLOCATED_IS_EMPTY
@ WRITE_SET_CHECK_ARRAY_SET
@ WRITE_SET_RECORD_DEAD
@ WRITE_SET_HAVOC_SLICE
@ WRITE_SET_CHECK_ASSIGNS_CLAUSE_INCLUSION
@ WRITE_SET_HAVOC_GET_ASSIGNABLE_TARGET
@ OBJ_SET_CONTAINS
@ WRITE_SET_CREATE
@ WRITE_SET_CHECK_ARRAY_COPY
@ WRITE_SET_ADD_FREEABLE
@ REPLACE_ENSURES_WAS_FREED_PRECONDITIONS
@ WRITE_SET_ADD_DECL
@ WRITE_SET_RECORD_DEALLOCATED
@ OBJ_SET_CONTAINS_EXACT
@ WRITE_SET_ADD_ALLOCATED
@ WRITE_SET_HAVOC_OBJECT_WHOLE
@ WRITE_SET_INSERT_OBJECT_FROM
dfcc_typet
One enum value per type defined by the cprover_dfcc.c library file.
@ WRITE_SET
type of descriptors of assignable/freeable sets of locations
@ CAR_SET_PTR
type of pointers to sets of CAR
@ CAR_SET
type of sets of CAR
@ OBJ_SET_PTR
type of pointers to sets of object identifiers
@ OBJ_SET
type of sets of object identifiers
@ WRITE_SET_PTR
type of pointers to descriptors of assignable/freeable sets of locations
@ CAR
type of descriptors of conditionally assignable ranges of bytes
nonstd::optional< T > optionalt
Definition optional.h:35