forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_set_dereference.h
147 lines (117 loc) · 3.57 KB
/
value_set_dereference.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*******************************************************************\
Module: Pointer Dereferencing
Author: Daniel Kroening, kroening@kroening.com
\*******************************************************************/
/// \file
/// Pointer Dereferencing
#ifndef CPROVER_POINTER_ANALYSIS_VALUE_SET_DEREFERENCE_H
#define CPROVER_POINTER_ANALYSIS_VALUE_SET_DEREFERENCE_H
#include <unordered_set>
#include <util/std_expr.h>
#include "dereference_callback.h"
class symbol_tablet;
class guardt;
class optionst;
class modet;
class symbolt;
/*! \brief TO_BE_DOCUMENTED
*/
class value_set_dereferencet
{
public:
/*! \brief Constructor
* \param _ns Namespace
* \param _new_symbol_table A symbol_table to store new symbols in
* \param _options Options, in particular whether pointer checks are
to be performed
* \param _dereference_callback Callback object for error reporting
*/
value_set_dereferencet(
const namespacet &_ns,
symbol_tablet &_new_symbol_table,
const optionst &_options,
dereference_callbackt &_dereference_callback,
const irep_idt _language_mode):
ns(_ns),
new_symbol_table(_new_symbol_table),
options(_options),
dereference_callback(_dereference_callback),
language_mode(_language_mode)
{ }
virtual ~value_set_dereferencet() { }
enum class modet { READ, WRITE };
/*!
* The method 'dereference' dereferences the
* given pointer-expression. Any errors are
* reported to the callback method given in the
* constructor.
*
* \param pointer A pointer-typed expression, to
be dereferenced.
* \param guard A guard, which is assumed to hold when
dereferencing.
* \param mode Indicates whether the dereferencing
is a load or store.
*/
virtual exprt dereference(
const exprt &pointer,
const guardt &guard,
const modet mode);
/*! \brief Returns 'true' iff the given expression contains unary '*'
*/
static bool has_dereference(const exprt &expr);
typedef std::unordered_set<exprt, irep_hash> expr_sett;
private:
const namespacet &ns;
symbol_tablet &new_symbol_table;
const optionst &options;
dereference_callbackt &dereference_callback;
/// language_mode: ID_java, ID_C or another language identifier
/// if we know the source language in use, irep_idt() otherwise.
const irep_idt language_mode;
static unsigned invalid_counter;
bool dereference_type_compare(
const typet &object_type,
const typet &dereference_type) const;
void offset_sum(
exprt &dest,
const exprt &offset) const;
class valuet
{
public:
exprt value;
exprt pointer_guard;
valuet():value(nil_exprt()), pointer_guard(false_exprt())
{
}
};
valuet build_reference_to(
const exprt &what,
const modet mode,
const exprt &pointer,
const guardt &guard);
bool get_value_guard(
const exprt &symbol,
const exprt &premise,
exprt &value);
static const exprt &get_symbol(const exprt &object);
void bounds_check(const index_exprt &expr, const guardt &guard);
void valid_check(const exprt &expr, const guardt &guard, const modet mode);
void invalid_pointer(const exprt &expr, const guardt &guard);
bool memory_model(
exprt &value,
const typet &type,
const guardt &guard,
const exprt &offset);
bool memory_model_conversion(
exprt &value,
const typet &type,
const guardt &guard,
const exprt &offset);
bool memory_model_bytes(
exprt &value,
const typet &type,
const guardt &guard,
const exprt &offset);
};
#endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_DEREFERENCE_H