Skip to content

Commit 5ecb825

Browse files
author
Daniel Kroening
committed
use typecast_exprt() instead of .make_typecast
.make_typecast() isn't type save; use the constructor for the resulting expression instead.
1 parent f2adef0 commit 5ecb825

10 files changed

+18
-21
lines changed

src/ansi-c/c_typecast.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,16 +734,15 @@ void c_typecastt::do_typecast(exprt &expr, const typet &dest_type)
734734

735735
if(dest_type.get(ID_C_c_type)==ID_bool)
736736
{
737-
expr=is_not_zero(expr, ns);
738-
expr.make_typecast(dest_type);
737+
expr = typecast_exprt(is_not_zero(expr, ns), dest_type);
739738
}
740739
else if(dest_type.id()==ID_bool)
741740
{
742741
expr=is_not_zero(expr, ns);
743742
}
744743
else
745744
{
746-
expr.make_typecast(dest_type);
745+
expr = typecast_exprt(expr, dest_type);
747746
}
748747
}
749748
}

src/ansi-c/c_typecheck_code.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void c_typecheck_baset::typecheck_return(codet &code)
667667
warning() << to_string(code.op0().type());
668668
warning() << eom;
669669

670-
code.op0().make_typecast(return_type);
670+
code.op0() = typecast_exprt(code.op0(), return_type);
671671
}
672672
}
673673
else

src/ansi-c/c_typecheck_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ void c_typecheck_baset::typecheck_compound_body(
10191019
exprt &assertion=it->op0();
10201020
typecheck_expr(assertion);
10211021
typecheck_expr(it->op1());
1022-
assertion.make_typecast(bool_typet());
1022+
assertion = typecast_exprt(assertion, bool_typet());
10231023
make_constant(assertion);
10241024

10251025
if(assertion.is_false())

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,5 +1708,5 @@ void cpp_typecheckt::make_ptr_typecast(
17081708
assert(subtype_typecast(src_struct, dest_struct) ||
17091709
subtype_typecast(dest_struct, src_struct));
17101710

1711-
expr.make_typecast(dest_type);
1711+
expr = typecast_exprt(expr, dest_type);
17121712
}

src/linking/linking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ void linkingt::duplicate_object_symbol(
10711071
{
10721072
// the type has been updated, now make sure that the initialising assignment
10731073
// will have matching types
1074-
old_symbol.value.make_typecast(old_symbol.type);
1074+
old_symbol.value = typecast_exprt(old_symbol.value, old_symbol.type);
10751075
}
10761076
}
10771077

src/solvers/lowering/popcount.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ exprt lower_popcount(const popcount_exprt &expr, const namespacet &ns)
3030
CHECK_RETURN(x_width.has_value() && *x_width >= 1);
3131
const std::size_t bits = address_bits(*x_width);
3232
const std::size_t new_width = numeric_cast_v<std::size_t>(power(2, bits));
33+
3334
const bool need_typecast =
3435
new_width > *x_width || x.type().id() != ID_unsignedbv;
36+
3537
if(need_typecast)
36-
x.make_typecast(unsignedbv_typet(new_width));
38+
x = typecast_exprt(x, unsignedbv_typet(new_width));
3739

3840
// repeatedly compute x = (x & bitmask) + ((x >> shift) & bitmask)
3941
for(std::size_t shift = 1; shift < new_width; shift <<= 1)
@@ -54,7 +56,5 @@ exprt lower_popcount(const popcount_exprt &expr, const namespacet &ns)
5456
}
5557

5658
// the result is restricted to the result type
57-
x.make_typecast(expr.type());
58-
59-
return x;
59+
return typecast_exprt(x, expr.type());
6060
}

src/util/simplify_expr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
364364

365365
Forall_operands(it, result)
366366
{
367-
it->make_typecast(expr.type());
367+
*it = typecast_exprt(*it, expr.type());
368368
simplify_typecast(*it); // recursive call
369369
}
370370

@@ -397,11 +397,11 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
397397
{
398398
if(op.type().id()==ID_pointer)
399399
{
400-
op.make_typecast(size_t_type);
400+
op = typecast_exprt(op, size_t_type);
401401
}
402402
else
403403
{
404-
op.make_typecast(size_t_type);
404+
op = typecast_exprt(op, size_t_type);
405405
if(*step > 1)
406406
op = mult_exprt(from_integer(*step, size_t_type), op);
407407
}

src/util/simplify_expr_array.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ bool simplify_exprt::simplify_index(exprt &expr)
168168
// These are index/value pairs, alternating.
169169
for(size_t i=0; i<array.operands().size()/2; i++)
170170
{
171-
exprt tmp_index=array.operands()[i*2];
172-
tmp_index.make_typecast(index.type());
171+
exprt tmp_index = typecast_exprt(array.operands()[i * 2], index.type());
173172
simplify(tmp_index);
174173
if(tmp_index==index)
175174
{

src/util/simplify_expr_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ bool simplify_exprt::simplify_bitwise(exprt &expr)
703703
new_expr.type()=bool_typet();
704704
simplify_node(new_expr);
705705

706-
new_expr.make_typecast(expr.type());
706+
new_expr = typecast_exprt(new_expr, expr.type());
707707
simplify_node(new_expr);
708708

709709
expr.swap(new_expr);

src/util/simplify_expr_pointer.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ bool simplify_exprt::simplify_pointer_offset(exprt &expr)
269269
if(ptr.op0().is_constant())
270270
{
271271
// (T *)0x1234 -> 0x1234
272-
exprt tmp=ptr.op0();
273-
tmp.make_typecast(expr.type());
272+
exprt tmp = typecast_exprt(ptr.op0(), expr.type());
274273
simplify_node(tmp);
275274
expr.swap(tmp);
276275
return false;
@@ -324,7 +323,7 @@ bool simplify_exprt::simplify_pointer_offset(exprt &expr)
324323
exprt tmp=op;
325324
if(tmp.type()!=expr.type())
326325
{
327-
tmp.make_typecast(expr.type());
326+
tmp = typecast_exprt(tmp, expr.type());
328327
simplify_node(tmp);
329328
}
330329

@@ -673,7 +672,7 @@ bool simplify_exprt::simplify_object_size(exprt &expr)
673672

674673
if(size.type() != expr_type)
675674
{
676-
size.make_typecast(expr_type);
675+
size = typecast_exprt(size, expr_type);
677676
simplify_node(size);
678677
}
679678

0 commit comments

Comments
 (0)