21
21
#include < util/string2int.h>
22
22
#include < util/string_constant.h>
23
23
24
- inline static typet c_sizeof_type_rec (const exprt &expr)
24
+ inline static optionalt< typet> c_sizeof_type_rec (const exprt &expr)
25
25
{
26
26
const irept &sizeof_type=expr.find (ID_C_c_sizeof_type);
27
27
@@ -33,13 +33,13 @@ inline static typet c_sizeof_type_rec(const exprt &expr)
33
33
{
34
34
forall_operands (it, expr)
35
35
{
36
- typet t= c_sizeof_type_rec (*it);
37
- if (t.is_not_nil ())
36
+ const auto t = c_sizeof_type_rec (*it);
37
+ if (t.has_value ())
38
38
return t;
39
39
}
40
40
}
41
41
42
- return nil_typet () ;
42
+ return {} ;
43
43
}
44
44
45
45
void goto_symext::symex_allocate (
@@ -55,7 +55,7 @@ void goto_symext::symex_allocate(
55
55
dynamic_counter++;
56
56
57
57
exprt size=code.op0 ();
58
- typet object_type= nil_typet () ;
58
+ optionalt< typet> object_type;
59
59
auto function_symbol = outer_symbol_table.lookup (state.source .function_id );
60
60
INVARIANT (function_symbol, " function associated with allocation not found" );
61
61
const irep_idt &mode = function_symbol->mode ;
@@ -75,60 +75,60 @@ void goto_symext::symex_allocate(
75
75
76
76
// special treatment for sizeof(T)*x
77
77
{
78
- typet tmp_type= c_sizeof_type_rec (tmp_size);
78
+ const auto tmp_type = c_sizeof_type_rec (tmp_size);
79
79
80
- if (tmp_type.is_not_nil ())
80
+ if (tmp_type.has_value ())
81
81
{
82
82
// Did the size get multiplied?
83
- auto elem_size = pointer_offset_size (tmp_type, ns);
84
- mp_integer alloc_size;
83
+ auto elem_size = pointer_offset_size (* tmp_type, ns);
84
+ const auto alloc_size = numeric_cast<mp_integer>(tmp_size) ;
85
85
86
86
if (!elem_size.has_value () || *elem_size==0 )
87
87
{
88
88
}
89
- else if (to_integer (tmp_size, alloc_size) &&
90
- tmp_size.id ()==ID_mult &&
91
- tmp_size.operands ().size ()==2 &&
92
- (tmp_size.op0 ().is_constant () ||
93
- tmp_size.op1 ().is_constant ()))
89
+ else if (
90
+ !alloc_size.has_value () && tmp_size.id () == ID_mult &&
91
+ tmp_size.operands ().size () == 2 &&
92
+ (tmp_size.op0 ().is_constant () || tmp_size.op1 ().is_constant ()))
94
93
{
95
94
exprt s=tmp_size.op0 ();
96
95
if (s.is_constant ())
97
96
{
98
97
s=tmp_size.op1 ();
99
- PRECONDITION (c_sizeof_type_rec (tmp_size.op0 ()) == tmp_type);
98
+ PRECONDITION (* c_sizeof_type_rec (tmp_size.op0 ()) == * tmp_type);
100
99
}
101
100
else
102
- PRECONDITION (c_sizeof_type_rec (tmp_size.op1 ()) == tmp_type);
101
+ PRECONDITION (* c_sizeof_type_rec (tmp_size.op1 ()) == * tmp_type);
103
102
104
- object_type= array_typet (tmp_type, s);
103
+ object_type = array_typet (* tmp_type, s);
105
104
}
106
105
else
107
106
{
108
- if (alloc_size == *elem_size)
109
- object_type= tmp_type;
107
+ if (* alloc_size == *elem_size)
108
+ object_type = * tmp_type;
110
109
else
111
110
{
112
- mp_integer elements = alloc_size / (*elem_size);
111
+ mp_integer elements = * alloc_size / (*elem_size);
113
112
114
- if (elements * (*elem_size) == alloc_size)
115
- object_type= array_typet (
116
- tmp_type, from_integer (elements, tmp_size.type ()));
113
+ if (elements * (*elem_size) == * alloc_size)
114
+ object_type =
115
+ array_typet (* tmp_type, from_integer (elements, tmp_size.type ()));
117
116
}
118
117
}
119
118
}
120
119
}
121
120
122
- if (object_type.is_nil ())
121
+ if (! object_type.has_value ())
123
122
object_type=array_typet (unsigned_char_type (), tmp_size);
124
123
125
124
// we introduce a fresh symbol for the size
126
125
// to prevent any issues of the size getting ever changed
127
126
128
- if (object_type.id ()==ID_array &&
129
- !to_array_type (object_type).size ().is_constant ())
127
+ if (
128
+ object_type->id () == ID_array &&
129
+ !to_array_type (*object_type).size ().is_constant ())
130
130
{
131
- exprt &array_size = to_array_type (object_type).size ();
131
+ exprt &array_size = to_array_type (* object_type).size ();
132
132
133
133
auxiliary_symbolt size_symbol;
134
134
@@ -155,7 +155,7 @@ void goto_symext::symex_allocate(
155
155
value_symbol.base_name =" dynamic_object" +std::to_string (dynamic_counter);
156
156
value_symbol.name =" symex_dynamic::" +id2string (value_symbol.base_name );
157
157
value_symbol.is_lvalue =true ;
158
- value_symbol.type = object_type;
158
+ value_symbol.type = * object_type;
159
159
value_symbol.type .set (ID_C_dynamic, true );
160
160
value_symbol.mode = mode;
161
161
@@ -171,23 +171,23 @@ void goto_symext::symex_allocate(
171
171
if (!zero_init.is_zero () && !zero_init.is_false ())
172
172
{
173
173
const auto zero_value =
174
- zero_initializer (object_type, code.source_location (), ns);
174
+ zero_initializer (* object_type, code.source_location (), ns);
175
175
CHECK_RETURN (zero_value.has_value ());
176
176
code_assignt assignment (value_symbol.symbol_expr (), *zero_value);
177
177
symex_assign (state, assignment);
178
178
}
179
179
else
180
180
{
181
- const exprt nondet = build_symex_nondet (object_type);
181
+ const exprt nondet = build_symex_nondet (* object_type);
182
182
const code_assignt assignment (value_symbol.symbol_expr (), nondet);
183
183
symex_assign (state, assignment);
184
184
}
185
185
186
186
exprt rhs;
187
187
188
- if (object_type. id ()== ID_array)
188
+ if (object_type-> id () == ID_array)
189
189
{
190
- const auto &array_type = to_array_type (object_type);
190
+ const auto &array_type = to_array_type (* object_type);
191
191
index_exprt index_expr (
192
192
value_symbol.symbol_expr (), from_integer (0 , index_type ()));
193
193
rhs = address_of_exprt (index_expr, pointer_type (array_type.subtype ()));
0 commit comments