Skip to content

Commit c240b22

Browse files
Cleanup invariants in remove_vector
1 parent edcf580 commit c240b22

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/goto-programs/remove_vector.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,18 @@ static void remove_vector(exprt &expr)
8282
expr.id()==ID_mod || expr.id()==ID_bitxor ||
8383
expr.id()==ID_bitand || expr.id()==ID_bitor)
8484
{
85+
// FIXME plus, mult, bitxor, bitand and bitor are defined as n-ary
86+
// operations rather than binary. This code assumes that they
87+
// can only have exactly 2 operands, and it is not clear
88+
// that it is safe to do so in this context
89+
PRECONDITION(expr.operands().size() == 2);
90+
auto const &binary_expr = to_binary_expr(expr);
8591
remove_vector(expr.type());
8692
array_typet array_type=to_array_type(expr.type());
8793

8894
mp_integer dimension;
8995
to_integer(array_type.size(), dimension);
9096

91-
assert(expr.operands().size()==2);
9297
const typet subtype=array_type.subtype();
9398
// do component-wise:
9499
// x+y -> vector(x[0]+y[0],x[1]+y[1],...)
@@ -99,22 +104,23 @@ static void remove_vector(exprt &expr)
99104
{
100105
exprt index=from_integer(i, array_type.size().type());
101106

102-
array_expr.operands()[i]=
103-
binary_exprt(index_exprt(expr.op0(), index, subtype), expr.id(),
104-
index_exprt(expr.op1(), index, subtype));
107+
array_expr.operands()[i] = binary_exprt(
108+
index_exprt(binary_expr.op0(), index, subtype),
109+
binary_expr.id(),
110+
index_exprt(binary_expr.op1(), index, subtype));
105111
}
106112

107113
expr=array_expr;
108114
}
109115
else if(expr.id()==ID_unary_minus || expr.id()==ID_bitnot)
110116
{
117+
auto const &unary_expr = to_unary_expr(expr);
111118
remove_vector(expr.type());
112119
array_typet array_type=to_array_type(expr.type());
113120

114121
mp_integer dimension;
115122
to_integer(array_type.size(), dimension);
116123

117-
assert(expr.operands().size()==1);
118124
const typet subtype=array_type.subtype();
119125
// do component-wise:
120126
// -x -> vector(-x[0],-x[1],...)
@@ -125,8 +131,8 @@ static void remove_vector(exprt &expr)
125131
{
126132
exprt index=from_integer(i, array_type.size().type());
127133

128-
array_expr.operands()[i]=
129-
unary_exprt(expr.id(), index_exprt(expr.op0(), index, subtype));
134+
array_expr.operands()[i] = unary_exprt(
135+
unary_expr.id(), index_exprt(unary_expr.op0(), index, subtype));
130136
}
131137

132138
expr=array_expr;

0 commit comments

Comments
 (0)