Skip to content

SMT-LIB2: shifts with wider shift distances#8834

Open
kroening wants to merge 1 commit intodevelopfrom
smt2-shift
Open

SMT-LIB2: shifts with wider shift distances#8834
kroening wants to merge 1 commit intodevelopfrom
smt2-shift

Conversation

@kroening
Copy link
Collaborator

@kroening kroening commented Feb 9, 2026

This fixes the case of converting shifts where the shift distance is wider than the shift operand to SMT-LIB2.

SMT-LIB2 requires that the width of the shift operand and the shift distance is the same. To not lose leading bits of the shift distance, use the wider one of the two as the width of the shift, and truncate the result when needed.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • n/a My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

❌ Patch coverage is 98.68421% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.01%. Comparing base (15eb10a) to head (a136328).

Files with missing lines Patch % Lines
src/solvers/smt2/smt2_conv.cpp 97.61% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8834   +/-   ##
========================================
  Coverage    80.00%   80.01%           
========================================
  Files         1700     1700           
  Lines       188252   188312   +60     
  Branches        73       73           
========================================
+ Hits        150613   150675   +62     
+ Misses       37639    37637    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kroening kroening force-pushed the smt2-shift branch 2 times, most recently from 7fed5fd to 365bd7b Compare February 9, 2026 18:51
Comment on lines +1862 to +1864
out << "((_ zero_extend " << width_op - width_distance << ") ";
convert_expr(shift_expr.distance());
out << ")"; // zero_extend
out << ')'; // zero_extend
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't this require the use of sign_extend if distance_type.id() == ID_signedbv? (And possibly also for distance_type.id() == ID_c_enum if the underlying type is signed.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We never had shifts with negative distance, and I don't see a need to introduce them. I'll add a comment to the expression class and the implementation that these have no meaning.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But then lines 1836.. check for exactly that. (I was also thinking that we should not have such types here, but then we should DATA_INVARIANT'ing this here and really not have those cases in the decision of the if statement).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We have never banned the use of signed types as arguments for the shift distance. We just don't give meaning for negative values.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Fair enough - can we please have a comment to say that we always interpret the distance as an unsigned bitvector, irrespective of the type it actually has?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

This fixes the case of converting shifts where the shift distance is wider
than the shift operand to SMT-LIB2.

SMT-LIB2 requires that the width of the shift operand and the shift distance
is the same.  To not lose leading bits of the shift distance, use the
wider one of the two as the width of the shift, and truncate the result
when needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants