Avoid branches in CPROVER library for --paths mode#8971
Open
tautschnig wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #8971 +/- ##
========================================
Coverage 80.55% 80.55%
========================================
Files 1707 1707
Lines 189051 189051
Branches 73 73
========================================
Hits 152299 152299
Misses 36752 36752 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Replace if-statements with conditional expressions in the built-in
CPROVER libraries to avoid generating GOTO branches that cause
exponential path explosion in --paths mode. Three places are touched:
1. __CPROVER_deallocate (src/ansi-c/library/stdlib.c)
nondeterministic deallocation tracking
Before: if(__VERIFIER_nondet___CPROVER_bool())
__CPROVER_deallocated = ptr;
After: __CPROVER_deallocated =
nondet ? ptr : __CPROVER_deallocated;
2. free (src/ansi-c/library/stdlib.c)
memory-leak detection
Before: if(__CPROVER_memory_leak == ptr) __CPROVER_memory_leak = 0;
After: __CPROVER_memory_leak =
(__CPROVER_memory_leak == ptr) ? 0 : __CPROVER_memory_leak;
3. __delete and __delete_array (src/cpp/library/new.c)
same memory-leak detection idiom as in `free`, mirrored on the
C++ delete / delete[] paths so the optimisation applies symmetrically
to C++ programs.
Each rewrite is annotated with a short comment explaining why the
seemingly-redundant self-assignment in the false branch is intentional,
so that a future reader does not "simplify" it back to an `if` and
silently undo the optimisation.
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.
Adds a CORE-tagged regression test
`regression/cbmc/path-branch-malloc-free` with --paths lifo over a
handful of independent malloc/free pairs. With this fix the test runs
in around 18s; without it the per-profile ctest timeout (1200s) is
exceeded, so reverting the optimisation is caught.
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
8c2786d to
0dc0f37
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
__CPROVER_deallocate: nondeterministic deallocation tracking
Before: if(__VERIFIER_nondet___CPROVER_bool()) __CPROVER_deallocated = ptr;
After: __CPROVER_deallocated = nondet ? ptr : __CPROVER_deallocated;
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.