Skip to content

SMV: typechecking for unary minus #893

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion regression/ebmc/range_type/range_type8.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ range_type8.smv
^SIGNAL=0$
--
--
We do not have type checking for unary minus.
We do not have solver support for unary minus on ranges.
6 changes: 6 additions & 0 deletions src/smvlang/smv_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ class smv_ranget

return *this;
}

// unary minus
smv_ranget operator-() const
{
return smv_ranget{-to, -from};
}
};

#endif // CPROVER_SMV_RANGE_H
23 changes: 23 additions & 0 deletions src/smvlang/smv_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,29 @@ void smv_typecheckt::typecheck_expr_rec(
<< "Expected number type for " << to_string(expr);
}
}
else if(expr.id() == ID_unary_minus)
{
typecheck_op(expr, dest_type, mode);

if(expr.operands().size() != 1)
{
error().source_location = expr.find_source_location();
error() << "Expected one operand for " << expr.id() << eom;
throw 0;
}

if(dest_type.is_nil())
{
if(expr.type().id() == ID_range || expr.type().id() == ID_bool)
{
// find proper type for precise arithmetic
smv_ranget smv_range_op =
convert_type(to_unary_minus_expr(expr).op().type());
smv_ranget new_range = -smv_range_op;
new_range.to_type(expr.type());
}
}
}
else if(expr.id()==ID_constant)
{
if(expr.type().id()==ID_integer)
Expand Down
Loading