Skip to content

Commit 7031dc2

Browse files
committed
Make interpretation of "is constant" match that of goto_symex_statet::constant_propagation
1 parent 78c7005 commit 7031dc2

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

src/analyses/constant_propagator.cpp

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -278,30 +278,54 @@ bool constant_propagator_domaint::ai_simplify(
278278

279279
bool constant_propagator_domaint::valuest::is_constant(const exprt &expr) const
280280
{
281-
if(expr.id()==ID_side_effect &&
282-
to_side_effect_expr(expr).get_statement()==ID_nondet)
283-
return false;
281+
if(expr.is_constant())
282+
return true;
284283

285-
if(expr.id()==ID_side_effect &&
286-
to_side_effect_expr(expr).get_statement()==ID_allocate)
287-
return false;
284+
if(expr.id() == ID_address_of)
285+
{
286+
const address_of_exprt &address_of_expr = to_address_of_expr(expr);
288287

289-
if(expr.id()==ID_symbol)
290-
if(replace_const.expr_map.find(to_symbol_expr(expr).get_identifier())==
291-
replace_const.expr_map.end())
292-
return false;
288+
return is_constant_address_of(address_of_expr.object());
289+
}
290+
else if(expr.id() == ID_typecast)
291+
{
292+
const typecast_exprt &typecast_expr = to_typecast_expr(expr);
293293

294-
if(expr.id()==ID_index)
295-
return false;
294+
return is_constant(typecast_expr.op());
295+
}
296+
else if(expr.id() == ID_array_of)
297+
{
298+
return is_constant(expr.op0());
299+
}
300+
else if(
301+
expr.id() == ID_plus || expr.id() == ID_array ||
302+
expr.id() == ID_struct || expr.id() == ID_union)
303+
{
304+
forall_operands(it, expr)
305+
if(!is_constant(*it))
306+
return false;
296307

297-
if(expr.id()==ID_address_of)
298-
return is_constant_address_of(to_address_of_expr(expr).object());
308+
return true;
309+
}
310+
// byte_update works, byte_extract may be out-of-bounds
311+
else if(
312+
expr.id() == ID_byte_update_big_endian ||
313+
expr.id() == ID_byte_update_little_endian)
314+
{
315+
forall_operands(it, expr)
316+
if(!is_constant(*it))
317+
return false;
299318

300-
forall_operands(it, expr)
301-
if(!is_constant(*it))
302-
return false;
319+
return true;
320+
}
321+
else if(expr.id() == ID_symbol)
322+
{
323+
return
324+
replace_const.expr_map.find(to_symbol_expr(expr).get_identifier()) !=
325+
replace_const.expr_map.end();
326+
}
303327

304-
return true;
328+
return false;
305329
}
306330

307331
bool constant_propagator_domaint::valuest::is_constant_address_of(
@@ -320,7 +344,10 @@ bool constant_propagator_domaint::valuest::is_constant_address_of(
320344
if(expr.id()==ID_string_constant)
321345
return true;
322346

323-
return true;
347+
if(expr.id()==ID_symbol)
348+
return true;
349+
350+
return false;
324351
}
325352

326353
/// Do not call this when iterating over replace_const.expr_map!

0 commit comments

Comments
 (0)