Skip to content
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

[SMT] Parse SMT bitvector width as signed #8042

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TaoBi22
Copy link
Contributor

@TaoBi22 TaoBi22 commented Jan 8, 2025

Fixes an issue where SMT bitvector widths being parsed as unsigned meant that e.g. !smt.bv<-1> would wrap around and be interpreted as a 18446744073709551615-wide bitvector. The downside of this fix is that the error messages for bitvectors that are too wide become a little less clear (see the updated test) - does this still look like an ok fix to you @maerhart? Let me know if I should also drop the code that's emitting that error in the RepeatOp verifier, don't think it can be triggered after this but I may have missed a case.

@TaoBi22 TaoBi22 added bug Something isn't working SMT labels Jan 8, 2025
@TaoBi22 TaoBi22 requested a review from maerhart as a code owner January 8, 2025 16:42
Copy link
Member

@maerhart maerhart left a comment

Choose a reason for hiding this comment

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

It might be cleaner to write a custom parser that avoids the implicit conversion (basically parsing an APInt and doing the necessary checks before converting it to uint64_t).
When creating this type in C++ you probably give it an unsigned int, so the implicit conversion to a signed int could be a bit annoying there (but also only in corner cases).
But this approach is also fine for me.

I assume something like #8062 can still happen after this change (just the bitwidth to trigger it would be smaller)?

@@ -89,8 +96,8 @@ func.func @repeat_count_too_large(%arg0: !smt.bv<32>) {

// -----

func.func @repeat_result_type_bitwidth_too_large(%arg0: !smt.bv<18446744073709551612>) {
// expected-error @below {{result bit-width (provided integer times bit-width of the input type) must fit into 64 bits}}
smt.bv.repeat 2 times %arg0 : !smt.bv<18446744073709551612>
Copy link
Member

Choose a reason for hiding this comment

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

In the repeat parser, 64 is hardcoded as the width of the unsigned integer used. We'd need to adjust this and keep this error test but with a smaller number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SMT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants