Skip to content

Commit 85d61b5

Browse files
authored
Merge pull request #3944 from tautschnig/deprecation-nil_typet-sizeof
Replace use of deprecated nil_typet in c_sizeof_type_rec [blocks: #3800]
2 parents 70b96ab + 44da594 commit 85d61b5

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/goto-symex/symex_builtin_functions.cpp

+32-32
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Author: Daniel Kroening, [email protected]
2121
#include <util/string2int.h>
2222
#include <util/string_constant.h>
2323

24-
inline static typet c_sizeof_type_rec(const exprt &expr)
24+
inline static optionalt<typet> c_sizeof_type_rec(const exprt &expr)
2525
{
2626
const irept &sizeof_type=expr.find(ID_C_c_sizeof_type);
2727

@@ -33,13 +33,13 @@ inline static typet c_sizeof_type_rec(const exprt &expr)
3333
{
3434
forall_operands(it, expr)
3535
{
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())
3838
return t;
3939
}
4040
}
4141

42-
return nil_typet();
42+
return {};
4343
}
4444

4545
void goto_symext::symex_allocate(
@@ -55,7 +55,7 @@ void goto_symext::symex_allocate(
5555
dynamic_counter++;
5656

5757
exprt size=code.op0();
58-
typet object_type=nil_typet();
58+
optionalt<typet> object_type;
5959
auto function_symbol = outer_symbol_table.lookup(state.source.function_id);
6060
INVARIANT(function_symbol, "function associated with allocation not found");
6161
const irep_idt &mode = function_symbol->mode;
@@ -75,60 +75,60 @@ void goto_symext::symex_allocate(
7575

7676
// special treatment for sizeof(T)*x
7777
{
78-
typet tmp_type=c_sizeof_type_rec(tmp_size);
78+
const auto tmp_type = c_sizeof_type_rec(tmp_size);
7979

80-
if(tmp_type.is_not_nil())
80+
if(tmp_type.has_value())
8181
{
8282
// 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);
8585

8686
if(!elem_size.has_value() || *elem_size==0)
8787
{
8888
}
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()))
9493
{
9594
exprt s=tmp_size.op0();
9695
if(s.is_constant())
9796
{
9897
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);
10099
}
101100
else
102-
PRECONDITION(c_sizeof_type_rec(tmp_size.op1()) == tmp_type);
101+
PRECONDITION(*c_sizeof_type_rec(tmp_size.op1()) == *tmp_type);
103102

104-
object_type=array_typet(tmp_type, s);
103+
object_type = array_typet(*tmp_type, s);
105104
}
106105
else
107106
{
108-
if(alloc_size == *elem_size)
109-
object_type=tmp_type;
107+
if(*alloc_size == *elem_size)
108+
object_type = *tmp_type;
110109
else
111110
{
112-
mp_integer elements = alloc_size / (*elem_size);
111+
mp_integer elements = *alloc_size / (*elem_size);
113112

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()));
117116
}
118117
}
119118
}
120119
}
121120

122-
if(object_type.is_nil())
121+
if(!object_type.has_value())
123122
object_type=array_typet(unsigned_char_type(), tmp_size);
124123

125124
// we introduce a fresh symbol for the size
126125
// to prevent any issues of the size getting ever changed
127126

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())
130130
{
131-
exprt &array_size = to_array_type(object_type).size();
131+
exprt &array_size = to_array_type(*object_type).size();
132132

133133
auxiliary_symbolt size_symbol;
134134

@@ -155,7 +155,7 @@ void goto_symext::symex_allocate(
155155
value_symbol.base_name="dynamic_object"+std::to_string(dynamic_counter);
156156
value_symbol.name="symex_dynamic::"+id2string(value_symbol.base_name);
157157
value_symbol.is_lvalue=true;
158-
value_symbol.type=object_type;
158+
value_symbol.type = *object_type;
159159
value_symbol.type.set(ID_C_dynamic, true);
160160
value_symbol.mode = mode;
161161

@@ -171,23 +171,23 @@ void goto_symext::symex_allocate(
171171
if(!zero_init.is_zero() && !zero_init.is_false())
172172
{
173173
const auto zero_value =
174-
zero_initializer(object_type, code.source_location(), ns);
174+
zero_initializer(*object_type, code.source_location(), ns);
175175
CHECK_RETURN(zero_value.has_value());
176176
code_assignt assignment(value_symbol.symbol_expr(), *zero_value);
177177
symex_assign(state, assignment);
178178
}
179179
else
180180
{
181-
const exprt nondet = build_symex_nondet(object_type);
181+
const exprt nondet = build_symex_nondet(*object_type);
182182
const code_assignt assignment(value_symbol.symbol_expr(), nondet);
183183
symex_assign(state, assignment);
184184
}
185185

186186
exprt rhs;
187187

188-
if(object_type.id()==ID_array)
188+
if(object_type->id() == ID_array)
189189
{
190-
const auto &array_type = to_array_type(object_type);
190+
const auto &array_type = to_array_type(*object_type);
191191
index_exprt index_expr(
192192
value_symbol.symbol_expr(), from_integer(0, index_type()));
193193
rhs = address_of_exprt(index_expr, pointer_type(array_type.subtype()));

0 commit comments

Comments
 (0)