Skip to content

SMV: convert typecasts to SMV #1094

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
May 18, 2025
Merged

SMV: convert typecasts to SMV #1094

merged 1 commit into from
May 18, 2025

Conversation

kroening
Copy link
Member

@kroening kroening commented May 1, 2025

This adds conversion for a variety of typecast expressions into SMV syntax.

@kroening kroening added the SMV label May 1, 2025
@kroening kroening force-pushed the expr2smv-typecast branch from 328c22d to 898660b Compare May 1, 2025 00:47
@kroening kroening force-pushed the expr2smv-typecast branch from 898660b to 3615f28 Compare May 8, 2025 18:26
@kroening kroening marked this pull request as ready for review May 13, 2025 20:01

if(src_width == dest_width)
{
// signess change only
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit pick: signess -> signedness

Comment on lines +257 to +261
// Signedness _and_ width change. First go to signed, then extend.
return convert_rec(smv_extend_exprt{
smv_signed_cast_exprt{expr.op(), signedbv_typet{src_width}},
dest_width - src_width,
dest_type});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please have a test that covers this case? I suppose the order of operations makes a difference when the most significant bit is 1.

to_signedbv_type(src_type).get_width() ==
to_unsignedbv_type(dest_type).get_width())
{
// signess change only
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

signess -> signedness

Comment on lines +286 to +291
// Signedness _and_ width change.
// First enlarge, then go unsigned.
return convert_rec(smv_unsigned_cast_exprt{
smv_extend_exprt{
expr.op(), dest_width - src_width, signedbv_typet{dest_width}},
dest_type});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again: test would be most appreciated.

else if(src_type.id() == ID_signedbv && dest_type.id() == ID_signedbv)
{
// signed to signed, width change.
// Note that resize(...) preserves the sign bit, unlike our typecast.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use extend rather than resize here.

@kroening kroening force-pushed the expr2smv-typecast branch from 3615f28 to 5b8d0f2 Compare May 15, 2025 20:16
Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, but tests would be appreciated as indicated.

@kroening kroening force-pushed the expr2smv-typecast branch 3 times, most recently from 4777980 to 485489e Compare May 18, 2025 14:30
@kroening
Copy link
Member Author

Test added with all 12 cases.

@kroening kroening force-pushed the expr2smv-typecast branch from 485489e to 2447060 Compare May 18, 2025 14:37
This adds conversion for a variety of typecast expressions into SMV syntax.
@kroening kroening force-pushed the expr2smv-typecast branch from 2447060 to 86c8025 Compare May 18, 2025 14:40
@kroening kroening merged commit 2d61d66 into main May 18, 2025
9 checks passed
@kroening kroening deleted the expr2smv-typecast branch May 18, 2025 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants