Skip to content

Commit fb01a7e

Browse files
committed
SMV: lower typecasts between enumeration types
Typecasts between SMV enumeration types (e.g., assigning a variable of type {a, b} to one of type {a, b, c}) are not handled by the flattening. Lower these typecasts to cond expressions that map each source element constant to the corresponding destination element constant.
1 parent fa2c2c0 commit fb01a7e

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

regression/smv/enums/enum4.desc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
KNOWNBUG
1+
CORE broken-smt-backend
22
enum4.smv
33

44
^EXIT=0$
55
^SIGNAL=0$
66
--
77
^warning: ignoring
88
--
9-
This fails in the decision procedure.

src/smvlang/smv_typecheck.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,35 @@ void smv_typecheckt::lower_node(exprt &expr) const
18151815
auto cond_expr = to_smv_cases_expr(expr).lower();
18161816
expr = std::move(cond_expr);
18171817
}
1818+
else if(expr.id() == ID_typecast)
1819+
{
1820+
auto &typecast_expr = to_typecast_expr(expr);
1821+
auto &src_type = typecast_expr.op().type();
1822+
auto &dest_type = typecast_expr.type();
1823+
1824+
// enumeration to enumeration -- lower to cond
1825+
if(
1826+
src_type.id() == ID_enumeration &&
1827+
dest_type.id() == ID_smv_enumeration)
1828+
{
1829+
auto lowered_dest_type = dest_type;
1830+
lower(lowered_dest_type);
1831+
1832+
auto &src_elements = to_enumeration_type(src_type).elements();
1833+
1834+
cond_exprt cond_expr{{}, lowered_dest_type};
1835+
for(auto &element : src_elements)
1836+
{
1837+
cond_expr.add_case(
1838+
equal_exprt{
1839+
typecast_expr.op(), constant_exprt{element.id(), src_type}},
1840+
constant_exprt{element.id(), lowered_dest_type});
1841+
}
1842+
1843+
expr = std::move(cond_expr);
1844+
return; // type already set
1845+
}
1846+
}
18181847

18191848
// lower the type
18201849
lower(expr.type());

0 commit comments

Comments
 (0)