Skip to content

Math library models: add missing *BSD variants, cleanup#9020

Draft
tautschnig wants to merge 2 commits into
diffblue:developfrom
tautschnig:math-builtins-cleanup
Draft

Math library models: add missing *BSD variants, cleanup#9020
tautschnig wants to merge 2 commits into
diffblue:developfrom
tautschnig:math-builtins-cleanup

Conversation

@tautschnig
Copy link
Copy Markdown
Collaborator

BSD systems appear to use __ prefixed variants of several functions. Define these as needed. Also, avoid handling some GCC-style __builtin_-prefixed functions via models when others are done directly in the type checker: do all of them in the type checker.

In addition to __builtin_isfinite, recognise its older glibc internal aliases __builtin_finite, __builtin_finitef and __builtin_finitel in the same isfinite_exprt branch of the type checker. Some glibc <bits/mathcalls-helper-functions.h> headers expose the legacy finite() API via these builtins, and without recognition CBMC would otherwise treat them as body-less functions returning nondet.

  • 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.

BSD systems appear to use `__` prefixed variants of several functions.
Define these as needed. Also, avoid handling some GCC-style
`__builtin_`-prefixed functions via models when others are done directly
in the type checker: do all of them in the type checker.

In addition to `__builtin_isfinite`, recognise its older glibc
internal aliases `__builtin_finite`, `__builtin_finitef` and
`__builtin_finitel` in the same isfinite_exprt branch of the type
checker.  Some glibc `<bits/mathcalls-helper-functions.h>` headers
expose the legacy `finite()` API via these builtins, and without
recognition CBMC would otherwise treat them as body-less functions
returning nondet.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig self-assigned this May 28, 2026
Copilot AI review requested due to automatic review settings May 28, 2026 11:32
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

Adds BSD-style __-prefixed math library models (e.g., __isfinite, __isnand, __isnormal, __signbitl, __isfinitef/l), moves several GCC __builtin_* functions (fabs variants, isnan/isinf/finite variants) from library models into the C type checker for consistent direct handling, and replaces internal uses of __builtin_inf* in math.c with __CPROVER_inf*. Updates library_check.sh to filter the newly added/relocated symbols, and replaces the old KNOWNBUG placeholder tests with real assertion-based regression tests.

Changes:

  • Add BSD __-prefixed math library function models and remove __builtin_fabs[fl] models now handled in the type checker.
  • Extend c_typecheck_expr to recognize __builtin_fabs[fl], __builtin_isnan[fl], __builtin_isinf[fl], __builtin_isfinite, __builtin_finite[fl] directly.
  • Replace KNOWNBUG regression stubs with real assertion-based tests for isfinite/isinf/isnormal/signbit/fpclassify and their __/__builtin_ variants; update library_check.sh filters accordingly.

Reviewed changes

Copilot reviewed 42 out of 42 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/ansi-c/library/math.c Remove __builtin_fabs* models, add BSD __isfinite*/__isnand/__isnormal*/__signbitl, replace __builtin_inf* calls with __CPROVER_inf*.
src/ansi-c/c_typecheck_expr.cpp Extend special-function handling for __builtin_fabs/isnan/isinf/isfinite/finite variants.
src/ansi-c/library_check.sh Filter additional __-prefixed and is*[fl] symbols added in models.
regression/cbmc-library/isfinite/{main.c,test.desc} Replace KNOWNBUG stub with real isfinite assertions; promote to CORE.
regression/cbmc-library/isnormal/{main.c,test.desc} Replace stub with __builtin_isnormal static-assert test; promote to CORE.
regression/cbmc-library/isinf/main.c Add __builtin_isinf / __builtin_isinf_sign runtime and static assertions.
regression/cbmc-library/signbit/main.c Add real signbit assertions for double and long double.
regression/cbmc-library/__fpclassify/main.c Add fpclassify and __builtin_fpclassify runtime and static assertions.
regression/cbmc-library/{__isinf,__isinff,__isinfl,__isnan,__isnanf,__isnanl,__isnormalf,__signbit,__signbitf,__builtin_fabs,__builtin_fabsf,__builtin_fabsl,isinff,isinfl,isnanf,isnanl}/* Delete obsolete KNOWNBUG placeholder tests now covered by typechecker handling and library_check filters.

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

perl -p -i -e 's/^__isnan[dfl]?\n//' __functions # isnan
perl -p -i -e 's/^__isnormal[fl]?\n//' __functions # isnormal
perl -p -i -e 's/^__printf_chk\n//' __functions # printf/__printf_chk.desc
perl -p -i -e 's/^__signbit[fl]?\n//' __functions # signbit, __signbitd
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.59%. Comparing base (cbdcf13) to head (b165f10).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9020      +/-   ##
===========================================
- Coverage    80.60%   80.59%   -0.01%     
===========================================
  Files         1711     1711              
  Lines       189454   189460       +6     
  Branches        73       73              
===========================================
- Hits        152712   152699      -13     
- Misses       36742    36761      +19     

☔ 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.

…ifacts

Temporary CI configuration to investigate the x86_64 long double layout
issue surfaced by signbit on macOS 15 Intel.  All other PR-triggered
workflows are switched to workflow_dispatch only.  pull-request-checks.yaml
now has only two jobs:

  * debug-macos-15-intel: builds cbmc with Make, then collects the SDK
    deployment macros, the native byte representation of long double on
    real hardware, the preprocessed signbit/main.c, the cbmc trace and
    show-goto-functions output, plus a manual-union repro that prints
    the bytes CBMC stores for -1.0L.

  * debug-macos-14-arm: same diagnostic collection, control case where
    long double == double and the test passes.

The full original workflow is preserved at
.github/workflows/pull-request-checks.yaml.full and will be restored
once the underlying long double bug is fixed.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig marked this pull request as draft May 29, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants