Skip to content

Commit 761f686

Browse files
author
Daniel Kroening
committed
fix for pusing a numerical typecast into pointer arithmetic
1 parent fcf4aeb commit 761f686

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/util/simplify_expr.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
415415
}
416416

417417
// Push a numerical typecast into pointer arithmetic
418-
// (T)(x + y) ---> (T)((size_t)x + (size_t)y)
418+
// (T)(ptr + int) ---> (T)((size_t)ptr + sizeof(subtype)*(size_t)int)
419419
//
420420
if((expr_type.id()==ID_signedbv || expr_type.id()==ID_unsignedbv) &&
421421
op_type.id()==ID_pointer &&
@@ -428,13 +428,18 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
428428
const unsignedbv_typet size_t_type(config.ansi_c.pointer_width);
429429
expr.op0().type()=size_t_type;
430430

431-
Forall_operands(it, expr.op0())
431+
for(auto & it : expr.op0().operands())
432432
{
433-
it->make_typecast(size_t_type);
434-
435-
if(step>1 &&
436-
it->type().id()!=ID_pointer)
437-
*it=mult_exprt(from_integer(step, size_t_type), *it);
433+
if(it.type().id()==ID_pointer)
434+
{
435+
it.make_typecast(size_t_type);
436+
}
437+
else
438+
{
439+
it.make_typecast(size_t_type);
440+
if(step>1)
441+
it=mult_exprt(from_integer(step, size_t_type), it);
442+
}
438443
}
439444

440445
simplify_rec(expr);

0 commit comments

Comments
 (0)