Go to the documentation of this file.
14 #ifndef CPROVER_GOTO_INSTRUMENT_CONTRACTS_INSTRUMENT_SPEC_ASSIGNS_H
15 #define CPROVER_GOTO_INSTRUMENT_CONTRACTS_INSTRUMENT_SPEC_ASSIGNS_H
26 #include <unordered_map>
27 #include <unordered_set>
45 "condition must have no side_effect sub-expression");
80 const exprt &_condition,
82 const exprt &_target_start_address,
83 const exprt &_target_size,
93 _target_start_address,
210 log(_message_handler),
270 min_line = std::numeric_limits<std::size_t>::max();
271 min_col = std::numeric_limits<std::size_t>::max();
272 max_line = std::numeric_limits<std::size_t>::min();
273 max_col = std::numeric_limits<std::size_t>::min();
280 min_line = std::numeric_limits<std::size_t>::min();
281 min_col = std::numeric_limits<std::size_t>::min();
282 max_line = std::numeric_limits<std::size_t>::max();
283 max_col = std::numeric_limits<std::size_t>::max();
293 source_location, std::numeric_limits<std::size_t>::min()),
295 source_location, std::numeric_limits<std::size_t>::min()));
300 source_location, std::numeric_limits<std::size_t>::max()),
302 source_location, std::numeric_limits<std::size_t>::max()));
316 source_location, std::numeric_limits<std::size_t>::max()),
318 source_location, std::numeric_limits<std::size_t>::max())) &&
322 source_location, std::numeric_limits<std::size_t>::min()),
324 source_location, std::numeric_limits<std::size_t>::min()),
338 std::size_t default_value)
344 return default_value;
358 std::size_t default_value)
362 return default_value;
374 static bool is_lte(
size_t line0,
size_t col0,
size_t line1,
size_t col1)
376 return (line0 < line1) || ((line0 == line1) && (col0 <= col1));
429 std::unordered_set<symbol_exprt, irep_hash> &dest);
464 template <
typename C>
472 [](
const symbol_exprt_to_car_mapt::value_type &s) { return s.first; });
510 const std::string &suffix,
527 bool allow_null_target,
543 bool include_stack_allocated)
const;
554 bool include_stack_allocated,
608 unordered_map<const conditional_target_exprt, const car_exprt, irep_hash>;
618 std::unordered_map<const symbol_exprt, const car_exprt, irep_hash>;
626 std::unordered_map<const exprt, const car_exprt, irep_hash>;
645 #endif // CPROVER_GOTO_INSTRUMENT_CONTRACTS_INSTRUMENT_SPEC_ASSIGNS_H
Class that provides messages with a built-in verbosity 'level'.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
cond_target_exprt_to_car_mapt from_spec_assigns
Map from conditional target expressions of assigns clauses to corresponding conditional address range...
bool has_subexpr(const exprt &expr, const std::function< bool(const exprt &)> &pred)
returns true if the expression has a subexpression that satisfies pred
const car_exprt & create_car_from_spec_assigns(const exprt &condition, const exprt &target)
Class that represents a single conditional target.
void traverse_instructions(const irep_idt ambient_function_id, goto_programt::const_targett it, const goto_programt::const_targett end, covered_locationst &covered_locations, propagated_static_localst &propagated) const
Traverses the given list of instructions, updating the given coverage map, recursing into function ca...
Stores information about a goto function computed from its CFG.
The type of an expression, extends irept.
static abstract_object_pointert transform(const exprt &expr, const std::vector< abstract_object_pointert > &operands, const abstract_environmentt &environment, const namespacet &ns)
void check_inclusion_heap_allocated_and_invalidate_aliases(const exprt &expr, goto_programt &dest)
Generates inclusion check instructions for an argument passed to free.
void create_snapshot(const car_exprt &car, goto_programt &dest) const
Returns snapshot instructions for a car_exprt.
const exprt & condition() const
Condition expression. When this condition holds the target is allowed.
const car_havoc_methodt havoc_method
Method to use to havod the target.
symbol_exprt_to_car_mapt from_stack_alloc
Map from DECL symbols to corresponding conditional address ranges.
Represents an interval of source locations covered by the static local variable search.
void check_inclusion_assignment(const exprt &lhs, goto_programt &dest) const
Generates inclusion check instructions for an assignment, havoc or havoc_object instruction.
bool has_propagate_static_local_pragma(source_locationt &source_location)
True iff the pragma to mark assignments to static local variables that need to be propagated upwards ...
void invalidate_car(const car_exprt &tracked_car, const car_exprt &freed_car, goto_programt &result) const
Adds an assignment in dest to invalidate the tracked car if was valid before and was pointing to the ...
const irep_idt & get_column() const
void invalidate_heap_and_spec_aliases(const car_exprt &freed_car, goto_programt &dest) const
Generates instructions to invalidate all targets aliased with a car that was passed to free,...
void update_max(size_t line, size_t col)
Updates the max_line and max_col in place using the given values iff they are larger.
conditional_target_exprt(const exprt &_condition, const exprt &_target)
Base class for all expressions.
symbol_exprt_to_car_mapt from_static_local
Map to from detected or propagated static local symbols to corresponding conditional address ranges.
void inclusion_check_assertion(const car_exprt &lhs, bool allow_null_lhs, bool include_stack_allocated, goto_programt &dest) const
Returns an inclusion check assertion of lhs over all tracked cars.
void update_min(size_t line, size_t col)
Updates the min_line and min_col in place using the given values iff they are smaller.
location_intervalt()
Initializes to the empty interval.
void get_static_locals(std::insert_iterator< C > inserter) const
Inserts the detected static local symbols into a target container.
exprt target_validity_expr(const car_exprt &car, bool allow_null_target) const
Returns the target validity expression for a car_exprt.
const exprt & target_size() const
Size of the target in bytes.
const symbol_exprt & lower_bound_var() const
Identifier of the lower address bound snapshot variable.
Expression to hold a symbol (variable)
A class that generates instrumentation for assigns clause checking.
const irep_idt & get_line() const
void target_validity_assertion(const car_exprt &car, bool allow_null_target, goto_programt &dest) const
Generates the target validity assertion for the given car and adds it to dest.
const irep_idt & function_id
Name of the instrumented function.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
const symbol_exprt & upper_bound_var() const
Identifier of the upper address bound snapshot variable.
const symbol_exprt & valid_var() const
Identifier of the validity snapshot variable.
std::unordered_map< const conditional_target_exprt, const car_exprt, irep_hash > cond_target_exprt_to_car_mapt
const namespacet ns
Program namespace.
car_exprt(const exprt &_condition, const exprt &_target, const exprt &_target_start_address, const exprt &_target_size, const symbol_exprt &_validity_var, const symbol_exprt &_lower_bound_var, const symbol_exprt &_upper_bound_var, const car_havoc_methodt _havoc_method)
car_exprt create_car_expr(const exprt &condition, const exprt &target) const
Creates a conditional address range expression from a cleaned-up condition and target expression.
const std::string & id2string(const irep_idt &d)
bool must_track_dead(const goto_programt::const_targett &target) const
Returns true iff a DEAD x must be processed to update the write set.
exprt inclusion_check_single(const car_exprt &lhs, const car_exprt &candidate_car) const
Returns inclusion check expression for a single candidate location.
symbol_tablet & st
Program symbol table.
const car_exprt & create_car_from_static_local(const symbol_exprt &target)
#define PRECONDITION(CONDITION)
void add_propagate_static_local_pragma(source_locationt &source_location)
Sets a pragma to mark assignments to static local variables that need to be propagated upwards in the...
void add_pragma_disable_assigns_check(source_locationt &source_location)
Adds a pragma on a source_locationt to disable inclusion checking.
exprt inclusion_check_full(const car_exprt &lhs, bool allow_null_lhs, bool include_stack_allocated) const
Returns an inclusion check expression of lhs over all tracked cars.
const irep_idt & mode
Language mode.
car_expr_listt from_heap_alloc
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
bool must_track_decl(const goto_programt::const_targett &target) const
Returns true iff a DECL x must be explicitly added to the write set.
const goto_functionst & functions
Other functions of the model.
bool must_check_assign(const goto_programt::const_targett &target)
Returns true iff an ASSIGN lhs := rhs instruction must be instrumented.
void anywhere()
Grows the interval cover the maximum range [(size_t::min, size_t::min), (size_t::min,...
void instrument_assign_statement(goto_programt::targett &instruction_it, goto_programt &body) const
Inserts an assertion in body immediately before the assignment at instruction_it, to ensure that the ...
A class for an expression that represents a conditional target or a list of targets sharing a common ...
car_havoc_methodt
method to use to havoc a target
std::size_t col_to_size_t(const source_locationt &source_location, std::size_t default_value)
If line or col is missing use default.
void track_static_locals_between(goto_programt::const_targett it, const goto_programt::const_targett end, goto_programt &dest)
Searches the goto instructions reachable between the given it and end target instructions to identify...
A collection of goto functions.
void track_static_locals(goto_programt &dest)
Searches the goto instructions reachable from the start to the end of the instrumented function's ins...
void invalidate_stack_allocated(const symbol_exprt &symbol_expr, goto_programt &dest)
Generate instructions to invalidate a stack-allocated object that goes DEAD in dest.
void track_plain_spec_target(const exprt &expr, goto_programt &dest)
Track and generate snaphsot instructions and target validity checking assertions for a conditional ta...
void instrument_call_statement(goto_programt::targett &instruction_it, goto_programt &body)
Inserts an assertion in body immediately before the function call at instruction_it,...
const exprt & target() const
The target expression.
const symbolt create_fresh_symbol(const std::string &suffix, const typet &type, const source_locationt &location) const
Creates a fresh symbolt with given suffix, scoped to function_id.
std::list< car_exprt > car_expr_listt
List of malloc'd conditional address ranges.
bool must_track_decl_or_dead(const irep_idt &ident) const
Returns true iff a function-local symbol must be tracked.
std::unordered_map< irep_idt, location_intervalt > covered_locationst
Map type from function identifiers to covered locations.
void instrument_instructions(goto_programt &body, goto_programt::targett instruction_it, const goto_programt::targett &instruction_end, const std::function< bool(const goto_programt::targett &)> &pred={})
Instruments a sequence of instructions with inclusion checks.
bool contains(const source_locationt &source_location)
True iff the interval contains the given location.
void collect_static_symbols(covered_locationst &covered_locations, std::unordered_set< symbol_exprt, irep_hash > &dest)
Collects static symbols from the symbol table that have a source location included in one of the cove...
std::size_t line_to_size_t(const source_locationt &source_location, std::size_t default_value)
If line is missing use default.
void add_pragma_disable_pointer_checks(source_locationt &source_location)
Adds a pragma on a source location disable all pointer checks.
const car_exprt & create_car_from_heap_alloc(const exprt &target)
const exprt & target_start_address() const
Start address of the target.
A generic container class for the GOTO intermediate representation of one function.
void track_heap_allocated(const exprt &expr, goto_programt &dest)
Track a whole heap-alloc object and generate snaphsot instructions in dest.
instructionst::const_iterator const_targett
void track_spec_target(const exprt &expr, goto_programt &dest)
Track an assigns clause target and generate snaphsot instructions and well-definedness assertions in ...
void update(const source_locationt &source_location)
Grows the interval to include the given (line, col) location.
cfg_infot & cfg_info
CFG information for simplification.
Class that represents a normalized conditional address range, with:
source_locationt & add_source_location()
instrument_spec_assignst(const irep_idt &_function_id, const goto_functionst &_functions, cfg_infot &_cfg_info, symbol_tablet &_st, message_handlert &_message_handler)
Class constructor.
std::unordered_map< const exprt, const car_exprt, irep_hash > exprt_to_car_mapt
void track_spec_target_group(const conditional_target_group_exprt &group, goto_programt &dest)
Track and generate snaphsot instructions and target validity checking assertions for a conditional ta...
std::unordered_set< symbol_exprt, irep_hash > propagated_static_localst
std::unordered_map< const symbol_exprt, const car_exprt, irep_hash > symbol_exprt_to_car_mapt
This class represents an instruction in the GOTO intermediate representation.
const exprt & target() const
Target expression.
bool stack_allocated_is_tracked(const symbol_exprt &symbol_expr) const
Returns true if the expression is tracked.
const exprt & condition() const
Condition expression.
static bool is_lte(size_t line0, size_t col0, size_t line1, size_t col1)
True iff (line0, col0) <= (line1, col1) in lexicographic ordering.
void track_stack_allocated(const symbol_exprt &symbol_expr, goto_programt &dest)
Track a stack-allocated object and generate snaphsot instructions in dest.
instructionst::iterator targett
const car_exprt & create_car_from_stack_alloc(const symbol_exprt &target)