CBMC
Loading...
Searching...
No Matches
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{
207
208 // generate a return value symbol (needed to instantiate all contract lambdas)
209 if(contract_code_type.return_type().id() != ID_empty)
210 {
213 contract_code_type.return_type(),
214 wrapper_symbol.name,
215 "__contract_return_value",
216 wrapper_symbol.location);
217
218 // build contract_lambda_parameters
220 }
221
222 // build contract_lambda_parameters
223 for(const auto &param_id :
224 to_code_type(wrapper_symbol.type).parameter_identifiers())
225 {
226 contract_lambda_parameters.push_back(ns.lookup(param_id).symbol_expr());
227 }
228
229 // encode all contract clauses
237}
238
240 goto_programt &dest,
241 std::set<irep_idt> &dest_fp_contracts)
242{
243 add_to_dest(dest);
244 dest_fp_contracts.insert(
246}
247
262
264{
265 // call write_set_create(
266 // requires_write_set,
267 // assigns_size = 0,
268 // frees_size = 0,
269 // replacement_mode = false,
270 // assume_requires_ctx = contract_mode == check,
271 // assert_requires_ctx = contract_mode != check,
272 // assume_ensures_ctx = false,
273 // assert_ensures_ctx = false,
274 // )
276
282 wrapper_sl));
283
291 false_exprt(),
292 false_exprt(),
293 true_exprt(),
294 true_exprt(),
295 wrapper_sl);
296
298
299 // check for absence of allocation/deallocation in requires clauses
300 // ```c
301 // DECL __check_no_alloc: bool;
302 // CALL __check_no_alloc = check_empty_alloc_dealloc(requilres_write_set);
303 // ASSERT __check_no_alloc;
304 // DEAD __check_no_alloc: bool;
305 // ```
308 bool_typet(),
309 wrapper_symbol.name,
310 "__no_alloc_dealloc_in_requires",
311 wrapper_sl);
312
314
318 wrapper_sl));
319
321 check_sl.set_function(wrapper_symbol.name);
322 check_sl.set_property_class("no_alloc_dealloc_in_requires");
323 check_sl.set_comment(
324 "Check that requires do not allocate or deallocate memory");
327
328 // generate write set release and DEAD instructions
331 wrapper_sl));
333}
334
336{
337 // call write_set_create(
338 // ensures_write_set,
339 // assigns_size = 0,
340 // frees_size = 0,
341 // assume_requires_ctx = false,
342 // assert_requires_ctx = false,
343 // assume_ensures_ctx = contract_mode != check,
344 // assert_ensures_ctx = contract_mode == check,
345 // )
347
352 wrapper_sl));
353
355
360 false_exprt(),
361 false_exprt(),
364 true_exprt(),
365 true_exprt(),
366 wrapper_sl);
367
369
370 // call link_allocated(pre_post, caller) if in REPLACE MODE
372 {
376 wrapper_sl));
377 }
378
379 // check for absence of allocation/deallocation in contract clauses
380 // ```c
381 // DECL __check_no_alloc: bool;
382 // CALL __check_no_alloc = check_empty_alloc_dealloc(ensures_write_set);
383 // ASSERT __check_no_alloc;
384 // DEAD __check_no_alloc: bool;
385 // ```
388 bool_typet(),
389 wrapper_symbol.name,
390 "__no_alloc_dealloc_in_ensures_clauses",
391 wrapper_sl);
392
394
398 wrapper_sl));
399
401 check_sl.set_function(wrapper_symbol.name);
402 check_sl.set_property_class("no_alloc_dealloc_in_ensures");
403 check_sl.set_comment(
404 "Check that ensures do not allocate or deallocate memory");
405
408
409 // generate write set release
412 wrapper_sl));
413
414 // declare write set DEAD
416}
417
419{
421
427 wrapper_sl));
428
429 // We use the empty write set used to check ensures for side effects
430 // to check for side effects in the assigns and frees functions as well
431 // TODO: I don't know what the above comment means, why was there an empty
432 // write set here?
433
434 // call write_set_create
435 {
438 from_integer(contract_functions.get_nof_assigns_targets(), size_type()),
439 from_integer(contract_functions.get_nof_frees_targets(), size_type()),
440 false_exprt(),
441 false_exprt(),
442 false_exprt(),
443 false_exprt(),
444 true_exprt(),
445 true_exprt(),
446 wrapper_sl);
448 }
449
450 // build arguments for assigns and frees clauses functions
453 for(const auto &parameter : wrapper_code_type.parameter_identifiers())
454 {
456 wrapper_arguments.push_back(parameter_symbol.symbol_expr());
457 }
458
459 // call spec_assigns to build the contract write set
460 {
462 contract_functions.get_spec_assigns_function_symbol().symbol_expr());
463
464 auto &arguments = call.arguments();
465
466 // forward wrapper arguments
467 for(const auto &arg : wrapper_arguments)
468 arguments.push_back(arg);
469
470 // pass write set to populate
471 arguments.emplace_back(addr_of_contract_write_set);
472
473 // pass the empty write set to check side effects against
474 arguments.emplace_back(addr_of_requires_write_set);
475
477 }
478
479 // call spec_frees to build the contract write set
480 {
482 contract_functions.get_spec_frees_function_symbol().symbol_expr());
483 auto &arguments = call.arguments();
484
485 // forward wrapper arguments
486 for(const auto &arg : wrapper_arguments)
487 arguments.push_back(arg);
488
489 // pass write set to populate
490 arguments.emplace_back(addr_of_contract_write_set);
491
492 // pass the empty write set to check side effects against
493 arguments.emplace_back(addr_of_requires_write_set);
494
496 }
497
498 // generate write set release and DEAD instructions
501 wrapper_sl));
504}
505
540
575{
576 if(expr.id() == ID_side_effect)
577 {
578 // Base case: pointer predicate function call
580 if(side_effect.get_statement() == ID_function_call)
581 {
582 exprt &function = side_effect.operands()[0];
583 if(function.id() == ID_symbol)
584 {
585 const irep_idt &func_name = to_symbol_expr(function).get_identifier();
587 {
588 function.add_source_location().set("no_fail", no_fail);
589 }
590 }
591 }
592 return;
593 }
594 else if(expr.id() == ID_and)
595 {
596 // Shortcutting AND: propagate current no_fail value to all operands
597 for(auto &op : expr.operands())
598 {
600 }
601 }
602 else if(expr.id() == ID_or)
603 {
604 // Shortcutting OR: set no_fail=false for all but last operand
605 auto &ops = expr.operands();
606 // Process all operands except the last one with no_fail=false
607 for(std::size_t i = 0; i < ops.size() - 1; ++i)
608 {
609 disable_may_fail_rec(ops[i], false);
610 }
611 // Process last operand with current no_fail value
612 if(!ops.empty())
613 {
615 }
616 }
617 else if(expr.id() == ID_implies)
618 {
619 // Shortcutting implies: false for antecedent, current value for consequent
620 INVARIANT(
621 expr.operands().size() == 2,
622 "Implication expression must have two operands");
623 disable_may_fail_rec(expr.operands()[0], false);
625 }
626 else
627 {
628 // bail on other types of expressions
629 return;
630 }
631}
632
634{
635 disable_may_fail_rec(expr, true);
636}
637
639{
640 // we use this empty requires write set to check for the absence of side
641 // effects in the requires clauses
642 const auto &wrapper_id = wrapper_symbol.name;
643 const auto &language_mode =
645
646 // if in replacement mode, check that assertions hold in the current context,
647 // otherwise assume
648 const auto &statement_type =
650
651 // goto program where all requires are added
653
654 // translate each requires clause
655 for(const auto &r : contract_code_type.c_requires())
656 {
659
660 // add "no_fail" suffix to predicates required as units
662 source_locationt sl(r.source_location());
664 {
665 sl.set_property_class(ID_precondition);
666 sl.set_comment(
667 "Check requires clause of contract " + id2string(contract_symbol.name) +
668 " for function " + id2string(wrapper_id));
669 }
670 // // rewrite pointer equalities before goto conversion
671 // TODO rewrite_equal_exprt_to_pointer_equals(requires_lmbd);
674 }
675
676 // fix calls to user-defined memory predicates
678
679 // instrument for side effects
680 // make the program well-formed
687 // turn it back into a sequence of statements
688 requires_program.instructions.back().turn_into_skip();
689
690 // append resulting program to preconditions section
692}
693
695{
696 const auto &language_mode = wrapper_symbol.mode;
697 const auto &wrapper_id = wrapper_symbol.name;
698 const auto &statement_type =
700
701 // goto program where all requires are added
703
704 // translate each ensures clause
705 for(const auto &e : contract_code_type.c_ensures())
706 {
708 .application(contract_lambda_parameters)
709 .with_source_location(e);
710
711 // add "no_fail" suffix to unit pointer predicates
713
714 // this also rewrites ID_old expressions to fresh variables
716 goto_model.symbol_table, ensures, language_mode, history);
717
718 source_locationt sl(e.source_location());
720 {
721 sl.set_property_class(ID_postcondition);
722 sl.set_comment(
723 "Check ensures clause of contract " + id2string(contract_symbol.name) +
724 " for function " + id2string(wrapper_id));
725 }
726 // // rewrite pointer equalities before goto conversion
727 // TODO rewrite_equal_exprt_to_pointer_equals(ensures);
730 }
731
732 // When checking an ensures clause we link the contract write set to the
733 // ensures write set to know what was deallocated by the function so that
734 // the was_freed predicate can perform its checks
738 wrapper_sl));
739
740 // fix calls to user-defined user-defined memory predicates
742
743 // instrument for side effects
744 // make the program well-formed
751 // turn it back into a sequence of statements
752 ensures_program.instructions.back().turn_into_skip();
753
754 // add the ensures program to the postconditions section
756}
757
765
767{
768 // build call to the wrapped function
770
772 {
773 symbol_exprt return_value = return_value_opt.value();
774 // DECL
776 call.lhs() = return_value;
777
778 // SET_RETURN_VALUE
781
782 // DEAD
784 }
785
786 // forward wrapper arguments
788
789 for(const auto &parameter : wrapper_code_type.parameter_identifiers())
790 {
791 PRECONDITION(!parameter.empty());
793 call.arguments().push_back(parameter_symbol.symbol_expr());
794 }
795
796 // pass write set to check against
797 call.arguments().push_back(addr_of_contract_write_set);
798
800}
801
803{
804 // generate local write set and add as parameter to the call
806 for(const auto &parameter :
807 to_code_type(wrapper_symbol.type).parameter_identifiers())
808 {
809 PRECONDITION(!parameter.empty());
811 write_set_arguments.push_back(parameter_symbol.symbol_expr());
812 }
813
814 // check assigns clause inclusion
815 // IF __caller_write_set==NULL GOTO skip_target;
816 // DECL check: bool;
817 // CALL check = __CPROVER_contracts_write_set_check_assigns_clause_inclusion(
818 // __caller_write_set, &__local_write_set);
819 // ASSERT check;
820 // CALL check = __CPROVER_contracts_write_set_check_frees_clause_inclusion(
821 // __caller_write_set, &__local_write_set);
822 // ASSERT check;
823 // DEAD check;
824 // skip_target: skip;
825
826 auto goto_instruction =
829
830 {
831 // assigns clause inclusion
834 bool_typet(),
835 wrapper_symbol.name,
836 "__check_assigns_clause_incl",
837 wrapper_sl);
838
840
844 wrapper_sl));
845
847 check_sl.set_function(wrapper_symbol.name);
848 check_sl.set_property_class("assigns");
849 check_sl.set_comment(
850 "Check that the assigns clause of " + id2string(contract_symbol.name) +
851 " is included in the caller's assigns clause");
854 }
855
856 {
857 // frees clause inclusion
860 bool_typet(),
861 wrapper_symbol.name,
862 "__check_frees_clause_incl",
863 wrapper_sl);
864
866
870 wrapper_sl));
871
873 check_sl.set_function(wrapper_symbol.name);
874 check_sl.set_property_class("frees");
875 check_sl.set_comment(
876 "Check that the frees clause of " + id2string(contract_symbol.name) +
877 " is included in the caller's frees clause");
880 }
881
882 auto label_instruction =
884 goto_instruction->complete_goto(label_instruction);
885
887 contract_functions.get_spec_assigns_havoc_function_symbol().symbol_expr(),
888 {addr_of_contract_write_set});
889
891
892 // assign nondet to the return value
893 if(return_value_opt.has_value())
894 {
895 symbol_exprt return_value = return_value_opt.value();
896
897 // DECL
899
900 // ASSIGN NONDET
902 return_value,
904 wrapper_sl));
905
906 // SET RETURN VALUE
909
910 // DEAD
912 }
913
914 // nondet free the freeable set, record effects in both the contract write
915 // set and the caller write set
919 wrapper_sl));
920}
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:566
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:57
std::vector< exprt > operandst
Definition expr.h:59
typet & type()
Return the type of the expression.
Definition expr.h:85
operandst & operands()
Definition expr.h:95
source_locationt & add_source_location()
Definition expr.h:241
The Boolean constant false.
Definition std_expr.h:3125
void set_prefix(const std::string &prefix)
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:132
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:3116
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:2416
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:211
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