CBMC
Loading...
Searching...
No Matches
dfcc_library.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Dynamic frame condition checking
4
5Author: Remi Delmas, delmarsd@amazon.com
6
7\*******************************************************************/
8
9#include "dfcc_library.h"
10
11#include <util/arith_tools.h>
12#include <util/c_types.h>
13#include <util/config.h>
14#include <util/cprover_prefix.h>
15#include <util/message.h>
16#include <util/pointer_expr.h>
18#include <util/std_code.h>
19#include <util/std_expr.h>
20
24
25#include <ansi-c/c_expr.h>
32
33#include "dfcc_utils.h"
34
36template <typename K, typename V>
37std::map<V, K> swap_map(std::map<K, V> const &map)
38{
39 std::map<V, K> result;
40 for(auto const &pair : map)
41 result.insert({pair.second, pair.first});
42 return result;
43}
44
45// NOLINTNEXTLINE(build/deprecated)
46#define CONTRACTS_PREFIX CPROVER_PREFIX "contracts_"
47
49const std::map<dfcc_typet, irep_idt> create_dfcc_type_to_name()
50{
51 return std::map<dfcc_typet, irep_idt>{
56 {dfcc_typet::PTR_PRED_CTX_PTR, CONTRACTS_PREFIX "ptr_pred_ctx_ptr_t"},
60 {dfcc_typet::WRITE_SET_PTR, CONTRACTS_PREFIX "write_set_ptr_t"}};
61}
62
63const std::map<dfcc_funt, irep_idt> create_dfcc_fun_to_name()
64{
65 return {
72 CONTRACTS_PREFIX "obj_set_create_indexed_by_object_id"},
74 CONTRACTS_PREFIX "obj_set_create_append"},
81 CONTRACTS_PREFIX "obj_set_contains_exact"},
85 CONTRACTS_PREFIX "write_set_insert_assignable"},
87 CONTRACTS_PREFIX "write_set_insert_object_whole"},
89 CONTRACTS_PREFIX "write_set_insert_object_from"},
91 CONTRACTS_PREFIX "write_set_insert_object_upto"},
93 CONTRACTS_PREFIX "write_set_add_freeable"},
95 CONTRACTS_PREFIX "write_set_add_allocated"},
96 {dfcc_funt::WRITE_SET_ADD_DECL, CONTRACTS_PREFIX "write_set_add_decl"},
98 CONTRACTS_PREFIX "write_set_record_dead"},
100 CONTRACTS_PREFIX "write_set_record_deallocated"},
102 CONTRACTS_PREFIX "write_set_check_allocated_deallocated_is_empty"},
104 CONTRACTS_PREFIX "write_set_check_assignment"},
106 CONTRACTS_PREFIX "write_set_check_array_set"},
108 CONTRACTS_PREFIX "write_set_check_array_copy"},
110 CONTRACTS_PREFIX "write_set_check_array_replace"},
112 CONTRACTS_PREFIX "write_set_check_havoc_object"},
114 CONTRACTS_PREFIX "write_set_check_deallocate"},
116 CONTRACTS_PREFIX "write_set_check_assigns_clause_inclusion"},
118 CONTRACTS_PREFIX "write_set_check_frees_clause_inclusion"},
120 CONTRACTS_PREFIX "write_set_deallocate_freeable"},
122 CONTRACTS_PREFIX "write_set_havoc_get_assignable_target"},
124 CONTRACTS_PREFIX "write_set_havoc_object_whole"},
126 CONTRACTS_PREFIX "write_set_havoc_slice"},
127 {dfcc_funt::LINK_PTR_PRED_CTX, CONTRACTS_PREFIX "link_ptr_pred_ctx"},
129 {dfcc_funt::LINK_DEALLOCATED, CONTRACTS_PREFIX "link_deallocated"},
130 {dfcc_funt::PTR_PRED_CTX_INIT, CONTRACTS_PREFIX "ptr_pred_ctx_init"},
131 {dfcc_funt::PTR_PRED_CTX_RESET, CONTRACTS_PREFIX "ptr_pred_ctx_reset"},
135 CONTRACTS_PREFIX "pointer_in_range_dfcc"},
139 CONTRACTS_PREFIX "check_replace_ensures_was_freed_preconditions"},
140 {dfcc_funt::OBEYS_CONTRACT, CONTRACTS_PREFIX "obeys_contract"}};
141}
142
152
153const std::map<irep_idt, dfcc_funt> create_havoc_hook()
154{
155 return {
156 {CPROVER_PREFIX "assignable",
161}
162
163const std::set<irep_idt> create_assignable_builtin_names()
164{
165 return {
166 CPROVER_PREFIX "assignable",
167 CPROVER_PREFIX "assignable_set_insert_assignable",
168 CPROVER_PREFIX "object_whole",
169 CPROVER_PREFIX "assignable_set_insert_object_whole",
170 CPROVER_PREFIX "object_from",
171 CPROVER_PREFIX "assignable_set_insert_object_from",
172 CPROVER_PREFIX "object_upto",
173 CPROVER_PREFIX "assignable_set_insert_object_upto",
174 CPROVER_PREFIX "freeable",
175 CPROVER_PREFIX "assignable_set_add_freeable"};
176}
177
180 goto_modelt &goto_model,
181 message_handlert &message_handler)
182 : goto_model(goto_model),
183 message_handler(message_handler),
184 log(message_handler),
185 dfcc_type_to_name(create_dfcc_type_to_name()),
186 dfcc_name_to_type(swap_map<dfcc_typet, irep_idt>(dfcc_type_to_name)),
187 dfcc_fun_to_name(create_dfcc_fun_to_name()),
188 dfcc_name_to_fun(swap_map<dfcc_funt, irep_idt>(dfcc_fun_to_name)),
189 dfcc_hook(create_dfcc_hook()),
190 havoc_hook(create_havoc_hook()),
191 assignable_builtin_names(create_assignable_builtin_names())
192{
193 // Add the instrumented map symbol to the symbol table.
195}
196
198bool dfcc_libraryt::is_front_end_builtin(const irep_idt &function_id) const
199{
200 return dfcc_hook.find(function_id) != dfcc_hook.end();
201}
202
205{
207 return dfcc_hook.find(function_id)->second;
208}
209
210// Returns the havoc function to use for a given front-end function
211std::optional<dfcc_funt>
213{
214 auto found = havoc_hook.find(function_id);
215 if(found != havoc_hook.end())
216 return {found->second};
217 else
218 return {};
219}
220
222{
223 sl.add_pragma("disable:pointer-check");
224 sl.add_pragma("disable:pointer-primitive-check");
225 sl.add_pragma("disable:pointer-overflow-check");
226 sl.add_pragma("disable:signed-overflow-check");
227 sl.add_pragma("disable:unsigned-overflow-check");
228 sl.add_pragma("disable:conversion-check");
229 sl.add_pragma("disable:undefined-shift-check");
230}
231
233{
234 for(const auto &pair : dfcc_fun_to_name)
235 {
236 auto &function = goto_model.goto_functions.function_map[pair.second];
237 for(auto &inst : function.body.instructions)
238 {
239 add_checked_pragmas(inst.source_location_nonconst());
240 }
241 }
242}
243
245{
246 std::set<irep_idt> missing;
247
248 // add `malloc` since it is needed used by the `is_fresh` function
249 missing.insert("malloc");
250
251 // add `free` and `__CPROVER_deallocate` since they are used by the
252 // `write_set_deallocate_freeable`
253 missing.insert("free");
254
255 // used by `write_set_release`
256 missing.insert(CPROVER_PREFIX "deallocate");
257
258 // Make sure all front end functions are loaded
259 missing.insert(CPROVER_PREFIX "assignable");
260 missing.insert(CPROVER_PREFIX "object_from");
261 missing.insert(CPROVER_PREFIX "object_upto");
262 missing.insert(CPROVER_PREFIX "object_whole");
263 missing.insert(CPROVER_PREFIX "freeable");
264
265 // go over all library functions
266 for(const auto &pair : dfcc_fun_to_name)
267 {
268 symbol_tablet::symbolst::const_iterator found =
269 goto_model.symbol_table.symbols.find(pair.second);
270
271 if(
273 found->second.value.is_nil())
274 {
275 missing.insert(pair.second);
276 }
277 }
278 return missing;
279}
280
281bool dfcc_libraryt::loaded = false;
282
283void dfcc_libraryt::load(std::set<irep_idt> &to_instrument)
284{
286 !loaded, "the cprover_contracts library can only be loaded once");
287 loaded = true;
288
289 log.status() << "Adding the cprover_contracts library (" << config.ansi_c.arch
290 << ")" << messaget::eom;
291
292 // these will need to get instrumented as well
293 to_instrument.insert("malloc");
294 to_instrument.insert("free");
295 to_instrument.insert(CPROVER_PREFIX "deallocate");
296
297 std::set<irep_idt> to_load;
298
299 // add the whole library
300 to_load.insert(CPROVER_PREFIX "contracts_library");
301
302 // add front end functions
303 to_load.insert(CPROVER_PREFIX "assignable");
304 to_load.insert(CPROVER_PREFIX "object_from");
305 to_load.insert(CPROVER_PREFIX "object_upto");
306 to_load.insert(CPROVER_PREFIX "object_whole");
307 to_load.insert(CPROVER_PREFIX "freeable");
308
309 // add stdlib dependences
310 to_load.insert("malloc");
311 to_load.insert("free");
312 to_load.insert(CPROVER_PREFIX "deallocate");
313
317
318 // compute missing library functions before modifying the symbol table
319 std::set<irep_idt> missing = get_missing_funs();
320
321 // copy all loaded symbols to the main symbol table
322 for(const auto &symbol_pair : tmp_symbol_table.symbols)
323 {
324 const auto &sym = symbol_pair.first;
327 }
328
329 // compile all missing library functions to GOTO
330 for(const auto &id : missing)
331 {
335 }
336
337 // check that all symbols have a goto_implementation
338 // and populate symbol maps
340 for(const auto &pair : dfcc_fun_to_name)
341 {
342 const auto &found =
344
345 INVARIANT(
347 found->second.body_available(),
348 "The body of DFCC library function " + id2string(pair.second) +
349 " could not be found");
350
351 dfcc_fun_symbol[pair.first] = ns.lookup(pair.second);
352 }
353
354 // populate symbol maps for easy access to symbols during translation
355 for(const auto &pair : dfcc_type_to_name)
356 {
357 dfcc_type[pair.first] = ns.lookup(pair.second).type;
358 }
359
360 // fix malloc and free calls
362
363 // inline the functions that need to be inlined for perf reasons
365
366 // hide all instructions in counter example traces
367 for(auto it : dfcc_fun_symbol)
368 goto_model.goto_functions.function_map.at(it.second.name).make_hidden();
369}
370
371std::optional<dfcc_funt> dfcc_libraryt::get_dfcc_fun(const irep_idt &id) const
372{
373 auto found = dfcc_name_to_fun.find(id);
374 if(found != dfcc_name_to_fun.end())
375 return {found->second};
376 else
377 return {};
378}
379
381{
382 return get_dfcc_fun(id).has_value();
383}
384
389
409
410bool dfcc_libraryt::inlined = false;
411
413{
414 INVARIANT(!inlined, "inline_functions can only be called once");
415 inlined = true;
416 for(const auto &function_id : to_inline)
417 {
420 }
421}
422
432
433bool dfcc_libraryt::specialized = false;
434
436{
437 INVARIANT(
439 "dfcc_libraryt::specialize_functions can only be called once");
440
441 specialized = true;
442 std::list<std::string> loop_names;
443
444 for(const auto &entry : to_unwind)
445 {
446 const auto &function = entry.first;
447 const auto &loop_id = entry.second;
448 std::stringstream stream;
449 stream << id2string(dfcc_fun_to_name.at(function)) << "." << loop_id << ":"
451 const auto &str = stream.str();
452 loop_names.push_back(str);
453 }
454 unwindsett unwindset;
455 unwindset.parse_unwindset(loop_names, goto_model, message_handler);
459}
460
465
468
470{
471 INVARIANT(
473 "dfcc_libraryt::fix_malloc_free_calls can only be called once");
474 malloc_free_fixed = true;
475 for(const auto fun : fix_malloc_free_set)
476 {
479
481 {
482 if(ins->is_function_call())
483 {
484 const auto &function = ins->call_function();
485
486 if(function.id() == ID_symbol)
487 {
488 const irep_idt &fun_name = to_symbol_expr(function).get_identifier();
489
490 if(fun_name == (CONTRACTS_PREFIX "malloc"))
491 to_symbol_expr(ins->call_function()).set_identifier("malloc");
492 else if(fun_name == (CONTRACTS_PREFIX "free"))
493 to_symbol_expr(ins->call_function()).set_identifier("free");
494 }
495 }
496 }
497 }
498}
499
501{
502 // not using assume-false in order not to hinder coverage
503 std::string options = "assert-false";
504 c_object_factory_parameterst object_factory_params;
506 options, object_factory_params, goto_model.symbol_table, message_handler);
507 for(const auto &it : dfcc_hook)
508 {
509 const auto &function_id = it.first;
510 if(goto_model.symbol_table.has_symbol(function_id))
511 {
512 auto &goto_function =
513 goto_model.goto_functions.function_map.at(function_id);
514
515 generate_function_bodies->generate_function_body(
516 goto_function, goto_model.symbol_table, function_id);
517 }
518 }
519}
520
522{
523 const irep_idt map_name = "__dfcc_instrumented_functions";
524
527
528 auto map_type =
530
533 map_type,
534 "",
535 "__dfcc_instrumented_functions",
537 ID_C,
538 "<built-in-library>",
539 array_of_exprt(from_integer(0, map_type.element_type()), map_type),
540 true);
541}
542
544 const std::set<irep_idt> &instrumented_functions,
545 const source_locationt &source_location,
546 goto_programt &dest)
547{
550
551 std::map<std::string, irep_idt> sorted_instrumented_functions;
552 for(const auto &function_id : instrumented_functions)
553 sorted_instrumented_functions.insert({id2string(function_id), function_id});
554
555 for(const auto &[_, function_id] : sorted_instrumented_functions)
556 {
558 dfcc_utilst::get_function_symbol(goto_model.symbol_table, function_id)
559 .symbol_expr()));
562 index_expr, from_integer(1, unsigned_char_type()), source_location));
563 }
564 goto_model.goto_functions.update();
565}
566
569 const exprt &max_assigns_clause_size,
571 const exprt &assume_requires_ctx,
572 const exprt &assert_requires_ctx,
573 const exprt &assume_ensures_ctx,
574 const exprt &assert_ensures_ctx,
575 const exprt &allow_allocate,
576 const exprt &allow_deallocate,
577 const source_locationt &source_location)
578{
579 auto function_symbol =
582 auto &arguments = call.arguments();
583 // check that address_of_write_set.type() is dfcc_typet::WRITE_SET_PTR
584 arguments.emplace_back(address_of_write_set);
585 PRECONDITION(max_assigns_clause_size.type() == size_type());
586 arguments.emplace_back(max_assigns_clause_size);
588 arguments.emplace_back(max_frees_clause_size);
589 arguments.push_back(assume_requires_ctx);
590 arguments.push_back(assert_requires_ctx);
591 arguments.push_back(assume_ensures_ctx);
592 arguments.push_back(assert_ensures_ctx);
593 arguments.push_back(allow_allocate);
594 arguments.push_back(allow_deallocate);
595 call.add_source_location() = source_location;
596 return call;
597}
598
601 const exprt &max_assigns_clause_size,
602 const source_locationt &source_location)
603{
606 max_assigns_clause_size,
608 false_exprt(),
609 false_exprt(),
610 false_exprt(),
611 false_exprt(),
612 false_exprt(),
613 false_exprt(),
614 source_location);
615}
616
618 const exprt &write_set_ptr,
619 const source_locationt &source_location)
620{
623 {write_set_ptr});
624 call.add_source_location() = source_location;
625 return call;
626}
627
629 const exprt &write_set_ptr,
630 const exprt &ptr,
631 const source_locationt &source_location)
632{
635 {write_set_ptr, ptr});
636 call.add_source_location() = source_location;
637 return call;
638}
639
641 const exprt &write_set_ptr,
642 const exprt &ptr,
643 const source_locationt &source_location)
644{
647 {write_set_ptr, ptr});
648 call.add_source_location() = source_location;
649 return call;
650}
651
653 const exprt &write_set_ptr,
654 const exprt &ptr,
655 const source_locationt &source_location)
656{
659 {write_set_ptr, ptr});
660 call.add_source_location() = source_location;
661 return call;
662}
663
665 const exprt &write_set_ptr,
666 const exprt &ptr,
667 const source_locationt &source_location)
668{
671 {write_set_ptr, ptr});
672 call.add_source_location() = source_location;
673 return call;
674}
675
678 const exprt &check_var,
679 const exprt &write_set_ptr,
680 const source_locationt &source_location)
681{
683 check_var,
685 .symbol_expr(),
686 {write_set_ptr});
687 call.add_source_location() = source_location;
688 return call;
689}
690
692 const exprt &check_var,
693 const exprt &write_set_ptr,
694 const exprt &ptr,
695 const exprt &size,
696 const source_locationt &source_location)
697{
699 check_var,
701 {write_set_ptr, ptr, size});
702 call.add_source_location() = source_location;
703 return call;
704}
705
707 const exprt &check_var,
708 const exprt &write_set_ptr,
709 const exprt &dest,
710 const source_locationt &source_location)
711{
713 check_var,
715 {write_set_ptr, dest});
716 call.add_source_location() = source_location;
717 return call;
718}
719
721 const exprt &check_var,
722 const exprt &write_set_ptr,
723 const exprt &dest,
724 const source_locationt &source_location)
725{
727 check_var,
729 {write_set_ptr, dest});
730 call.add_source_location() = source_location;
731 return call;
732}
733
735 const exprt &check_var,
736 const exprt &write_set_ptr,
737 const exprt &dest,
738 const exprt &src,
739 const source_locationt &source_location)
740{
742 check_var,
744 {write_set_ptr, dest, src});
745 call.add_source_location() = source_location;
746 return call;
747}
748
750 const exprt &check_var,
751 const exprt &write_set_ptr,
752 const exprt &ptr,
753 const source_locationt &source_location)
754{
756 check_var,
758 {write_set_ptr, ptr});
759 call.add_source_location() = source_location;
760 return call;
761}
762
764 const exprt &check_var,
765 const exprt &write_set_ptr,
766 const exprt &ptr,
767 const source_locationt &source_location)
768{
770 check_var,
772 {write_set_ptr, ptr});
773 call.add_source_location() = source_location;
774 return call;
775}
776
792
808
810 const exprt &write_set_ptr,
812 const source_locationt &source_location)
813{
817 call.add_source_location() = source_location;
818 return call;
819}
820
822 const exprt &write_set_ptr,
823 const exprt &ptr_pred_ctx_ptr,
824 const source_locationt &source_location)
825{
829 call.add_source_location() = source_location;
830 return call;
831}
832
836 const source_locationt &source_location)
837{
841 call.add_source_location() = source_location;
842 return call;
843}
844
848 const source_locationt &source_location)
849{
853 call.add_source_location() = source_location;
854 return call;
855}
856
859 const exprt &ptr,
860 const exprt &write_set_ptr,
861 const source_locationt &source_location)
862{
865 .symbol_expr(),
866 {ptr, write_set_ptr});
867 call.add_source_location() = source_location;
868 return call;
869}
870
873 const exprt &obj_set_ptr,
874 const source_locationt &source_location)
875{
878 .symbol_expr(),
879 {obj_set_ptr});
880 call.add_source_location() = source_location;
881 return call;
882}
883
885 const exprt &obj_set_ptr,
886 const source_locationt &source_location)
887{
890 call.add_source_location() = source_location;
891 return call;
892}
893
895 const exprt &ptr_pred_ctx_ptr,
896 const source_locationt &source_location)
897{
901 call.add_source_location() = source_location;
902 return call;
903}
904
906 const exprt &ptr_pred_ctx_ptr,
907 const source_locationt &source_location)
908{
912 call.add_source_location() = source_location;
913 return call;
914}
void cprover_c_library_factory_force_load(const std::set< irep_idt > &functions, symbol_table_baset &symbol_table, message_handlert &message_handler)
Load the requested function symbols from the cprover library and add them to the symbol table regardl...
configt config
Definition config.cpp:25
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
API to expression classes that are internal to the C frontend.
unsignedbv_typet unsigned_char_type()
Definition c_types.cpp:127
Operator to return the address of an object.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
Array constructor from single element.
Definition std_expr.h:1502
Arrays with given size.
Definition std_types.h:807
goto_instruction_codet representation of a function call statement.
struct configt::ansi_ct ansi_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 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 link_ptr_pred_ctx_call(const exprt &write_set_ptr, const exprt &ptr_pred_ctx_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_link_ptr_pred_ctx.
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.
std::optional< dfcc_funt > get_dfcc_fun(const irep_idt &id) const
Returns the dfcc_funt that corresponds to the given id if any.
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.
const code_function_callt ptr_pred_ctx_init_call(const exprt &ptr_pred_ctx_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_ptr_pred_ctx_init.
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.
const code_function_callt ptr_pred_ctx_reset_call(const exprt &ptr_pred_ctx_ptr, const source_locationt &source_location)
Builds call to __CPROVER_contracts_ptr_pred_ctx_init.
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.
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.
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.
std::map< dfcc_funt, symbolt > dfcc_fun_symbol
Maps enum values to the actual function symbols (dynamically loaded)
std::optional< dfcc_funt > get_havoc_hook(const irep_idt &function_id) const
Returns the library instrumentation hook for the given built-in.
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:38
Base class for all expressions.
Definition expr.h:57
typet & type()
Return the type of the expression.
Definition expr.h:85
The Boolean constant false.
Definition std_expr.h:3125
function_mapt function_map
symbol_tablet symbol_table
Symbol table.
Definition goto_model.h:31
goto_functionst goto_functions
GOTO functions.
Definition goto_model.h:34
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
Array index operator.
Definition std_expr.h:1421
An expression denoting infinity.
Definition std_expr.h:3150
static eomt eom
Definition message.h:289
mstreamt & status() const
Definition message.h:406
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition namespace.h:91
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
const symbolt & lookup_ref(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
The symbol table.
virtual std::pair< symbolt &, bool > insert(symbolt symbol) override
Author: Diffblue Ltd.
Symbol table entry.
Definition symbol.h:28
void set_compiled()
Set the symbol's value to "compiled"; to be used once the code-typed value has been converted to a go...
Definition symbol.h:120
void parse_unwindset(const std::list< std::string > &unwindset, abstract_goto_modelt &goto_model, message_handlert &message_handler)
#define CPROVER_PREFIX
#define CONTRACTS_PREFIX
const std::map< irep_idt, dfcc_funt > create_havoc_hook()
static const std::set< dfcc_funt > to_inline
set of functions that need to be inlined
const std::map< dfcc_funt, irep_idt > create_dfcc_fun_to_name()
const std::set< irep_idt > create_assignable_builtin_names()
static void add_checked_pragmas(source_locationt &sl)
const std::map< dfcc_typet, irep_idt > create_dfcc_type_to_name()
Creates the enum to type name mapping.
std::map< V, K > swap_map(std::map< K, V > const &map)
Swaps keys and values in a map.
static const std::set< dfcc_funt > fix_malloc_free_set
Set of functions that contain calls to assignable_malloc or assignable_free.
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.
const std::map< irep_idt, dfcc_funt > create_dfcc_hook()
Dynamic frame condition checking library loading.
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
@ PTR_PRED_CTX_RESET
@ PTR_PRED_CTX_INIT
@ 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
@ LINK_PTR_PRED_CTX
@ 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
@ PTR_PRED_CTX_PTR
type of pointers to context info for pointer predicates evaluation
@ 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
@ PTR_PRED_CTX
type of context info for pointer predicates evaluation
@ 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
Dynamic frame condition checking utility functions.
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, bool ignore_no_match)
Generate function bodies with some default behavior: assert-false, assume-false, assert-false-assume-...
void goto_convert(const codet &code, symbol_table_baset &symbol_table, goto_programt &dest, message_handlert &message_handler, const irep_idt &mode)
Goto Programs with Functions.
Goto Function.
Symbol Table + CFG.
#define Forall_goto_program_instructions(it, program)
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
double log(double x)
Definition math.c:2416
API to expression classes for Pointers.
exprt pointer_object(const exprt &p)
Various predicates over pointers in programs.
#define PRECONDITION_WITH_DIAGNOSTICS(CONDITION,...)
Definition invariant.h:464
#define PRECONDITION(CONDITION)
Definition invariant.h:463
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
API to expression classes.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition std_expr.h:211
static symbolt & get_function_symbol(symbol_table_baset &, const irep_idt &function_id)
Returns the symbolt for function_id.
static void inline_function(goto_modelt &goto_model, const irep_idt &function_id, message_handlert &message_handler)
Inlines the given function, aborts on recursive calls during inlining.
static const symbolt & create_static_symbol(symbol_table_baset &, const typet &type, const std::string &prefix, const std::string &base_name, const source_locationt &source_location, const irep_idt &mode, const irep_idt &module, const exprt &initial_value, const bool no_nondet_initialization=true)
Adds a new static symbol named prefix::base_name of type type with value initial_value in the symbol ...
#define size_type
Definition unistd.c:186
Loop unwinding.
Loop unwinding.