Skip to content

Check that fast math intrinsic results are finite - #4730

Open
feliperodri wants to merge 1 commit into
model-checking:mainfrom
feliperodri:fix/fadd-fast-result-finite-check
Open

Check that fast math intrinsic results are finite#4730
feliperodri wants to merge 1 commit into
model-checking:mainfrom
feliperodri:fix/fadd-fast-result-finite-check

Conversation

@feliperodri

Copy link
Copy Markdown
Member

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.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@feliperodri
feliperodri requested a review from a team as a code owner August 12, 2026 20:52
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Aug 12, 2026
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
feliperodri force-pushed the fix/fadd-fast-result-finite-check branch from 49d7f96 to 141382c Compare August 12, 2026 21:08
@feliperodri feliperodri added the [F] Soundness Kani failed to detect an issue label Aug 12, 2026
@feliperodri
feliperodri requested a balanced review from Copilot August 12, 2026 21:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[F] Soundness Kani failed to detect an issue Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants