Skip to content

Align floating-point predicates across float_utilst and float_bvt#8988

Open
tautschnig wants to merge 3 commits into
diffblue:developfrom
tautschnig:float-predicates
Open

Align floating-point predicates across float_utilst and float_bvt#8988
tautschnig wants to merge 3 commits into
diffblue:developfrom
tautschnig:float-predicates

Conversation

@tautschnig
Copy link
Copy Markdown
Collaborator

@tautschnig tautschnig commented Apr 28, 2026

Depends-on: #9020

  • Add float_utilst::is_finite and use it (float_bvt already has is_finite).
  • Remove unused float_utilst::is_plus_inf, float_utilst::is_minus_inf (float_bvt does not have these either).

Tests targeting predicates continue to pass.

  • Each commit message has a non-empty body, explaining why the change was made.
  • 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.

@tautschnig tautschnig self-assigned this Apr 28, 2026
Copilot AI review requested due to automatic review settings April 28, 2026 12:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns floating-point classification predicates between float_utilst and other float encodings by introducing a shared is_finite helper, simplifying predicate conversion, and adding regressions to cover the updated behavior (bitvector and SMT paths).

Changes:

  • Add float_utilst::is_finite and remove unused is_plus_inf / is_minus_inf.
  • Simplify ID_isfinite conversion in boolbvt to use the new helper.
  • Add new regressions for isfinite and isinf (floatbv and SMT/Z3 paths).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/solvers/floatbv/float_utils.h Removes unused infinity-sign helpers; declares new is_finite predicate.
src/solvers/floatbv/float_utils.cpp Implements float_utilst::is_finite and deletes unused helpers.
src/solvers/flattening/boolbv.cpp Refactors ID_isfinite conversion to call float_utilst::is_finite.
regression/cbmc/Float-predicates/test.desc Adds floatbv regression for classification predicates.
regression/cbmc/Float-predicates/test_smt.desc Adds SMT/Z3 regression for classification predicates.
regression/cbmc/Float-predicates/main.c Test program exercising isfinite and isinf (with sign checks).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,10 @@
CORE no-new-smt
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

This test runs CBMC with --smt2 --z3 but isn't labeled smt-backend. In regression/cbmc/CMakeLists.txt, the default regression profile excludes tests with the smt-backend label, so without it this test may run unexpectedly in default CI (and require Z3). Add smt-backend to the label line (e.g., CORE smt-backend no-new-smt).

Suggested change
CORE no-new-smt
CORE smt-backend no-new-smt

Copilot uses AI. Check for mistakes.
Comment thread src/solvers/flattening/boolbv.cpp Outdated
!float_utils.is_NaN(bv));
return float_utils.is_finite(bv);
}
else if(op.id() == ID_fixedbv)
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The fixedbv fast-path is checking op.id() == ID_fixedbv, but ID_fixedbv is a type id (and the surrounding isnan/isinf/isnormal branches use op.type().id()). As written, this branch will never match and ID_isfinite on fixedbv will fall through to SUB::convert_rest, likely producing an unexpected result or conversion failure. Use op.type().id() == ID_fixedbv here for consistency with the other predicates.

Suggested change
else if(op.id() == ID_fixedbv)
else if(op.type().id() == ID_fixedbv)

Copilot uses AI. Check for mistakes.
tautschnig and others added 3 commits May 28, 2026 00:01
GCC's <math.h> macros expand isfinite(x) to __builtin_isfinite(x),
yet c_typecheck_expr.cpp only recognised the __CPROVER_-prefixed
helpers (__CPROVER_isfinite{f,d,ld}).  As a result, on glibc systems
where isfinite() goes through __builtin_isfinite, CBMC failed to
lower the call to an isfinite_exprt and instead treated the call as
a body-less function.  Symptoms include a 'no body for callee
__builtin_isfinite' warning and havocked nondet results that make
assert(isfinite(...)) fail.

Aligns with the existing handling of __builtin_isnan,
__builtin_isinf, __builtin_isinf_sign, and __builtin_isnormal.

Add the missing identifiers to the isfinite_exprt branch of
c_typecheck_expr.cpp:
  __builtin_isfinite       (modern variant)
  __builtin_finite         (older glibc internal alias)
  __builtin_finitef        (float variant)
  __builtin_finitel        (long double variant)

Also add fallback library bodies in library/math.c so that indirect
calls (function pointers etc.) resolve correctly, mirroring the
existing __builtin_isnan{,f} entries.

Stub regression/cbmc-library/ test directories accompany each new
library entry, as required by library_check.sh.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
The ID_isfinite branch in boolbvt::convert_rest tested
'op.id() == ID_fixedbv', but ID_fixedbv is a *type* id and op is the
operand expression, not a type.  The dead branch never matched and
fixedbv operands fell through to SUB::convert_rest, which is not
prepared to lower an isfinite expression and would yield an
unexpected result or conversion failure.

The neighbouring ID_isnan, ID_isinf, and ID_isnormal branches all
correctly use 'op.type().id() == ID_fixedbv'.  Bring ID_isfinite
into line.

Pre-existing typo, unrelated to the surrounding refactoring; fixed
here because it sits in the immediate neighbourhood of changes to
the floatbv branch and to keep the fixedbv handling consistent.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
- Add float_utilst::is_finite and use it (float_bvt already has
  is_finite).
- Remove unused float_utilst::is_plus_inf, float_utilst::is_minus_inf
  (float_bvt does not have these either).
- Switch the ID_isfinite floatbv branch in boolbvt::convert_rest to
  the new helper.

Add a regression/cbmc/Float-predicates test exercising isfinite and
isinf via <math.h> against both the default SAT and the SMT (Z3)
backends.  Tagging the SMT test with smt-backend keeps it out of
the default and paths-lifo profiles, matching the convention used
by other tests that hard-code --smt2 --z3.

Tests targeting predicates continue to pass.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.60%. Comparing base (cbdcf13) to head (f1cae3d).

Files with missing lines Patch % Lines
src/solvers/flattening/boolbv.cpp 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8988   +/-   ##
========================================
  Coverage    80.60%   80.60%           
========================================
  Files         1711     1711           
  Lines       189454   189445    -9     
  Branches        73       73           
========================================
- Hits        152712   152705    -7     
+ Misses       36742    36740    -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.

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.

2 participants