Skip to content

Commit b0016ca

Browse files
authored
Merge pull request #1176 from diffblue/smv-typechecking
SMV: tighten expression type checking
2 parents d1e5533 + 759a77f commit b0016ca

File tree

3 files changed

+42
-20
lines changed

3 files changed

+42
-20
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
range_type9.smv
3+
4+
^file .* line 5: Expected expression of type `1..6', but got expression `7', which is of type `7..7'$
5+
^EXIT=2$
6+
^SIGNAL=0$
7+
--
8+
--
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
MODULE main
2+
VAR x: 1..6;
3+
4+
-- out of range
5+
ASSIGN x := 7;

src/smvlang/smv_typecheck.cpp

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,31 +1297,40 @@ void smv_typecheckt::convert_expr_to(exprt &expr, const typet &type)
12971297
}
12981298
else if(type.id() == ID_range)
12991299
{
1300-
if(expr.id() == ID_constant && expr.type().id() == ID_range)
1301-
{
1302-
// re-type the constant
1303-
auto value = numeric_cast_v<mp_integer>(to_constant_expr(expr));
1304-
expr = from_integer(value, type);
1305-
return;
1306-
}
1307-
else if(expr.id() == ID_cond && expr.type().id() == ID_range)
1300+
if(expr.type().id() == ID_range)
13081301
{
1309-
// re-type the cond
1310-
bool condition = true;
1311-
1312-
for(auto &op : expr.operands())
1302+
// range to range
1303+
if(expr.id() == ID_constant)
13131304
{
1314-
if(!condition)
1315-
convert_expr_to(op, type);
1305+
// re-type the constant
1306+
auto value = numeric_cast_v<mp_integer>(to_constant_expr(expr));
1307+
if(to_range_type(type).includes(value))
1308+
{
1309+
expr = from_integer(value, type);
1310+
return;
1311+
}
1312+
}
1313+
else if(expr.id() == ID_cond)
1314+
{
1315+
// re-type the cond
1316+
bool condition = true;
1317+
1318+
for(auto &op : expr.operands())
1319+
{
1320+
if(!condition)
1321+
convert_expr_to(op, type);
13161322

1317-
condition = !condition;
1323+
condition = !condition;
1324+
}
1325+
expr.type() = type;
1326+
return;
1327+
}
1328+
else
1329+
{
1330+
expr = typecast_exprt{expr, type};
1331+
return;
13181332
}
1319-
expr.type() = type;
1320-
return;
13211333
}
1322-
1323-
expr = typecast_exprt{expr, type};
1324-
return;
13251334
}
13261335
else if(type.id() == ID_bool)
13271336
{

0 commit comments

Comments
 (0)