Fix float-to-integer conversion for wide destination types#8986
Open
tautschnig wants to merge 1 commit into
Open
Fix float-to-integer conversion for wide destination types#8986tautschnig wants to merge 1 commit into
tautschnig wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes incorrect float-to-integer conversion when the destination integer width exceeds the float fraction width by extending the fraction before shifting and adding a regression test.
Changes:
- Extend
unpacked.fractiontodest_width(when needed) before computing the shift for integer conversion. - Adjust the shift offset computation to use the effective fraction width.
- Add regression tests covering wide float-to-int conversions (bitvector + SMT paths).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/solvers/floatbv/float_bv.cpp | Extends fraction width before shifting to avoid negative/incorrect shift distances for wide integer targets. |
| regression/cbmc/Float-to-int-wide/main.c | Adds a regression program exercising float-to-(wide)int conversions. |
| regression/cbmc/Float-to-int-wide/test.desc | Adds a FloatBV regression test harness entry. |
| regression/cbmc/Float-to-int-wide/test_smt.desc | Adds an SMT regression test harness entry for the same scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8986 +/- ##
===========================================
+ Coverage 80.59% 80.62% +0.02%
===========================================
Files 1711 1711
Lines 189454 189464 +10
Branches 73 73
===========================================
+ Hits 152697 152746 +49
+ Misses 36757 36718 -39 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
float_bvt::to_integer did not extend the fraction to dest_width before shifting, causing incorrect results when dest_width exceeds the fraction width (the shift distance went negative for large exponents). The fix mirrors the extend-then-shift pattern already used by float_utilst::to_integer. The PR carries over a latent constraint shared between both encodings: the shift distance is built in a bit-vector of width spec.e, so `dest_width - 1` must be representable in that signed/unsigned bit width. For the integer types C currently supports this holds — float (spec.e = 8) supports dest_width up to 128 (i.e. up to __int128); double (spec.e = 11) supports dest_width up to 1024. That assumption is now an explicit PRECONDITION on both float_bvt::to_integer and float_utilst::to_integer, with matching 'keep in sync' comments. Widening the subtraction type to support even wider integer destinations (and pulling the integer-conversion logic out into a single helper shared between the two IR layers) is a sensible follow-up. Regression test exercises the bug across the parameter space: int (at and above 2^24), unsigned int (including a 2^31 case where unsigned-vs-signed semantics matter), long long from float and double sources (the 64-bit destination cases that were the most common practical breakage), and __int128 from both float and double sources where supported. Without the fix, eight of these eleven assertions fail on develop. Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
1195e13 to
e14b54d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
float_bvt::to_integer did not extend the fraction to dest_width before shifting, causing incorrect results when dest_width exceeds the fraction width (the shift distance went negative for large exponents).