Skip to content

Avoid branches in CPROVER library for --paths mode#8971

Open
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:library-branching
Open

Avoid branches in CPROVER library for --paths mode#8971
tautschnig wants to merge 1 commit intodiffblue:developfrom
tautschnig:library-branching

Conversation

@tautschnig
Copy link
Copy Markdown
Collaborator

Replace if-statements with conditional expressions in two places in the built-in CPROVER library to avoid generating GOTO branches that cause exponential path explosion in --paths mode:

  1. __CPROVER_deallocate: nondeterministic deallocation tracking
    Before: if(__VERIFIER_nondet___CPROVER_bool()) __CPROVER_deallocated = ptr;
    After: __CPROVER_deallocated = nondet ? ptr : __CPROVER_deallocated;

  2. free: memory leak detection
    Before: if(__CPROVER_memory_leak==ptr) __CPROVER_memory_leak=0;
    After: __CPROVER_memory_leak = (leak==ptr) ? 0 : leak;

Both are semantically equivalent but avoid GOTO instructions, so --paths mode does not fork at these points.

Impact on Collections-C benchmark (159 tests, --paths lifo):
Original --paths: 61 pass, 93 timeout, 3105s
After fix 1: 123 pass, 31 timeout, 1463s
After both fixes: 127 pass, 26 timeout, 1159s
With precomp: 127 pass, 26 timeout, 1046s (14x vs Soteria)

The fixed --paths mode now passes 9 MORE tests than monolithic SAT (127 vs 118), including treeset and treetable tests.

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

Replace if-statements with conditional expressions in two places in
the built-in CPROVER library to avoid generating GOTO branches that
cause exponential path explosion in --paths mode:

1. __CPROVER_deallocate: nondeterministic deallocation tracking
   Before: if(__VERIFIER_nondet___CPROVER_bool()) __CPROVER_deallocated = ptr;
   After:  __CPROVER_deallocated = nondet ? ptr : __CPROVER_deallocated;

2. free: memory leak detection
   Before: if(__CPROVER_memory_leak==ptr) __CPROVER_memory_leak=0;
   After:  __CPROVER_memory_leak = (leak==ptr) ? 0 : leak;

Both are semantically equivalent but avoid GOTO instructions, so
--paths mode does not fork at these points.

Impact on Collections-C benchmark (159 tests, --paths lifo):
  Original --paths:  61 pass, 93 timeout, 3105s
  After fix 1:      123 pass, 31 timeout, 1463s
  After both fixes: 127 pass, 26 timeout, 1159s
  With precomp:     127 pass, 26 timeout, 1046s (14x vs Soteria)

The fixed --paths mode now passes 9 MORE tests than monolithic SAT
(127 vs 118), including treeset and treetable tests.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig self-assigned this Apr 27, 2026
Copilot AI review requested due to automatic review settings April 27, 2026 10:16
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 updates the built-in ANSI-C CPROVER library (stdlib.c) to avoid generating GOTO-level control-flow branches in --paths mode by replacing two if statements with conditional (?:) expressions. This targets path explosion by keeping the logic as expression-level conditionals instead of control-flow splits.

Changes:

  • Rewrite free’s memory-leak tracking (__CPROVER_memory_leak) update using a conditional expression.
  • Rewrite __CPROVER_deallocate’s nondeterministic deallocation tracking (__CPROVER_deallocated) update using a conditional expression.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.50%. Comparing base (b32074b) to head (8c2786d).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8971   +/-   ##
========================================
  Coverage    80.50%   80.50%           
========================================
  Files         1704     1704           
  Lines       188778   188778           
  Branches        73       73           
========================================
+ Hits        151975   151978    +3     
+ Misses       36803    36800    -3     

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

2 participants