Skip to content

Fix flatten2bv abort on non-constant FPA float (#9101)#9102

Draft
kroening wants to merge 5 commits into
developfrom
kroening/issue-9101-knownbug-test
Draft

Fix flatten2bv abort on non-constant FPA float (#9101)#9102
kroening wants to merge 5 commits into
developfrom
kroening/issue-9101-knownbug-test

Conversation

@kroening

@kroening kroening commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Closes #9101

Problem

--smt2 --fpa --outfile aborts with an invariant violation (flatten2bv of a non-constant FPA-encoded float is unsupported) when the program reinterprets the bits of a non-constant float through a union — the classic union { float f; unsigned u; } idiom pervasive in bit-exact libm code. The native SAT backend solves the same program without issue.

Root cause

The union with_exprt handling in convert_expr (and convert_union) calls flatten2bv(value) directly on a float-typed value. Under FPA theory, flatten2bv only handled constant floats (emitting their IEEE-754 bit pattern as a literal BV). Non-constant floats need the bvfromfloat round-trip — declare a fresh BV variable and assert ((_ to_fp E S) bv) == float — but this was only wired up for explicit typecast_exprt(floatbv→bv) in find_symbols.

Fix

Extend the non-constant branch of flatten2bv to emit the same bvfromfloat round-trip inline, using defined_expressions with a synthetic typecast_exprt as cache key for deduplication (consistent with the existing find_symbols mechanism).

Testing

@kroening kroening changed the title Add KNOWNBUG regression test for #9101 Fix flatten2bv abort on non-constant FPA float (#9101) Jul 4, 2026
kroening added 2 commits July 4, 2026 12:38
The SMT2 export path aborts with an invariant violation when
flatten2bv encounters a non-constant FPA-encoded float (e.g. a
nondet float stored in a union and read back as unsigned).

Add a minimal reproducer that exercises this code path via the
classic union-based float-to-int type-punning idiom.  The test is
marked KNOWNBUG because the export currently aborts (SIGABRT)
instead of producing a complete SMT2 formula.
When flatten2bv encounters a non-constant floatbv expression under FPA
theory (e.g. a nondet float stored in a union), it now emits the same
bvfromfloat round-trip that find_symbols already uses for explicit
typecast(floatbv→bv): declare a fresh BV variable and assert that
((_ to_fp E S) bv) equals the float expression.

Previously this hit an UNEXPECTEDCASE invariant violation, aborting the
SMT2 export mid-write and leaving a truncated output file.

The regression test is promoted from KNOWNBUG to CORE.
@kroening kroening force-pushed the kroening/issue-9101-knownbug-test branch from 481d85e to 3693209 Compare July 4, 2026 19:38
kroening added 2 commits July 4, 2026 13:09
The test explicitly controls the output format (--smt2 --fpa --outfile -)
and must not be re-run with a different solver backend appended.  Add
broken-smt-backend and no-new-smt tags, matching the convention used by
other --outfile tests (e.g. array_of_bool_as_bitvec/test-smt2-outfile.desc).
Tests using --outfile - dump raw SMT2 to stdout, which is not valid XML.
Add the new test to the exclusion list in validate-trace-xml-schema/check.py,
matching the existing exclusions for array_of_bool_as_bitvec and others.
@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.79%. Comparing base (1e835df) to head (813ca98).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9102      +/-   ##
===========================================
+ Coverage    80.77%   80.79%   +0.01%     
===========================================
  Files         1712     1712              
  Lines       189814   189830      +16     
  Branches        73       73              
===========================================
+ Hits        153324   153364      +40     
+ Misses       36490    36466      -24     

☔ View full report in Codecov by Harness.
📢 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.

The bvfromfloat auxiliary (declare-fun + assert) must be emitted at the
SMT-LIB top level, not inline during expression conversion.  Move the
declaration logic into find_symbols, which runs before any expression
output.

find_symbols now pre-creates a bvfromfloat entry for every non-constant
floatbv-typed expression it visits under FPA theory.  flatten2bv then
simply looks up the existing entry by its defined_expressions key
(a synthetic typecast_exprt from floatbv to bv).
@kroening kroening marked this pull request as draft July 6, 2026 17:56
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.

--smt2 --outfile aborts (flatten2bv: unsupported) on float↔int type-punning that native solving handles

1 participant