CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dfcc_wrapper_program.cpp
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\*******************************************************************/
9
10#include <util/arith_tools.h>
11#include <util/c_types.h>
12#include <util/expr_util.h>
13#include <util/format_expr.h>
14#include <util/invariant.h>
16#include <util/namespace.h>
18#include <util/std_expr.h>
19
21
22#include <ansi-c/c_expr.h>
25
27#include "dfcc_instrument.h"
29#include "dfcc_library.h"
31#include "dfcc_pointer_equals.h"
32#include "dfcc_utils.h"
33
36 symbol_table_baset &symbol_table,
37 dfcc_libraryt &library,
38 const symbolt &wrapper_symbol)
39{
41 symbol_table,
43 wrapper_symbol.name,
44 "__contract_write_set",
45 wrapper_symbol.location);
46}
47
50 symbol_table_baset &symbol_table,
51 dfcc_libraryt &library,
52 const symbolt &wrapper_symbol)
53{
55 symbol_table,
57 wrapper_symbol.name,
58 "__address_of_contract_write_set",
59 wrapper_symbol.location);
60}
61
62// Generate the write set to check for side effects in requires clauses
64 symbol_table_baset &symbol_table,
65 dfcc_libraryt &library,
66 const symbolt &wrapper_symbol)
67{
69 symbol_table,
71 wrapper_symbol.name,
72 "__requires_write_set",
73 wrapper_symbol.location);
74}
75
78 symbol_table_baset &symbol_table,
79 dfcc_libraryt &library,
80 const symbolt &wrapper_symbol)
81{
83 symbol_table,
85 wrapper_symbol.name,
86 "__address_of_requires_write_set",
87 wrapper_symbol.location);
88}
89
92 symbol_table_baset &symbol_table,
93 dfcc_libraryt &library,
94 const symbolt &wrapper_symbol)
95{
97 symbol_table,
99 wrapper_symbol.name,
100 "__ensures_write_set",
101 wrapper_symbol.location);
102}
103
106 symbol_table_baset &symbol_table,
107 dfcc_libraryt &library,
108 const symbolt &wrapper_symbol)
109{
111 symbol_table,
113 wrapper_symbol.name,
114 "__address_of_ensures_write_set",
115 wrapper_symbol.location);
116}
117
120 symbol_table_baset &symbol_table,
121 dfcc_libraryt &library,
122 const symbolt &wrapper_symbol)
123{
125 symbol_table,
127 wrapper_symbol.name,
128 "__ptr_pred_ctx",
129 wrapper_symbol.location);
130}
131
134 symbol_table_baset &symbol_table,
135 dfcc_libraryt &library,
136 const symbolt &wrapper_symbol)
137{
139 symbol_table,
141 wrapper_symbol.name,
142 "__address_of_ptr_pred_ctx",
143 wrapper_symbol.location);
144}
145
147 const dfcc_contract_modet contract_mode,
148 const symbolt &wrapper_symbol,
149 const symbolt &wrapped_symbol,
150 const dfcc_contract_functionst &contract_functions,
152 goto_modelt &goto_model,
153 message_handlert &message_handler,
154 dfcc_libraryt &library,
155 dfcc_instrumentt &instrument,
156 dfcc_lift_memory_predicatest &memory_predicates)
157 : contract_mode(contract_mode),
158 wrapper_symbol(wrapper_symbol),
159 wrapped_symbol(wrapped_symbol),
160 contract_functions(contract_functions),
161 contract_symbol(contract_functions.pure_contract_symbol),
162 contract_code_type(to_code_with_contract_type(contract_symbol.type)),
163 caller_write_set(caller_write_set_symbol.symbol_expr()),
164 wrapper_sl(wrapper_symbol.location),
165 return_value_opt(),
166 contract_write_set(create_contract_write_set(
167 goto_model.symbol_table,
168 library,
169 wrapper_symbol)),
170 addr_of_contract_write_set(create_addr_of_contract_write_set(
171 goto_model.symbol_table,
172 library,
173 wrapper_symbol)),
174 requires_write_set(create_requires_write_set(
175 goto_model.symbol_table,
176 library,
177 wrapper_symbol)),
178 addr_of_requires_write_set(create_addr_of_requires_write_set(
179 goto_model.symbol_table,
180 library,
181 wrapper_symbol)),
182 ensures_write_set(create_ensures_write_set(
183 goto_model.symbol_table,
184 library,
185 wrapper_symbol)),
186 addr_of_ensures_write_set(create_addr_of_ensures_write_set(
187 goto_model.symbol_table,
188 library,
189 wrapper_symbol)),
190 ptr_pred_ctx(
191 create_ptr_pred_ctx(goto_model.symbol_table, library, wrapper_symbol)),
192 addr_of_ptr_pred_ctx(create_addr_of_ptr_pred_ctx(
193 goto_model.symbol_table,
194 library,
195 wrapper_symbol)),
196 function_pointer_contracts(),
197 goto_model(goto_model),
198 message_handler(message_handler),
199 log(message_handler),
200 library(library),
201 instrument(instrument),
202 memory_predicates(memory_predicates),
203 ns(goto_model.symbol_table),
204 converter(goto_model.symbol_table, log.get_message_handler())
205{
206 // generate a return value symbol (needed to instantiate all contract lambdas)
207 if(contract_code_type.return_type().id() != ID_empty)
208 {
211 contract_code_type.return_type(),
212 wrapper_symbol.name,
213 "__contract_return_value",
214 wrapper_symbol.location);
215
216 // build contract_lambda_parameters
218 }
219
220 // build contract_lambda_parameters
221 for(const auto &param_id :
222 to_code_type(wrapper_symbol.type).parameter_identifiers())
223 {
224 contract_lambda_parameters.push_back(ns.lookup(param_id).symbol_expr());
225 }
226
227 // encode all contract clauses
235}
236
238 goto_programt &dest,
239 std::set<irep_idt> &dest_fp_contracts)
240{
241 add_to_dest(dest);
242 dest_fp_contracts.insert(
244}
245
260
262{
263 // call write_set_create(
264 // requires_write_set,
265 // assigns_size = 0,
266 // frees_size = 0,
267 // replacement_mode = false,
268 // assume_requires_ctx = contract_mode == check,
269 // assert_requires_ctx = contract_mode != check,
270 // assume_ensures_ctx = false,
271 // assert_ensures_ctx = false,
272 // )
274
280 wrapper_sl));
281
289 false_exprt(),
290 false_exprt(),
291 true_exprt(),
292 true_exprt(),
293 wrapper_sl);
294
296
297 // check for absence of allocation/deallocation in requires clauses
298 // ```c
299 // DECL __check_no_alloc: bool;
300 // CALL __check_no_alloc = check_empty_alloc_dealloc(requilres_write_set);
301 // ASSERT __check_no_alloc;
302 // DEAD __check_no_alloc: bool;
303 // ```
306 bool_typet(),
307 wrapper_symbol.name,
308 "__no_alloc_dealloc_in_requires",
309 wrapper_sl);
310
312
316 wrapper_sl));
317
319 check_sl.set_function(wrapper_symbol.name);
320 check_sl.set_property_class("no_alloc_dealloc_in_requires");
321 check_sl.set_comment(
322 "Check that requires do not allocate or deallocate memory");
325
326 // generate write set release and DEAD instructions
329 wrapper_sl));
331}
332
334{
335 // call write_set_create(
336 // ensures_write_set,
337 // assigns_size = 0,
338 // frees_size = 0,
339 // assume_requires_ctx = false,
340 // assert_requires_ctx = false,
341 // assume_ensures_ctx = contract_mode != check,
342 // assert_ensures_ctx = contract_mode == check,
343 // )
345
350 wrapper_sl));
351
353
358 false_exprt(),
359 false_exprt(),
362 true_exprt(),
363 true_exprt(),
364 wrapper_sl);
365
367
368 // call link_allocated(pre_post, caller) if in REPLACE MODE
370 {
374 wrapper_sl));
375 }
376
377 // check for absence of allocation/deallocation in contract clauses
378 // ```c
379 // DECL __check_no_alloc: bool;
380 // CALL __check_no_alloc = check_empty_alloc_dealloc(ensures_write_set);
381 // ASSERT __check_no_alloc;
382 // DEAD __check_no_alloc: bool;
383 // ```
386 bool_typet(),
387 wrapper_symbol.name,
388 "__no_alloc_dealloc_in_ensures_clauses",
389 wrapper_sl);
390
392
396 wrapper_sl));
397
399 check_sl.set_function(wrapper_symbol.name);
400 check_sl.set_property_class("no_alloc_dealloc_in_ensures");
401 check_sl.set_comment(
402 "Check that ensures do not allocate or deallocate memory");
403
406
407 // generate write set release
410 wrapper_sl));
411
412 // declare write set DEAD
414}
415
417{
419
425 wrapper_sl));
426
427 // We use the empty write set used to check ensures for side effects
428 // to check for side effects in the assigns and frees functions as well
429 // TODO: I don't know what the above comment means, why was there an empty
430 // write set here?
431
432 // call write_set_create
433 {
436 from_integer(contract_functions.get_nof_assigns_targets(), size_type()),
437 from_integer(contract_functions.get_nof_frees_targets(), size_type()),
438 false_exprt(),
439 false_exprt(),
440 false_exprt(),
441 false_exprt(),
442 true_exprt(),
443 true_exprt(),
444 wrapper_sl);
446 }
447
448 // build arguments for assigns and frees clauses functions
451 for(const auto &parameter : wrapper_code_type.parameter_identifiers())
452 {
454 wrapper_arguments.push_back(parameter_symbol.symbol_expr());
455 }
456
457 // call spec_assigns to build the contract write set
458 {
460 contract_functions.get_spec_assigns_function_symbol().symbol_expr());
461
462 auto &arguments = call.arguments();
463
464 // forward wrapper arguments
465 for(const auto &arg : wrapper_arguments)
466 arguments.push_back(arg);
467
468 // pass write set to populate
469 arguments.emplace_back(addr_of_contract_write_set);
470
471 // pass the empty write set to check side effects against
472 arguments.emplace_back(addr_of_requires_write_set);
473
475 }
476
477 // call spec_frees to build the contract write set
478 {
480 contract_functions.get_spec_frees_function_symbol().symbol_expr());
481 auto &arguments = call.arguments();
482
483 // forward wrapper arguments
484 for(const auto &arg : wrapper_arguments)
485 arguments.push_back(arg);
486
487 // pass write set to populate
488 arguments.emplace_back(addr_of_contract_write_set);
489
490 // pass the empty write set to check side effects against
491 arguments.emplace_back(addr_of_requires_write_set);
492
494 }
495
496 // generate write set release and DEAD instructions
499 wrapper_sl));
502}
503
538
573{
574 if(expr.id() == ID_side_effect)
575 {
576 // Base case: pointer predicate function call
578 if(side_effect.get_statement() == ID_function_call)
579 {
580 exprt &function = side_effect.operands()[0];
581 if(function.id() == ID_symbol)
582 {
583 const irep_idt &func_name = to_symbol_expr(function).get_identifier();
585 {
586 function.add_source_location().set("no_fail", no_fail);
587 }
588 }
589 }
590 return;
591 }
592 else if(expr.id() == ID_and)
593 {
594 // Shortcutting AND: propagate current no_fail value to all operands
595 for(auto &op : expr.operands())
596 {
598 }
599 }
600 else if(expr.id() == ID_or)
601 {
602 // Shortcutting OR: set no_fail=false for all but last operand
603 auto &ops = expr.operands();
604 // Process all operands except the last one with no_fail=false
605 for(std::size_t i = 0; i < ops.size() - 1; ++i)
606 {
607 disable_may_fail_rec(ops[i], false);
608 }
609 // Process last operand with current no_fail value
610 if(!ops.empty())
611 {
613 }
614 }
615 else if(expr.id() == ID_implies)
616 {
617 // Shortcutting implies: false for antecedent, current value for consequent
618 INVARIANT(
619 expr.operands().size() == 2,
620 "Implication expression must have two operands");
621 disable_may_fail_rec(expr.operands()[0], false);
623 }
624 else
625 {
626 // bail on other types of expressions
627 return;
628 }
629}
630
632{
633 disable_may_fail_rec(expr, true);
634}
635
637{
638 // we use this empty requires write set to check for the absence of side
639 // effects in the requires clauses
640 const auto &wrapper_id = wrapper_symbol.name;
641 const auto &language_mode =
643
644 // if in replacement mode, check that assertions hold in the current context,
645 // otherwise assume
646 const auto &statement_type =
648
649 // goto program where all requires are added
651
652 // translate each requires clause
653 for(const auto &r : contract_code_type.c_requires())
654 {
657
658 // add "no_fail" suffix to predicates required as units
660 source_locationt sl(r.source_location());
662 {
663 sl.set_property_class(ID_precondition);
664 sl.set_comment(
665 "Check requires clause of contract " + id2string(contract_symbol.name) +
666 " for function " + id2string(wrapper_id));
667 }
668 // // rewrite pointer equalities before goto conversion
669 // TODO rewrite_equal_exprt_to_pointer_equals(requires_lmbd);
672 }
673
674 // fix calls to user-defined memory predicates
676
677 // instrument for side effects
678 // make the program well-formed
685 // turn it back into a sequence of statements
686 requires_program.instructions.back().turn_into_skip();
687
688 // append resulting program to preconditions section
690}
691
693{
694 const auto &language_mode = wrapper_symbol.mode;
695 const auto &wrapper_id = wrapper_symbol.name;
696 const auto &statement_type =
698
699 // goto program where all requires are added
701
702 // translate each ensures clause
703 for(const auto &e : contract_code_type.c_ensures())
704 {
706 .application(contract_lambda_parameters)
707 .with_source_location(e);
708
709 // add "no_fail" suffix to unit pointer predicates
711
712 // this also rewrites ID_old expressions to fresh variables
714 goto_model.symbol_table, ensures, language_mode, history);
715
716 source_locationt sl(e.source_location());
718 {
719 sl.set_property_class(ID_postcondition);
720 sl.set_comment(
721 "Check ensures clause of contract " + id2string(contract_symbol.name) +
722 " for function " + id2string(wrapper_id));
723 }
724 // // rewrite pointer equalities before goto conversion
725 // TODO rewrite_equal_exprt_to_pointer_equals(ensures);
728 }
729
730 // When checking an ensures clause we link the contract write set to the
731 // ensures write set to know what was deallocated by the function so that
732 // the was_freed predicate can perform its checks
736 wrapper_sl));
737
738 // fix calls to user-defined user-defined memory predicates
740
741 // instrument for side effects
742 // make the program well-formed
749 // turn it back into a sequence of statements
750 ensures_program.instructions.back().turn_into_skip();
751
752 // add the ensures program to the postconditions section
754}
755
763
765{
766 // build call to the wrapped function
768
770 {
771 symbol_exprt return_value = return_value_opt.value();
772 // DECL
774 call.lhs() = return_value;
775
776 // SET_RETURN_VALUE
779
780 // DEAD
782 }
783
784 // forward wrapper arguments
786
787 for(const auto &parameter : wrapper_code_type.parameter_identifiers())
788 {
789 PRECONDITION(!parameter.empty());
791 call.arguments().push_back(parameter_symbol.symbol_expr());
792 }
793
794 // pass write set to check against
795 call.arguments().push_back(addr_of_contract_write_set);
796
798}
799
801{
802 // generate local write set and add as parameter to the call
804 for(const auto &parameter :
805 to_code_type(wrapper_symbol.type).parameter_identifiers())
806 {
807 PRECONDITION(!parameter.empty());
809 write_set_arguments.push_back(parameter_symbol.symbol_expr());
810 }
811
812 // check assigns clause inclusion
813 // IF __caller_write_set==NULL GOTO skip_target;
814 // DECL check: bool;
815 // CALL check = __CPROVER_contracts_write_set_check_assigns_clause_inclusion(
816 // __caller_write_set, &__local_write_set);
817 // ASSERT check;
818 // CALL check = __CPROVER_contracts_write_set_check_frees_clause_inclusion(
819 // __caller_write_set, &__local_write_set);
820 // ASSERT check;
821 // DEAD check;
822 // skip_target: skip;
823
824 auto goto_instruction =
827
828 {
829 // assigns clause inclusion
832 bool_typet(),
833 wrapper_symbol.name,
834 "__check_assigns_clause_incl",
835 wrapper_sl);
836
838
842 wrapper_sl));
843
845 check_sl.set_function(wrapper_symbol.name);
846 check_sl.set_property_class("assigns");
847 check_sl.set_comment(
848 "Check that the assigns clause of " + id2string(contract_symbol.name) +
849 " is included in the caller's assigns clause");
852 }
853
854 {
855 // frees clause inclusion
858 bool_typet(),
859 wrapper_symbol.name,
860 "__check_frees_clause_incl",
861 wrapper_sl);
862
864
868 wrapper_sl));
869
871 check_sl.set_function(wrapper_symbol.name);
872 check_sl.set_property_class("frees");
873 check_sl.set_comment(
874 "Check that the frees clause of " + id2string(contract_symbol.name) +
875 " is included in the caller's frees clause");
878 }
879
880 auto label_instruction =
882 goto_instruction->complete_goto(label_instruction);
883
885 contract_functions.get_spec_assigns_havoc_function_symbol().symbol_expr(),
886 {addr_of_contract_write_set});
887
889
890 // assign nondet to the return value
891 if(return_value_opt.has_value())
892 {
893 symbol_exprt return_value = return_value_opt.value();
894
895 // DECL
897
898 // ASSIGN NONDET
900 return_value,
902 wrapper_sl));
903
904 // SET RETURN VALUE
907
908 // DEAD
910 }
911
912 // nondet free the freeable set, record effects in both the contract write
913 // set and the caller write set
917 wrapper_sl));
918}
constant_exprt from_integer(const mp_integer &int_value, const typet &type)
API to expression classes that are internal to the C frontend.
const code_with_contract_typet & to_code_with_contract_type(const typet &type)
Cast a typet to a code_with_contract_typet.
Definition c_types.h:467
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
The Boolean type.
Definition std_types.h:36
goto_instruction_codet representation of a function call statement.
Data structure for representing an arbitrary statement in a program.
Generates GOTO functions modelling a contract assigns and frees clauses.
This class instruments GOTO functions or instruction sequences for frame condition checking and loop ...
void instrument_goto_program(const irep_idt &function_id, goto_programt &goto_program, const exprt &write_set, std::set< irep_idt > &function_pointer_contracts)
Instruments a GOTO program against a given write set variable.
Class interface to library types and functions defined in cprover_contracts.c.
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 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 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_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.
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.
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.
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.
std::map< dfcc_typet, typet > dfcc_type
Maps enum values to the actual types (dynamically loaded)
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_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 fix_calls(goto_programt &program)
Fixes calls to user-defined memory predicates in the given program, by adding an address-of to argume...
const source_locationt wrapper_sl
Source location with wrapper function name as function name.
const symbol_exprt addr_of_ptr_pred_ctx
Symbol for the pointer to the is_fresh object set.
void encode_ensures_clauses()
Encodes postconditions, instruments them to check for side effects.
const symbol_exprt contract_write_set
Symbol for the write set object derived from the contract.
void encode_havoced_function_call()
Creates instructions that havoc the contract write set, create a nondet return value,...
const symbol_exprt caller_write_set
void encode_requires_write_set()
Encodes the empty write set used to check for side effects in requires.
void encode_requires_clauses()
Encodes preconditions, instruments them to check for side effects.
const symbol_exprt addr_of_requires_write_set
Symbol for the pointer to the write set used to check requires clauses.
void encode_contract_write_set()
Encodes the write set of the contract being checked/replaced (populated by calling functions provided...
const dfcc_contract_functionst & contract_functions
const code_with_contract_typet & contract_code_type
const symbol_exprt requires_write_set
Symbol for the write set used to check requires clauses for side effects.
exprt::operandst contract_lambda_parameters
Vector of arguments to use to instantiate the lambdas wrapping the contract clauses.
const symbol_exprt addr_of_ensures_write_set
Symbol for the pointer to the write set used to check ensures clauses.
const dfcc_contract_modet contract_mode
void encode_checked_function_call()
Creates a checked function call to the wrapped function, passing it the contract-derived write set as...
std::set< irep_idt > function_pointer_contracts
Set of required or ensured contracts for function pointers discovered when processing the contract of...
dfcc_lift_memory_predicatest & memory_predicates
void add_to_dest(goto_programt &dest, std::set< irep_idt > &dest_fp_contracts)
Adds the whole program to dest and the discovered function pointer contracts dest_fp_contracts.
void encode_function_call()
Encodes the function call section of the wrapper program.
dfcc_wrapper_programt(const dfcc_contract_modet contract_mode, const symbolt &wrapper_symbol, const symbolt &wrapped_symbol, const dfcc_contract_functionst &contract_functions, const symbolt &caller_write_set_symbol, goto_modelt &goto_model, message_handlert &message_handler, dfcc_libraryt &library, dfcc_instrumentt &instrument, dfcc_lift_memory_predicatest &memory_predicates)
const symbol_exprt addr_of_contract_write_set
Symbol for the pointer to the write set object derived from the contract.
void encode_ptr_pred_ctx()
Encodes the pointer predicates evaluation context object.
const symbol_exprt ensures_write_set
Symbol for the write set used to check ensures clauses for side effects.
const symbol_exprt ptr_pred_ctx
Symbol for the object set used to evaluate is_fresh predicates.
std::optional< symbol_exprt > return_value_opt
Symbol for the return value of the wrapped function.
dfcc_instrumentt & instrument
void encode_ensures_write_set()
Encodes the empty write set used to check for side effects in ensures.
goto_programt link_deallocated_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
std::vector< exprt > operandst
Definition expr.h:58
typet & type()
Return the type of the expression.
Definition expr.h:84
operandst & operands()
Definition expr.h:94
source_locationt & add_source_location()
Definition expr.h:236
The Boolean constant false.
Definition std_expr.h:3199
void goto_convert(const codet &code, goto_programt &dest, const irep_idt &mode)
symbol_tablet symbol_table
Symbol table.
Definition goto_model.h:31
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_set_return_value(exprt return_value, const source_locationt &l=source_locationt::nil())
static instructiont make_dead(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_end_function(const source_locationt &l=source_locationt::nil())
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
void set(const irep_idt &name, const irep_idt &value)
Definition irep.h:412
const irep_idt & id() const
Definition irep.h:388
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
A side_effect_exprt that returns a non-deterministically chosen value.
Definition std_code.h:1520
An expression containing a side effect.
Definition std_code.h:1450
Expression to hold a symbol (variable)
Definition std_expr.h:131
The symbol table base class interface.
Symbol table entry.
Definition symbol.h:28
source_locationt location
Source code location of definition of symbol.
Definition symbol.h:37
irep_idt name
The unique identifier.
Definition symbol.h:40
The Boolean constant true.
Definition std_expr.h:3190
Translates assigns and frees clauses of a function contract into goto functions that allow to build a...
dfcc_contract_modet
Enum type representing the contract checking and replacement modes.
Add instrumentation to a goto program to perform frame condition checks.
bool dfcc_is_cprover_pointer_predicate(const irep_idt &id)
Returns true iff the symbol is one of the CPROVER pointer predicates.
Dynamic frame condition checking library loading.
@ 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
@ PTR_PRED_CTX
type of context info for pointer predicates evaluation
@ WRITE_SET_PTR
type of pointers to descriptors of assignable/freeable sets of locations
Collects all user-defined predicates that call functions is_fresh, pointer_in_range,...
Instruments occurrences of pointer_equals predicates in programs encoding requires and ensures clause...
Dynamic frame condition checking utility functions.
static symbol_exprt create_requires_write_set(symbol_table_baset &symbol_table, dfcc_libraryt &library, const symbolt &wrapper_symbol)
void disable_may_fail_rec(exprt &expr, bool no_fail)
Recursively traverses expression, adding "no_fail" attributes to pointer predicates that we know cann...
static symbol_exprt create_addr_of_contract_write_set(symbol_table_baset &symbol_table, dfcc_libraryt &library, const symbolt &wrapper_symbol)
Generate the contract write set pointer.
static symbol_exprt create_addr_of_ensures_write_set(symbol_table_baset &symbol_table, dfcc_libraryt &library, const symbolt &wrapper_symbol)
Generate the write set pointer to check side effects in ensures clauses.
static symbol_exprt create_addr_of_ptr_pred_ctx(symbol_table_baset &symbol_table, dfcc_libraryt &library, const symbolt &wrapper_symbol)
Generate object set pointer used to support is_fresh predicates.
static symbol_exprt create_ptr_pred_ctx(symbol_table_baset &symbol_table, dfcc_libraryt &library, const symbolt &wrapper_symbol)
Generate object set used to support is_fresh predicates.
void disable_may_fail(exprt &expr)
static symbol_exprt create_addr_of_requires_write_set(symbol_table_baset &symbol_table, dfcc_libraryt &library, const symbolt &wrapper_symbol)
Generate the write set pointer to check side effects in requires clauses.
static symbol_exprt create_ensures_write_set(symbol_table_baset &symbol_table, dfcc_libraryt &library, const symbolt &wrapper_symbol)
Generate the write set to check side effects in ensures clauses.
static symbol_exprt create_contract_write_set(symbol_table_baset &symbol_table, dfcc_libraryt &library, const symbolt &wrapper_symbol)
Generate the contract write set.
Generates the body of a wrapper function from a contract for contract checking or contract replacemen...
constant_exprt make_boolean_expr(bool value)
returns true_exprt if given true and false_exprt otherwise
Deprecated expression utility functions.
Symbol Table + CFG.
const std::string & id2string(const irep_idt &d)
Definition irep.h:44
static int8_t r
Definition irep_hash.h:60
double log(double x)
Definition math.c:2449
API to expression classes for 'mathematical' expressions.
const lambda_exprt & to_lambda_expr(const exprt &expr)
Cast an exprt to a lambda_exprt.
Pointer Logic.
#define PRECONDITION(CONDITION)
Definition invariant.h:463
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
Definition invariant.h:423
side_effect_exprt & to_side_effect_expr(exprt &expr)
Definition std_code.h:1506
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
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
Definition std_types.h:788
static symbolt & get_function_symbol(symbol_table_baset &, const irep_idt &function_id)
Returns the symbolt for function_id.
static const exprt make_null_check_expr(const exprt &ptr)
Returns the expression expr == NULL.
static symbol_exprt create_symbol(symbol_table_baset &, const typet &type, const irep_idt &function_id, const std::string &base_name, const source_locationt &source_location)
Adds a new symbol named function_id::base_name of type type with given attributes in the symbol table...
#define size_type
Definition unistd.c:186
void generate_history_variables_initialization(symbol_table_baset &symbol_table, exprt &clause, const irep_idt &mode, goto_programt &program)
This function generates all the instructions required to initialize history variables.
Definition utils.cpp:494