Skip to content

SMV: tighten expression type checking #1176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions regression/smv/range-type/range_type9.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
range_type9.smv

^file .* line 5: Expected expression of type `1..6', but got expression `7', which is of type `7..7'$
^EXIT=2$
^SIGNAL=0$
--
--
5 changes: 5 additions & 0 deletions regression/smv/range-type/range_type9.smv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE main
VAR x: 1..6;

-- out of range
ASSIGN x := 7;
49 changes: 29 additions & 20 deletions src/smvlang/smv_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,31 +1297,40 @@ void smv_typecheckt::convert_expr_to(exprt &expr, const typet &type)
}
else if(type.id() == ID_range)
{
if(expr.id() == ID_constant && expr.type().id() == ID_range)
{
// re-type the constant
auto value = numeric_cast_v<mp_integer>(to_constant_expr(expr));
expr = from_integer(value, type);
return;
}
else if(expr.id() == ID_cond && expr.type().id() == ID_range)
if(expr.type().id() == ID_range)
{
// re-type the cond
bool condition = true;

for(auto &op : expr.operands())
// range to range
if(expr.id() == ID_constant)
{
if(!condition)
convert_expr_to(op, type);
// re-type the constant
auto value = numeric_cast_v<mp_integer>(to_constant_expr(expr));
if(to_range_type(type).includes(value))
{
expr = from_integer(value, type);
return;
}
}
else if(expr.id() == ID_cond)
{
// re-type the cond
bool condition = true;

for(auto &op : expr.operands())
{
if(!condition)
convert_expr_to(op, type);

condition = !condition;
condition = !condition;
}
expr.type() = type;
return;
}
else
{
expr = typecast_exprt{expr, type};
return;
}
expr.type() = type;
return;
}

expr = typecast_exprt{expr, type};
return;
}
else if(type.id() == ID_bool)
{
Expand Down
Loading