Skip to content

Float constant propagation must observe rounding modes#8772

Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:fix-350-float-constant-prop
Open

Float constant propagation must observe rounding modes#8772
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:fix-350-float-constant-prop

Conversation

@tautschnig
Copy link
Collaborator

Detect assignments to __CPROVER_rounding_mode and invalidate all floating-point constants in the value map. This ensures soundness by preventing the reuse of constants computed with a different rounding mode, at the cost of potentially missing some optimization opportunities.

Fixes: #350

  • 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.
  • 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 Feb 24, 2026
Detect assignments to `__CPROVER_rounding_mode` and invalidate all
floating-point constants in the value map. This ensures soundness by
preventing the reuse of constants computed with a different rounding
mode, at the cost of potentially missing some optimization
opportunities.

Fixes: diffblue#350
@tautschnig tautschnig force-pushed the fix-350-float-constant-prop branch from c3dd308 to 9ca26bf Compare March 18, 2026 14:16
@tautschnig tautschnig marked this pull request as ready for review March 18, 2026 14:16
Copilot AI review requested due to automatic review settings March 18, 2026 14:16
Copy link

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 addresses unsound float constant propagation when __CPROVER_rounding_mode changes by invalidating cached floating-point constants on rounding-mode assignments, and updates/extends regression and unit tests accordingly.

Changes:

  • Detect assignments to __CPROVER_rounding_mode in constant propagation and clear cached float constants.
  • Add a unit test covering rounding-mode changes and their impact on propagated float constants.
  • Add/adjust regression tests to reflect the more conservative (sounder) behavior.

Reviewed changes

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

Show a summary per file
File Description
src/analyses/constant_propagator.cpp Invalidate cached float constants on rounding-mode assignment; add invalidation helper.
src/analyses/constant_propagator.h Declare invalidate_floatbv_constants on the domain value store.
unit/analyses/constant_propagator.cpp Add unit test scenario for rounding-mode changes affecting float constant propagation.
regression/goto-instrument/constant_propagation_float_rounding_unsound/test.desc New regression test driver for the previously-unsound case.
regression/goto-instrument/constant_propagation_float_rounding_unsound/main.c New regression test program exercising rounding-mode change around float division.
regression/goto-analyzer/constant_propagation_rounding_mode/test.desc Update expected outcomes (one assertion becomes UNKNOWN).
regression/goto-analyzer/constant_propagation_nondet_rounding_mode/test.desc Update expected outcomes (more conservative UNKNOWN results).

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


// Remove any variable with floating-point type, as its value
// may have been computed with a different rounding mode
if(symbol.type.id() == ID_floatbv)
Comment on lines +414 to +423
THEN(
"The propagator should NOT have f1 as a constant, because "
"the rounding mode changed")
{
const auto &final_domain = constant_propagator[test_instruction];

// f1 should not be constant at this point because the rounding
// mode changed after it was computed
REQUIRE_FALSE(
final_domain.values.is_constant(local_f1.symbol_expr(), ns));
@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.42%. Comparing base (85c204f) to head (9ca26bf).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8772   +/-   ##
========================================
  Coverage    80.41%   80.42%           
========================================
  Files         1703     1703           
  Lines       188398   188462   +64     
  Branches        73       73           
========================================
+ Hits        151498   151563   +65     
+ Misses       36900    36899    -1     

☔ 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Float constant propagation is unsound

2 participants