Skip to content

Commit d3bee61

Browse files
authored
Merge pull request #8222 from tautschnig/cleanup/no-follow-goto-symex
goto-symex: Replace uses of namespacet::follow
2 parents 27c4de3 + 588fc07 commit d3bee61

7 files changed

+68
-34
lines changed

Diff for: src/goto-symex/auto_objects.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ exprt goto_symext::make_auto_object(const typet &type, statet &state)
3434

3535
void goto_symext::initialize_auto_object(const exprt &expr, statet &state)
3636
{
37-
const typet &type=ns.follow(expr.type());
37+
DATA_INVARIANT(
38+
expr.type().id() != ID_struct,
39+
"no L2-renamed expression expected, all struct-like types should be tags");
3840

39-
if(type.id()==ID_struct)
41+
if(
42+
auto struct_tag_type = type_try_dynamic_cast<struct_tag_typet>(expr.type()))
4043
{
41-
const struct_typet &struct_type=to_struct_type(type);
44+
const struct_typet &struct_type = ns.follow_tag(*struct_tag_type);
4245

4346
for(const auto &comp : struct_type.components())
4447
{
@@ -47,10 +50,9 @@ void goto_symext::initialize_auto_object(const exprt &expr, statet &state)
4750
initialize_auto_object(member_expr, state);
4851
}
4952
}
50-
else if(type.id()==ID_pointer)
53+
else if(auto pointer_type = type_try_dynamic_cast<pointer_typet>(expr.type()))
5154
{
52-
const pointer_typet &pointer_type=to_pointer_type(type);
53-
const typet &base_type = pointer_type.base_type();
55+
const typet &base_type = pointer_type->base_type();
5456

5557
// we don't like function pointers and
5658
// we don't like void *
@@ -59,11 +61,11 @@ void goto_symext::initialize_auto_object(const exprt &expr, statet &state)
5961
// could be NULL nondeterministically
6062

6163
address_of_exprt address_of_expr(
62-
make_auto_object(base_type, state), pointer_type);
64+
make_auto_object(base_type, state), *pointer_type);
6365

6466
if_exprt rhs(
6567
side_effect_expr_nondett(bool_typet(), expr.source_location()),
66-
null_pointer_exprt(pointer_type),
68+
null_pointer_exprt(*pointer_type),
6769
address_of_expr);
6870

6971
symex_assign(state, expr, rhs);

Diff for: src/goto-symex/field_sensitivity.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ exprt field_sensitivityt::apply(
9999
be.op().type().id() == ID_union_tag) &&
100100
is_ssa_expr(be.op()) && be.offset().is_constant())
101101
{
102-
const union_typet &type = to_union_type(ns.follow(be.op().type()));
102+
const union_typet &type =
103+
be.op().type().id() == ID_union_tag
104+
? ns.follow_tag(to_union_tag_type(be.op().type()))
105+
: to_union_type(be.op().type());
103106
for(const auto &comp : type.components())
104107
{
105108
ssa_exprt tmp = to_ssa_expr(be.op());
@@ -221,9 +224,12 @@ exprt field_sensitivityt::get_fields(
221224
(!disjoined_fields_only && (ssa_expr.type().id() == ID_union ||
222225
ssa_expr.type().id() == ID_union_tag)))
223226
{
224-
const struct_union_typet &type =
225-
to_struct_union_type(ns.follow(ssa_expr.type()));
226-
const struct_union_typet::componentst &components = type.components();
227+
const struct_union_typet::componentst &components =
228+
(ssa_expr.type().id() == ID_struct_tag ||
229+
ssa_expr.type().id() == ID_union_tag)
230+
? ns.follow_tag(to_struct_or_union_tag_type(ssa_expr.type()))
231+
.components()
232+
: to_struct_union_type(ssa_expr.type()).components();
227233

228234
exprt::operandst fields;
229235
fields.reserve(components.size());
@@ -371,7 +377,10 @@ void field_sensitivityt::field_assignments_rec(
371377
else if(
372378
ssa_rhs.type().id() == ID_struct || ssa_rhs.type().id() == ID_struct_tag)
373379
{
374-
const struct_typet &type = to_struct_type(ns.follow(ssa_rhs.type()));
380+
const struct_typet &type =
381+
ssa_rhs.type().id() == ID_struct_tag
382+
? ns.follow_tag(to_struct_tag_type(ssa_rhs.type()))
383+
: to_struct_type(ssa_rhs.type());
375384
const struct_union_typet::componentst &components = type.components();
376385

377386
PRECONDITION(
@@ -409,7 +418,10 @@ void field_sensitivityt::field_assignments_rec(
409418
else if(
410419
ssa_rhs.type().id() == ID_union || ssa_rhs.type().id() == ID_union_tag)
411420
{
412-
const union_typet &type = to_union_type(ns.follow(ssa_rhs.type()));
421+
const union_typet &type =
422+
ssa_rhs.type().id() == ID_union_tag
423+
? ns.follow_tag(to_union_tag_type(ssa_rhs.type()))
424+
: to_union_type(ssa_rhs.type());
413425
const struct_union_typet::componentst &components = type.components();
414426

415427
PRECONDITION(

Diff for: src/goto-symex/goto_symex_state.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -741,17 +741,22 @@ void goto_symex_statet::rename(
741741
}
742742
}
743743

744-
// expand struct and union tag types
745-
type = ns.follow(type);
746-
747744
if(type.id()==ID_array)
748745
{
749746
auto &array_type = to_array_type(type);
750747
rename<level>(array_type.element_type(), irep_idt(), ns);
751748
array_type.size() = rename<level>(std::move(array_type.size()), ns).get();
752749
}
753-
else if(type.id() == ID_struct || type.id() == ID_union)
750+
else if(
751+
type.id() == ID_struct || type.id() == ID_union ||
752+
type.id() == ID_struct_tag || type.id() == ID_union_tag)
754753
{
754+
// expand struct and union tag types
755+
if(type.id() == ID_struct_tag)
756+
type = ns.follow_tag(to_struct_tag_type(type));
757+
else if(type.id() == ID_union_tag)
758+
type = ns.follow_tag(to_union_tag_type(type));
759+
755760
struct_union_typet &s_u_type=to_struct_union_type(type);
756761
struct_union_typet::componentst &components=s_u_type.components();
757762

Diff for: src/goto-symex/shadow_memory.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ void shadow_memoryt::initialize_shadow_memory(
3030
exprt expr,
3131
const shadow_memory_field_definitionst::field_definitiont &fields)
3232
{
33-
typet type = ns.follow(expr.type());
34-
clean_pointer_expr(expr, type);
33+
// clean_pointer_expr may change the type
34+
typet type = expr.type();
35+
clean_pointer_expr(expr);
3536
for(const auto &field_pair : fields)
3637
{
3738
const symbol_exprt &shadow = add_field(state, expr, field_pair.first, type);

Diff for: src/goto-symex/shadow_memory_util.cpp

+23-11
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,12 @@ exprt deref_expr(const exprt &expr)
249249
return dereference_exprt(expr);
250250
}
251251

252-
void clean_pointer_expr(exprt &expr, const typet &type)
252+
void clean_pointer_expr(exprt &expr)
253253
{
254254
if(
255-
can_cast_type<array_typet>(type) && can_cast_expr<symbol_exprt>(expr) &&
256-
to_array_type(type).size().get_bool(ID_C_SSA_symbol))
255+
can_cast_type<array_typet>(expr.type()) &&
256+
can_cast_expr<symbol_exprt>(expr) &&
257+
to_array_type(expr.type()).size().get_bool(ID_C_SSA_symbol))
257258
{
258259
remove_array_type_l2(expr.type());
259260
exprt original_expr = to_ssa_expr(expr).get_original_expr();
@@ -448,12 +449,17 @@ exprt compute_or_over_bytes(
448449
can_cast_type<c_bool_typet>(field_type) ||
449450
can_cast_type<bool_typet>(field_type),
450451
"Can aggregate bytes with *or* only if the shadow memory type is _Bool.");
451-
const typet type = ns.follow(expr.type());
452452

453-
if(type.id() == ID_struct || type.id() == ID_union)
453+
if(
454+
expr.type().id() == ID_struct || expr.type().id() == ID_union ||
455+
expr.type().id() == ID_struct_tag || expr.type().id() == ID_union_tag)
454456
{
457+
const auto &components =
458+
(expr.type().id() == ID_struct_tag || expr.type().id() == ID_union_tag)
459+
? ns.follow_tag(to_struct_or_union_tag_type(expr.type())).components()
460+
: to_struct_union_type(expr.type()).components();
455461
exprt::operandst values;
456-
for(const auto &component : to_struct_union_type(type).components())
462+
for(const auto &component : components)
457463
{
458464
if(component.get_is_padding())
459465
{
@@ -464,9 +470,9 @@ exprt compute_or_over_bytes(
464470
}
465471
return or_values(values, field_type);
466472
}
467-
else if(type.id() == ID_array)
473+
else if(expr.type().id() == ID_array)
468474
{
469-
const array_typet &array_type = to_array_type(type);
475+
const array_typet &array_type = to_array_type(expr.type());
470476
if(array_type.size().is_constant())
471477
{
472478
exprt::operandst values;
@@ -495,7 +501,10 @@ exprt compute_or_over_bytes(
495501
if(is_union)
496502
{
497503
extract_bytes_of_bv(
498-
conditional_cast_floatbv_to_unsignedbv(expr), type, field_type, values);
504+
conditional_cast_floatbv_to_unsignedbv(expr),
505+
expr.type(),
506+
field_type,
507+
values);
499508
}
500509
else
501510
{
@@ -998,11 +1007,14 @@ normalize(const object_descriptor_exprt &expr, const namespacet &ns)
9981007
else if(object.id() == ID_member)
9991008
{
10001009
const member_exprt &member_expr = to_member_expr(object);
1010+
const auto &struct_op = member_expr.struct_op();
10011011
const struct_typet &struct_type =
1002-
to_struct_type(ns.follow(member_expr.struct_op().type()));
1012+
struct_op.type().id() == ID_struct_tag
1013+
? ns.follow_tag(to_struct_tag_type(struct_op.type()))
1014+
: to_struct_type(struct_op.type());
10031015
offset +=
10041016
*member_offset(struct_type, member_expr.get_component_name(), ns);
1005-
object = member_expr.struct_op();
1017+
object = struct_op;
10061018
}
10071019
else
10081020
{

Diff for: src/goto-symex/shadow_memory_util.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ irep_idt extract_field_name(const exprt &string_expr);
7575
/// L2 symbols and string constants not having char-pointer type.
7676
/// \param expr The pointer to the original memory, e.g. as passed to
7777
/// __CPROVER_field_get.
78-
/// \param type The followed type of expr.
79-
void clean_pointer_expr(exprt &expr, const typet &type);
78+
void clean_pointer_expr(exprt &expr);
8079

8180
/// Wraps a given expression into a `dereference_exprt` unless it is an
8281
/// `address_of_exprt` in which case it just unboxes it and returns its content.

Diff for: src/goto-symex/symex_assign.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,10 @@ void symex_assignt::assign_from_struct(
168168
const struct_exprt &rhs,
169169
const exprt::operandst &guard)
170170
{
171-
const auto &components = to_struct_type(ns.follow(lhs.type())).components();
171+
const auto &components =
172+
lhs.type().id() == ID_struct_tag
173+
? ns.follow_tag(to_struct_tag_type(lhs.type())).components()
174+
: to_struct_type(lhs.type()).components();
172175
PRECONDITION(rhs.operands().size() == components.size());
173176

174177
for(const auto &comp_rhs : make_range(components).zip(rhs.operands()))

0 commit comments

Comments
 (0)