Check that fast math intrinsic results are finite - #4730
Open
feliperodri wants to merge 1 commit into
Open
Conversation
Previously, Kani only verified that the inputs to fast math intrinsics (fadd_fast, fsub_fast, fmul_fast, fdiv_fast) were finite. However, per the Rust documentation, producing a non-finite result (infinity or NaN) from these intrinsics is also undefined behavior, even when both inputs are finite (e.g., f32::MAX + f32::MAX overflows to infinity). This commit adds a result finiteness check to all four fast math intrinsics. After the operation is performed and assigned to the destination, the result is asserted (and assumed) to be finite. Regression tests are added covering: - All four fast math intrinsics with finite inputs that overflow to infinity (kani-verify-fail). - Pointer wrapping_add with extreme offsets confirming these are correctly NOT flagged as UB under default settings. Signed-off-by: Felipe Monteiro <felisous@amazon.com>
feliperodri
force-pushed
the
fix/fadd-fast-result-finite-check
branch
from
August 12, 2026 21:08
49d7f96 to
141382c
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.
Previously, Kani only verified that the inputs to fast math intrinsics (
fadd_fast,fsub_fast,fmul_fast,fdiv_fast) were finite. However, per the Rust documentation, producing a non-finite result (infinity or NaN) from these intrinsics is also undefined behavior, even when both inputs are finite (e.g.,f32::MAX+f32::MAXoverflows to infinity).This commit adds a result finiteness check to all four fast math intrinsics. After the operation is performed and assigned to the destination, the result is asserted (and assumed) to be finite.
Regression tests are added covering:
kani-verify-fail).wrapping_addwith extreme offsets confirming these are correctly NOT flagged as UB under default settings.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.