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
23
24#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 unwindsett unwindset{goto_model};
443 std::list<std::string> loop_names;
444
445 for(const auto &entry : to_unwind)
446 {
447 const auto &function = entry.first;
448 const auto &loop_id = entry.second;
449 std::stringstream stream;
450 stream << id2string(dfcc_fun_to_name.at(function)) << "." << loop_id << ":"
452 const auto &str = stream.str();
453 loop_names.push_back(str);
454 }
455 unwindset.parse_unwindset(loop_names, 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
562
565 const exprt &max_assigns_clause_size,
567 const exprt &assume_requires_ctx,
568 const exprt &assert_requires_ctx,
569 const exprt &assume_ensures_ctx,
570 const exprt &assert_ensures_ctx,
571 const exprt &allow_allocate,
572 const exprt &allow_deallocate,
573 const source_locationt &source_location)
574{
575 auto function_symbol =
578 auto &arguments = call.arguments();
579 // check that address_of_write_set.type() is dfcc_typet::WRITE_SET_PTR
580 arguments.emplace_back(address_of_write_set);
581 PRECONDITION(max_assigns_clause_size.type() == size_type());
582 arguments.emplace_back(max_assigns_clause_size);
584 arguments.emplace_back(max_frees_clause_size);
585 arguments.push_back(assume_requires_ctx);
586 arguments.push_back(assert_requires_ctx);
587 arguments.push_back(assume_ensures_ctx);
588 arguments.push_back(assert_ensures_ctx);
589 arguments.push_back(allow_allocate);
590 arguments.push_back(allow_deallocate);
591 call.add_source_location() = source_location;
592 return call;
593}
594
597 const exprt &max_assigns_clause_size,
598 const source_locationt &source_location)
599{
602 max_assigns_clause_size,
604 false_exprt(),
605 false_exprt(),
606 false_exprt(),
607 false_exprt(),
608 false_exprt(),
609 false_exprt(),
610 source_location);
611}
612
614 const exprt &write_set_ptr,
615 const source_locationt &source_location)
616{
619 {write_set_ptr});
620 call.add_source_location() = source_location;
621 return call;
622}
623
625 const exprt &write_set_ptr,
626 const exprt &ptr,
627 const source_locationt &source_location)
628{
631 {write_set_ptr, ptr});
632 call.add_source_location() = source_location;
633 return call;
634}
635
637 const exprt &write_set_ptr,
638 const exprt &ptr,
639 const source_locationt &source_location)
640{
643 {write_set_ptr, ptr});
644 call.add_source_location() = source_location;
645 return call;
646}
647
649 const exprt &write_set_ptr,
650 const exprt &ptr,
651 const source_locationt &source_location)
652{
655 {write_set_ptr, ptr});
656 call.add_source_location() = source_location;
657 return call;
658}
659
661 const exprt &write_set_ptr,
662 const exprt &ptr,
663 const source_locationt &source_location)
664{
667 {write_set_ptr, ptr});
668 call.add_source_location() = source_location;
669 return call;
670}
671
674 const exprt &check_var,
675 const exprt &write_set_ptr,
676 const source_locationt &source_location)
677{
679 check_var,
681 .symbol_expr(),
682 {write_set_ptr});
683 call.add_source_location() = source_location;
684 return call;
685}
686
688 const exprt &check_var,
689 const exprt &write_set_ptr,
690 const exprt &ptr,
691 const exprt &size,
692 const source_locationt &source_location)
693{
695 check_var,
697 {write_set_ptr, ptr, size});
698 call.add_source_location() = source_location;
699 return call;
700}
701
703 const exprt &check_var,
704 const exprt &write_set_ptr,
705 const exprt &dest,
706 const source_locationt &source_location)
707{
709 check_var,
711 {write_set_ptr, dest});
712 call.add_source_location() = source_location;
713 return call;
714}
715
717 const exprt &check_var,
718 const exprt &write_set_ptr,
719 const exprt &dest,
720 const source_locationt &source_location)
721{
723 check_var,
725 {write_set_ptr, dest});
726 call.add_source_location() = source_location;
727 return call;
728}
729
731 const exprt &check_var,
732 const exprt &write_set_ptr,
733 const exprt &dest,
734 const exprt &src,
735 const source_locationt &source_location)
736{
738 check_var,
740 {write_set_ptr, dest, src});
741 call.add_source_location() = source_location;
742 return call;
743}
744
746 const exprt &check_var,
747 const exprt &write_set_ptr,
748 const exprt &ptr,
749 const source_locationt &source_location)
750{
752 check_var,
754 {write_set_ptr, ptr});
755 call.add_source_location() = source_location;
756 return call;
757}
758
760 const exprt &check_var,
761 const exprt &write_set_ptr,
762 const exprt &ptr,
763 const source_locationt &source_location)
764{
766 check_var,
768 {write_set_ptr, ptr});
769 call.add_source_location() = source_location;
770 return call;
771}
772
788
804
806 const exprt &write_set_ptr,
808 const source_locationt &source_location)
809{
813 call.add_source_location() = source_location;
814 return call;
815}
816
818 const exprt &write_set_ptr,
819 const exprt &ptr_pred_ctx_ptr,
820 const source_locationt &source_location)
821{
825 call.add_source_location() = source_location;
826 return call;
827}
828
832 const source_locationt &source_location)
833{
837 call.add_source_location() = source_location;
838 return call;
839}
840
844 const source_locationt &source_location)
845{
849 call.add_source_location() = source_location;
850 return call;
851}
852
855 const exprt &ptr,
856 const exprt &write_set_ptr,
857 const source_locationt &source_location)
858{
861 .symbol_expr(),
862 {ptr, write_set_ptr});
863 call.add_source_location() = source_location;
864 return call;
865}
866
869 const exprt &obj_set_ptr,
870 const source_locationt &source_location)
871{
874 .symbol_expr(),
875 {obj_set_ptr});
876 call.add_source_location() = source_location;
877 return call;
878}
879
881 const exprt &obj_set_ptr,
882 const source_locationt &source_location)
883{
886 call.add_source_location() = source_location;
887 return call;
888}
889
891 const exprt &ptr_pred_ctx_ptr,
892 const source_locationt &source_location)
893{
897 call.add_source_location() = source_location;
898 return call;
899}
900
902 const exprt &ptr_pred_ctx_ptr,
903 const source_locationt &source_location)
904{
908 call.add_source_location() = source_location;
909 return call;
910}
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:562
Array constructor from single element.
Definition std_expr.h:1558
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:56
typet & type()
Return the type of the expression.
Definition expr.h:84
The Boolean constant false.
Definition std_expr.h:3199
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.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
Array index operator.
Definition std_expr.h:1470
An expression denoting infinity.
Definition std_expr.h:3224
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
#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)
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:2449
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:272
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.