Skip to content

Commit bdda3c3

Browse files
authored
Merge pull request #4178 from tautschnig/enum-from-integer
Simplify integer -> enum-tag type casts
2 parents c0819f9 + b58eb6f commit bdda3c3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/util/simplify_expr.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,17 @@ bool simplify_exprt::simplify_typecast(exprt &expr)
570570
expr=from_integer(int_value, expr_type);
571571
return false;
572572
}
573+
else if(expr_type_id == ID_c_enum_tag)
574+
{
575+
const auto &c_enum_type = ns.follow_tag(to_c_enum_tag_type(expr_type));
576+
if(!c_enum_type.is_incomplete()) // possibly incomplete
577+
{
578+
exprt tmp = from_integer(int_value, c_enum_type);
579+
tmp.type() = expr_type; // we maintain the tag type
580+
expr = tmp;
581+
return false;
582+
}
583+
}
573584
}
574585
else if(op_type_id==ID_rational)
575586
{

0 commit comments

Comments
 (0)