Skip to content

Commit b64a22e

Browse files
author
Daniel Kroening
committed
add correct type conversion when using subtype() or subtypes()
1 parent ec75c5d commit b64a22e

21 files changed

+113
-83
lines changed

src/analyses/goto_rw.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,9 @@ void rw_range_sett::get_objects_rec(const typet &type)
594594
// TODO should recurse into various composite types
595595
if(type.id()==ID_array)
596596
{
597-
get_objects_rec(type.subtype());
598-
get_objects_rec(get_modet::READ, to_array_type(type).size());
597+
const auto &array_type = to_array_type(type);
598+
get_objects_rec(array_type.subtype());
599+
get_objects_rec(get_modet::READ, array_type.size());
599600
}
600601
}
601602

src/cpp/cpp_template_type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ inline const template_typet &to_template_type(const typet &type)
5050
inline const typet &template_subtype(const typet &type)
5151
{
5252
if(type.id()==ID_template)
53-
return type.subtype();
53+
return static_cast<const type_with_subtypet &>(type).subtype();
5454

5555
return type;
5656
}
5757

5858
inline typet &template_subtype(typet &type)
5959
{
6060
if(type.id()==ID_template)
61-
return type.subtype();
61+
return static_cast<type_with_subtypet &>(type).subtype();
6262

6363
return type;
6464
}

src/goto-instrument/thread_instrumentation.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,7 @@ void mutex_init_instrumentation(goto_modelt &goto_model)
140140

141141
Forall_goto_functions(f_it, goto_model.goto_functions)
142142
mutex_init_instrumentation(
143-
goto_model.symbol_table, f_it->second.body, lock_type.subtype());
143+
goto_model.symbol_table,
144+
f_it->second.body,
145+
to_pointer_type(lock_type).subtype());
144146
}

src/goto-symex/auto_objects.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void goto_symext::initialize_auto_object(
5757
else if(type.id()==ID_pointer)
5858
{
5959
const pointer_typet &pointer_type=to_pointer_type(type);
60-
const typet &subtype=ns.follow(type.subtype());
60+
const typet &subtype = ns.follow(pointer_type.subtype());
6161

6262
// we don't like function pointers and
6363
// we don't like void *
@@ -67,7 +67,7 @@ void goto_symext::initialize_auto_object(
6767
// could be NULL nondeterministically
6868

6969
address_of_exprt address_of_expr(
70-
make_auto_object(type.subtype(), state), pointer_type);
70+
make_auto_object(pointer_type.subtype(), state), pointer_type);
7171

7272
if_exprt rhs(
7373
side_effect_expr_nondett(bool_typet(), expr.source_location()),

src/goto-symex/goto_symex_state.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static bool check_renaming(const typet &type)
220220
return true;
221221
}
222222
else if(type.has_subtype())
223-
return check_renaming(type.subtype());
223+
return check_renaming(to_type_with_subtype(type).subtype());
224224

225225
return false;
226226
}
@@ -501,7 +501,7 @@ void goto_symex_statet::rename(
501501
DATA_INVARIANT(
502502
expr.type().id() == ID_pointer,
503503
"type of address_of should be ID_pointer");
504-
expr.type().subtype()=expr.op0().type();
504+
to_pointer_type(expr.type()).subtype() = expr.op0().type();
505505
}
506506
else
507507
{
@@ -737,7 +737,7 @@ void goto_symex_statet::rename_address(
737737

738738
rename_address(index_expr.array(), ns, level);
739739
PRECONDITION(index_expr.array().type().id() == ID_array);
740-
expr.type()=index_expr.array().type().subtype();
740+
expr.type() = to_array_type(index_expr.array().type()).subtype();
741741

742742
// the index is not an address
743743
rename(index_expr.index(), ns, level);
@@ -822,8 +822,9 @@ void goto_symex_statet::rename(
822822

823823
if(type.id()==ID_array)
824824
{
825-
rename(type.subtype(), irep_idt(), ns, level);
826-
rename(to_array_type(type).size(), ns, level);
825+
auto &array_type = to_array_type(type);
826+
rename(array_type.subtype(), irep_idt(), ns, level);
827+
rename(array_type.size(), ns, level);
827828
}
828829
else if(type.id()==ID_struct ||
829830
type.id()==ID_union ||
@@ -844,7 +845,7 @@ void goto_symex_statet::rename(
844845
}
845846
else if(type.id()==ID_pointer)
846847
{
847-
rename(type.subtype(), irep_idt(), ns, level);
848+
rename(to_pointer_type(type).subtype(), irep_idt(), ns, level);
848849
}
849850
else if(type.id() == ID_symbol_type)
850851
{
@@ -888,8 +889,9 @@ void goto_symex_statet::get_original_name(typet &type) const
888889

889890
if(type.id()==ID_array)
890891
{
891-
get_original_name(type.subtype());
892-
get_original_name(to_array_type(type).size());
892+
auto &array_type = to_array_type(type);
893+
get_original_name(array_type.subtype());
894+
get_original_name(array_type.size());
893895
}
894896
else if(type.id()==ID_struct ||
895897
type.id()==ID_union ||
@@ -906,7 +908,7 @@ void goto_symex_statet::get_original_name(typet &type) const
906908
}
907909
else if(type.id()==ID_pointer)
908910
{
909-
get_original_name(type.subtype());
911+
get_original_name(to_pointer_type(type).subtype());
910912
}
911913
}
912914

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ void goto_symext::symex_allocate(
6060
const irep_idt &mode = function_symbol->mode;
6161

6262
// is the type given?
63-
if(code.type().id()==ID_pointer && code.type().subtype().id()!=ID_empty)
63+
if(
64+
code.type().id() == ID_pointer &&
65+
to_pointer_type(code.type()).subtype().id() != ID_empty)
6466
{
65-
object_type=code.type().subtype();
67+
object_type = to_pointer_type(code.type()).subtype();
6668
}
6769
else
6870
{
@@ -194,11 +196,11 @@ void goto_symext::symex_allocate(
194196

195197
if(object_type.id()==ID_array)
196198
{
197-
index_exprt index_expr(value_symbol.type.subtype());
199+
const auto &array_type = to_array_type(object_type);
200+
index_exprt index_expr(array_type.subtype());
198201
index_expr.array()=value_symbol.symbol_expr();
199202
index_expr.index()=from_integer(0, index_type());
200-
rhs=address_of_exprt(
201-
index_expr, pointer_type(value_symbol.type.subtype()));
203+
rhs = address_of_exprt(index_expr, pointer_type(array_type.subtype()));
202204
}
203205
else
204206
{
@@ -400,6 +402,8 @@ void goto_symext::symex_cpp_new(
400402
if(code.type().id()!=ID_pointer)
401403
throw "new expected to return pointer";
402404

405+
const auto &pointer_type = to_pointer_type(code.type());
406+
403407
do_array =
404408
(code.get(ID_statement) == ID_cpp_new_array ||
405409
code.get(ID_statement) == ID_java_new_array_data);
@@ -427,19 +431,18 @@ void goto_symext::symex_cpp_new(
427431
{
428432
exprt size_arg = static_cast<const exprt &>(code.find(ID_size));
429433
clean_expr(size_arg, state, false);
430-
symbol.type = array_typet(code.type().subtype(), size_arg);
434+
symbol.type = array_typet(pointer_type.subtype(), size_arg);
431435
}
432436
else
433-
symbol.type=code.type().subtype();
437+
symbol.type = pointer_type.subtype();
434438

435439
symbol.type.set(ID_C_dynamic, true);
436440

437441
state.symbol_table.add(symbol);
438442

439443
// make symbol expression
440444

441-
exprt rhs(ID_address_of, code.type());
442-
rhs.type().subtype()=code.type().subtype();
445+
exprt rhs(ID_address_of, pointer_type);
443446

444447
if(do_array)
445448
{

src/goto-symex/symex_dereference.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,11 @@ void goto_symext::dereference_rec(
321321
exprt &object=address_of_expr.object();
322322

323323
const typet &expr_type=ns.follow(expr.type());
324-
expr=address_arithmetic(object, state, guard,
325-
expr_type.subtype().id()==ID_array);
324+
expr = address_arithmetic(
325+
object,
326+
state,
327+
guard,
328+
to_pointer_type(expr_type).subtype().id() == ID_array);
326329
}
327330
else if(expr.id()==ID_typecast)
328331
{

src/util/arith_tools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ bool to_integer(const constant_exprt &expr, mp_integer &int_value)
7272
}
7373
else if(type_id==ID_c_bit_field)
7474
{
75-
const typet &subtype=type.subtype();
75+
const typet &subtype = to_c_bit_field_type(type).subtype();
7676
if(subtype.id()==ID_signedbv)
7777
{
7878
int_value=binary2integer(id2string(value), true);

src/util/expr_initializer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ exprt expr_initializert<nondet>::expr_initializer_rec(
112112
result = side_effect_expr_nondett(type, source_location);
113113
else
114114
{
115-
exprt sub_zero = expr_initializer_rec(type.subtype(), source_location);
115+
exprt sub_zero =
116+
expr_initializer_rec(to_complex_type(type).subtype(), source_location);
116117
result = complex_exprt(sub_zero, sub_zero, to_complex_type(type));
117118
}
118119

src/util/expr_util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ bool has_subtype(
181181
}
182182
else
183183
{
184-
for(const auto &subtype : top.subtypes())
184+
for(const auto &subtype : to_type_with_subtypes(top).subtypes())
185185
push_if_not_visited(subtype);
186186
}
187187
}

src/util/find_symbols.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void find_symbols(kindt kind, const typet &src, find_symbols_sett &dest)
124124
src.id()!=ID_pointer)
125125
{
126126
if(src.has_subtype())
127-
find_symbols(kind, src.subtype(), dest);
127+
find_symbols(kind, to_type_with_subtype(src).subtype(), dest);
128128

129129
forall_subtypes(it, src)
130130
find_symbols(kind, *it, dest);

src/util/format_type.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ std::ostream &format_rec(std::ostream &os, const typet &type)
4040
const auto &id = type.id();
4141

4242
if(id == ID_pointer)
43-
return os << '*' << format(type.subtype());
43+
return os << '*' << format(to_pointer_type(type).subtype());
4444
else if(id == ID_array)
4545
{
4646
const auto &t = to_array_type(type);
4747
if(t.is_complete())
48-
return os << format(type.subtype()) << '[' << format(t.size()) << ']';
48+
return os << format(t.subtype()) << '[' << format(t.size()) << ']';
4949
else
50-
return os << format(type.subtype()) << "[]";
50+
return os << format(t.subtype()) << "[]";
5151
}
5252
else if(id == ID_struct)
5353
return format_rec(os, to_struct_type(type));

src/util/json_expr.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ json_objectt json(
154154
else if(type.id()==ID_c_enum_tag)
155155
{
156156
// we return the base type
157-
return json(ns.follow_tag(to_c_enum_tag_type(type)).subtype(), ns, mode);
157+
return json(
158+
to_c_enum_type(ns.follow_tag(to_c_enum_tag_type(type))).subtype(),
159+
ns,
160+
mode);
158161
}
159162
else if(type.id()==ID_fixedbv)
160163
{
@@ -165,7 +168,7 @@ json_objectt json(
165168
else if(type.id()==ID_pointer)
166169
{
167170
result["name"]=json_stringt("pointer");
168-
result["subtype"]=json(type.subtype(), ns, mode);
171+
result["subtype"] = json(to_pointer_type(type).subtype(), ns, mode);
169172
}
170173
else if(type.id()==ID_bool)
171174
{
@@ -174,12 +177,12 @@ json_objectt json(
174177
else if(type.id()==ID_array)
175178
{
176179
result["name"]=json_stringt("array");
177-
result["subtype"]=json(type.subtype(), ns, mode);
180+
result["subtype"] = json(to_array_type(type).subtype(), ns, mode);
178181
}
179182
else if(type.id()==ID_vector)
180183
{
181184
result["name"]=json_stringt("vector");
182-
result["subtype"]=json(type.subtype(), ns, mode);
185+
result["subtype"] = json(to_vector_type(type).subtype(), ns, mode);
183186
result["size"]=json(to_vector_type(type).size(), ns, mode);
184187
}
185188
else if(type.id()==ID_struct)
@@ -242,9 +245,8 @@ json_objectt json(
242245
lang=std::unique_ptr<languaget>(get_default_language());
243246
}
244247

245-
const typet &underlying_type=
246-
type.id()==ID_c_bit_field?type.subtype():
247-
type;
248+
const typet &underlying_type =
249+
type.id() == ID_c_bit_field ? to_c_bit_field_type(type).subtype() : type;
248250

249251
std::string type_string;
250252
bool error=lang->from_type(underlying_type, type_string, ns);
@@ -270,7 +272,8 @@ json_objectt json(
270272
{
271273
result["name"]=json_stringt("integer");
272274
result["binary"] = json_stringt(constant_expr.get_value());
273-
result["width"]=json_numbert(type.subtype().get_string(ID_width));
275+
result["width"] =
276+
json_numbert(to_c_enum_type(type).subtype().get_string(ID_width));
274277
result["type"]=json_stringt("enum");
275278
result["data"]=json_stringt(value_string);
276279
}

0 commit comments

Comments
 (0)