ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
interval_domain.h
Go to the documentation of this file.
1
3
4#ifndef CPROVER_ANALYSES_INTERVAL_DOMAIN_H
5#define CPROVER_ANALYSES_INTERVAL_DOMAIN_H
6
10#include <boost/serialization/nvp.hpp>
12#include <irep2/irep2_utils.h>
13#include <util/arith/mp_arith.h>
14#include <util/base/threeval.h>
15#include <boost/multiprecision/cpp_bin_float.hpp>
16#include <variant>
17
24{
25public:
29
30 using interval = std::variant<
31 std::shared_ptr<integer_intervalt>,
32 std::shared_ptr<real_intervalt>,
33 std::shared_ptr<wrapped_interval>>;
34
35 // Map of variables into intervals.
36 // If a key does not exist then imply the TOP interval.
37 // If a key exists then the shared_ptr must point to a valid place
38 using interval_map = std::unordered_map<irep_idt, interval, irep_id_hash>;
39
43
44 void transform(
47 ai_baset &ai,
48 const namespacet &ns) final override;
49
50 void output(std::ostream &out) const override;
51
52 static void set_options(const optionst &options);
53
54 void dump() const;
55
56 // TODO: Add options for ai.h
57 // Extensions
66 static bool
68 static bool
75
89 static thread_local bool skip_inductive_step_instructions;
90 // Widening options
91 static unsigned
97 static bool widening_narrowing;
98
101 static tvt
103
104protected:
119 bool join(const interval_domaint &b, const goto_programt::const_targett &to);
120
121public:
122 bool merge(
123 const interval_domaint &b,
126 {
127 const bool result = join(b, to);
128 copied = false;
129 return result;
130 }
131
133 {
135 // get_empty() is shared: the next write must copy it first.
136 copied = false;
137 }
138
139 // no states
140 void make_bottom() final override
141 {
142 clear_state();
143 bottom = true;
144 }
145
146 // all states
147 void make_top() final override
148 {
149 clear_state();
150 bottom = false;
151 }
152
153 void make_entry() final override
154 {
155 make_top();
156 }
157
158 bool is_bottom() const override final
159 {
160 return bottom;
161 }
162
163 bool is_top() const override final
164 {
165 return !bottom && intervals->empty();
166 }
167
182 expr2tc make_expression(const expr2tc &symbol) const;
183
190 void assume(const expr2tc &);
191
193 void assume_assertion(const expr2tc &guard, const ai_baset &ai);
194
207
211 void join_snapshot(const std::shared_ptr<interval_map> &snapshot);
212
222 void havoc_rec(const expr2tc &expr);
223
227
230 bool havoc_pointee(const expr2tc &arg, bool any_type);
231
251 virtual bool
252 ai_simplify(expr2tc &condition, const namespacet &ns) const override;
253
254 std::shared_ptr<interval_map> intervals;
255 bool copied = false;
256
257 static std::shared_ptr<interval_map> get_empty()
258 {
259 static std::shared_ptr<interval_map> map = std::make_shared<interval_map>();
260 return map;
261 }
263 {
264 if (copied)
265 return;
266 std::shared_ptr<interval_map> cpy = std::make_shared<interval_map>();
267 *cpy = *intervals;
268 intervals = cpy;
269 copied = true;
270 }
271
272protected:
273 // Abstract state information
276 bool bottom;
277
290 void assume_rec(const expr2tc &expr, bool negation = false);
291
300 void assume_rec(const expr2tc &lhs, expr2t::expr_ids id, const expr2tc &rhs);
301
309 void assign(const expr2tc &assignment, const bool recursive = false);
310
320 template <class Interval>
321 void apply_assignment(const expr2tc &lhs, const expr2tc &rhs, bool recursive);
322
354 template <class Interval>
355 Interval
356 extrapolate_intervals(const Interval &before, const Interval &after) const;
357
380 template <class Interval>
381 Interval interpolate_intervals(const Interval &before, const Interval &after);
382
391 template <class Interval>
392 void apply_assume_less(const expr2tc &lhs, const expr2tc &rhs);
393
401 template <class Interval>
402 void apply_assume_symbol_truth(const symbol2t &sym, bool is_false);
403
412 template <class Interval>
413 Interval generate_modular_interval(const type2tc &t) const;
414
417 template <class Interval>
418 Interval wrap_to_type(const Interval &i, const type2tc &t) const;
419
420public:
430 template <class Interval>
431 Interval get_interval(const expr2tc &e) const;
432
440 template <class Interval>
441 Interval get_interval_from_symbol(const symbol2t &sym) const;
442
443 template <size_t Index, class Interval>
444 Interval get_interval_from_variant(const symbol2t &sym) const;
445
446 template <class Interval>
447 bool join_intervals(
448 const std::shared_ptr<Interval> &after,
449 std::shared_ptr<Interval> &dst,
450 bool can_extrapolate) const;
451
459 template <class Interval>
460 Interval get_interval_from_const(const expr2tc &sym) const;
461
462 template <class Interval>
463 Interval
464 get_interval_from_typecast(const typecast2t &cast, Interval result) const;
465
466 template <class Interval>
467 Interval get_top_interval_from_expr(const expr2tc &sym) const;
468
469 template <class Interval>
470 bool is_mapped(const symbol2t &sym) const;
471
472 template <class Interval>
473 expr2tc make_expression_helper(const expr2tc &symbol) const;
474
475 template <class Interval>
477 const Interval &interval,
478 const type2tc &type,
479 bool upper) const;
480
481protected:
482 template <class IntervalMap>
483 bool join(
484 IntervalMap &new_map,
485 const IntervalMap &previous_map,
486 const bool is_guard_instruction = true);
487
495 template <class Interval>
496 void update_symbol_interval(const symbol2t &sym, const Interval &value);
497
498 template <size_t Index, class Interval>
499 void update_symbol_from_variant(const symbol2t &sym, const Interval &value);
500};
501
502#endif // CPROVER_ANALYSES_INTERVAL_DOMAIN_H
Abstract Interpretation.
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition ai.h:27
ai_domain_baset()
The constructor is expected to produce 'false' or 'bottom'.
Definition ai_domain.h:19
Definition irep2_expr.h:2175
expr_ids
Enumeration identifying each sort of expr.
Definition irep2.h:730
instructionst::const_iterator const_targett
Definition goto_program.h:591
void clear_state()
Definition interval_domain.h:132
Interval get_interval_from_const(const expr2tc &sym) const
Get the interval from constant expression.
bool copied
Definition interval_domain.h:255
bool join(const interval_domaint &b, const goto_programt::const_targett &to)
Sets *this to the mathematical join between the two domains.
Definition interval_domain.cpp:1242
bool is_bottom() const override final
Definition interval_domain.h:158
void output(std::ostream &out) const override
Definition interval_domain.cpp:911
void make_bottom() final override
no states
Definition interval_domain.h:140
Interval get_interval_from_typecast(const typecast2t &cast, Interval result) const
bool join_intervals(const std::shared_ptr< Interval > &after, std::shared_ptr< Interval > &dst, bool can_extrapolate) const
Definition interval_domain.cpp:1121
Interval wrap_to_type(const Interval &i, const type2tc &t) const
Bring an interval computed over unbounded integers back into the range of the bitvector type t,...
Definition interval_domain.cpp:262
void copy_if_needed()
Definition interval_domain.h:262
virtual bool ai_simplify(expr2tc &condition, const namespacet &ns) const override
Uses the abstract state to simplify a given expression using context- specific information.
Definition interval_domain.cpp:1692
static bool enable_real_intervals
Enabled wrapped intervals (disables Integers).
Definition interval_domain.h:70
expr2tc make_expression_helper(const expr2tc &symbol) const
Definition interval_domain.cpp:839
expr2tc make_expression(const expr2tc &symbol) const
Creates an expression with the intervals found for the given symbol.
Definition interval_domain.cpp:1675
void update_symbol_interval(const symbol2t &sym, const Interval &value)
Sets new interval for symbol.
void apply_assume_less(const expr2tc &lhs, const expr2tc &rhs)
Applies LHS < RHS.
Definition interval_domain.cpp:653
static bool widening_under_approximate_bound
Sets a limit for number of iterations before widening.
Definition interval_domain.h:93
void assume_assertion(const expr2tc &guard, const ai_baset &ai)
Under –interval-analysis-assume-asserts, narrows the state to guard.
Definition interval_domain.cpp:1479
std::variant< std::shared_ptr< integer_intervalt >, std::shared_ptr< real_intervalt >, std::shared_ptr< wrapped_interval > > interval
Definition interval_domain.h:30
bool is_top() const override final
Definition interval_domain.h:163
static bool enable_assume_asserts
Enable real (floating-point) intervals.
Definition interval_domain.h:71
void update_symbol_from_variant(const symbol2t &sym, const Interval &value)
Definition interval_domain.cpp:52
static bool enable_eval_assumptions
Asserts are propagates as assumptions.
Definition interval_domain.h:72
Interval interpolate_intervals(const Interval &before, const Interval &after)
Applies Interpolation narrowing algorithm.
static bool enable_ibex_contractor
Try to evaluate in a guard in a TVT to accelerate bottoms.
Definition interval_domain.h:74
interval_domaint()
Definition interval_domain.h:40
bool bottom
Is this state a bottom.
Definition interval_domain.h:276
Interval get_interval_from_symbol(const symbol2t &sym) const
Get the interval from symbol object or top.
Interval get_interval(const expr2tc &e) const
Get the interval for expression.
std::unordered_map< irep_idt, interval, irep_id_hash > interval_map
Definition interval_domain.h:38
void make_top() final override
all states – the analysis doesn't use this, and domains may refuse to implement it.
Definition interval_domain.h:147
static bool widening_extrapolate
Whether to considers overflows for Integers.
Definition interval_domain.h:95
Interval extrapolate_intervals(const Interval &before, const Interval &after) const
Applies Extrapolation widening algorithm.
static bool widening_narrowing
Extrapolate bound to infinity based on previous iteration.
Definition interval_domain.h:97
static tvt eval_boolean_expression(const expr2tc &cond, const interval_domaint &id)
Interpolate bound back after fixpoint.
Definition interval_domain.cpp:1555
void havoc_written_arguments(const code_function_call2t &call)
Forget what a body-less call that symex models may write through its pointer arguments (#8083).
Definition interval_domain.cpp:1372
static bool enable_assertion_simplification
Make a modular operation after every assignment.
Definition interval_domain.h:64
Interval get_top_interval_from_expr(const expr2tc &sym) const
Definition interval_domain.cpp:348
bool is_mapped(const symbol2t &sym) const
static bool enable_interval_bitwise_arithmetic
Enable simplification for arithmetic operators.
Definition interval_domain.h:60
std::shared_ptr< interval_map > intervals
Definition interval_domain.h:254
Interval get_interval_from_variant(const symbol2t &sym) const
Definition interval_domain.cpp:19
void make_entry() final override
a reasonable entry-point state
Definition interval_domain.h:153
void assume(const expr2tc &)
Adds a restriction over all intervals.
Definition interval_domain.cpp:1491
void join_snapshot(const std::shared_ptr< interval_map > &snapshot)
Join the domain recorded when another symex path was parked into this one, over every variable: a pat...
Definition interval_domain.cpp:1274
static std::shared_ptr< interval_map > get_empty()
Definition interval_domain.h:257
static unsigned fixpoint_limit
Definition interval_domain.h:92
void assign(const expr2tc &assignment, const bool recursive=false)
Computes an assignment expression.
Definition interval_domain.cpp:1290
static bool enable_contraction_for_abstract_states
Simplify condition and assertions with the intervals.
Definition interval_domain.h:67
static bool enable_wrapped_intervals
Use contractor for <= operations.
Definition interval_domain.h:69
void dump() const
Definition interval_domain.cpp:1669
bool havoc_pointee(const expr2tc &arg, bool any_type)
Havoc the variable arg points into; false when that is unknown and arg, a pointer or any_type,...
Definition interval_domain.cpp:1359
void havoc_rec(const expr2tc &expr)
Recursively explores an Expression until it reaches a symbol, then removes it from the int_map whatev...
Definition interval_domain.cpp:1392
bool merge(const interval_domaint &b, goto_programt::const_targett, goto_programt::const_targett to)
Definition interval_domain.h:122
static bool enable_interval_arithmetic
Definition interval_domain.h:58
interval_templatet< BigInt > integer_intervalt
Definition interval_domain.h:26
static void set_options(const optionst &options)
Definition interval_domain.cpp:1716
void assume_rec(const expr2tc &expr, bool negation=false)
Recursively explores intervals of an assume expression.
Definition interval_domain.cpp:1586
void apply_assume_symbol_truth(const symbol2t &sym, bool is_false)
Applies symbol = truth.
Definition interval_domain.cpp:101
interval_templatet< boost::multiprecision::cpp_bin_float_100 > real_intervalt
Definition interval_domain.h:27
void apply_assignment(const expr2tc &lhs, const expr2tc &rhs, bool recursive)
Applies LHS <= RHS and RHS <= LHS from assignment instructions.
Definition interval_domain.cpp:291
expr2tc make_expression_value(const Interval &interval, const type2tc &type, bool upper) const
Interval generate_modular_interval(const type2tc &t) const
Generates interval with [min, max] of type t.
void process_instruction(goto_programt::const_targett from)
Updates the interval state based on a single goto-program instruction.
Definition interval_domain.cpp:1749
static bool enable_modular_intervals
Enable simplification for bitwise operations.
Definition interval_domain.h:62
static bool skip_inductive_step_instructions
Use ibex contractor.
Definition interval_domain.h:89
This class is used to store intervals in the form of lower <= upper.
Definition interval_template.h:20
Definition namespace.h:10
Definition options.h:11
Symbol type.
Definition irep2_expr.h:625
Definition threeval.h:10
Typecast expression.
Definition irep2_expr.h:729
Definition toml.hpp:1531
pthread_cond_t cond
Definition cuda.h:50
irep_container< type2t > type2tc
Definition irep2.h:430
irep_container< expr2t > expr2tc
Definition irep2.h:431
bool is_false(const expr2tc &expr)
Test if expr is false.
Definition irep2_utils.h:241
Definition transform.py:1
typet any_type()
Definition python_types.cpp:10
#define true
Definition stdbool.h:11