Skip to content

Commit 0e2b13f

Browse files
committed
Remove tautological typecasts
1 parent a9fa893 commit 0e2b13f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/util/simplify_expr.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
240240
if(expr_type.id()==ID_c_bool &&
241241
op_type.id()!=ID_bool)
242242
{
243+
// casts from boolean to a signed int and back:
244+
// (boolean)(int)boolean -> boolean
245+
if(expr.op0().id()==ID_typecast && op_type.id()==ID_signedbv)
246+
{
247+
const auto &typecast=to_typecast_expr(expr.op0());
248+
if(typecast.op().type().id()==ID_c_bool)
249+
{
250+
expr=typecast.op0();
251+
return false;
252+
}
253+
}
254+
243255
// rewrite (_Bool)x to (_Bool)(x!=0)
244256
binary_relation_exprt inequality;
245257
inequality.id(op_type.id()==ID_floatbv?ID_ieee_float_notequal:ID_notequal);

0 commit comments

Comments
 (0)