Skip to content

Improve exp.single-threaded for analysis without threadflag and escape#1981

Open
sim642 wants to merge 13 commits intomasterfrom
no-threadflag
Open

Improve exp.single-threaded for analysis without threadflag and escape#1981
sim642 wants to merge 13 commits intomasterfrom
no-threadflag

Conversation

@sim642
Copy link
Copy Markdown
Member

@sim642 sim642 commented Apr 8, 2026

So far, exp.single-threaded only prevented new threads from being spawned but did not override multi-threadedness related queries.
Now, using the queries through the corresponding helper functions, the option has stronger effect.

In particular, this allows analyzing a single-threaded program without the threadflag and escape analyses enabled, without immediately becoming flow-insensitive for globals (like exp.earlyglobs) and assuming all locals may have escaped (and become globals).

There is a performance benefit for having less analyses activated, even if they don't compute anything for single-threaded programs.
This is also what motivated the single-threaded autotuner for SV-COMP. This PR would allow pushing that autotuner even further to disable threadflag and escape analyses for such programs.

@sim642 sim642 added this to the v2.8.0 Clumsy Clurichaun milestone Apr 8, 2026
Copilot AI review requested due to automatic review settings April 8, 2026 08:43
Copy link
Copy Markdown
Contributor

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 strengthens the effect of exp.single-threaded by routing multi-threadedness and escape-related decisions through centralized helper functions, allowing more precise analysis of single-threaded programs even when threadflag, threadid, or escape analyses are disabled.

Changes:

  • Add regression tests covering exp.single-threaded behavior when escape / threadflag (and threadid) are deactivated.
  • Introduce/extend helper-based semantics for MayEscape and MustBeSingleThreaded queries via ThreadEscape.has_escaped and ThreadFlag.{is_currently_multi,has_ever_been_multi}.
  • Update multiple analyses to use these helpers instead of directly querying Queries.MayEscape / Queries.MustBeSingleThreaded.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/regression/00-sanity/42-no-threadflag.t New cram test for single-threaded mode with threadflag/threadid deactivated (and earlyglobs toggled).
tests/regression/00-sanity/42-no-threadflag.c C input for the above test (simple global flow-sensitivity expectation).
tests/regression/00-sanity/43-no-escape.t New cram test for single-threaded mode with escape deactivated (with earlyglobs enabled).
tests/regression/00-sanity/43-no-escape.c C input for the above test (address-taken local should remain non-escaped under forced single-threaded mode).
src/domains/queries.ml Document intended access paths for MayEscape / MustBeSingleThreaded via helper functions.
src/analyses/threadFlag.ml Make helper functions respect exp.single-threaded by forcing “not multi-threaded”.
src/analyses/threadEscape.ml Make ThreadEscape.has_escaped return false under exp.single-threaded.
src/analyses/singleThreadedLifter.ml Use ThreadFlag.has_ever_been_multi for multithreaded detection.
src/analyses/raceAnalysis.ml Use ThreadEscape.has_escaped for “treat as global/escaped” decision.
src/analyses/mutexAnalysis.ml Use ThreadEscape.has_escaped for “treat as global/escaped” decision.
src/analyses/wrapperFunctionAnalysis.ml Use ThreadFlag.has_ever_been_multi instead of direct MustBeSingleThreaded query.
src/analyses/varEq.ml Use ThreadFlag.has_ever_been_multi instead of direct MustBeSingleThreaded query.
src/analyses/useAfterFree.ml Use ThreadFlag.has_ever_been_multi for multi-threaded warning gating.
src/analyses/memLeak.ml Use ThreadFlag helpers for multi-threadedness checks and simplify prior helper.
src/analyses/basePriv.ml Use ThreadFlag helpers to detect “recovered to single-threaded” state.
src/analyses/apron/relationPriv.apron.ml Use ThreadFlag.has_ever_been_multi for branched sync decisions.
src/analyses/mCP.ml Add TODOs around exp.single-threaded spawn suppression message behavior.

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

sim642 added 3 commits April 8, 2026 11:53
Due to 7b2a223, locals which have vaddrof false are not longer queried at all by mutex/race analysis.
1. Don't output final message if no thread creations are even attempted by the program.
2. Output non-final message for each suppressed thread.
@michael-schwarz michael-schwarz self-requested a review April 9, 2026 04:41
@sim642
Copy link
Copy Markdown
Member Author

sim642 commented Apr 9, 2026

In my rsync runs (goblint/bench@58495e9), something strange happens with this change. When deactivating threadflag and escape in favor of exp.single-threaded the runtime increases from 2h 30min to 11h 13min. The number of vars slightly decreases and the number of evals more than doubles.

I thought that maybe the GobConfig.get_bool is causing an overhead because these are probably called very often (probably every access to a global at least), and should be cached into a ref. But that inefficiency wouldn't increase evals, so something else must be happening as well.

@sim642
Copy link
Copy Markdown
Member Author

sim642 commented Apr 9, 2026

In my rsync runs (goblint/bench@58495e9), something strange happens with this change. When deactivating threadflag and escape in favor of exp.single-threaded the runtime increases from 2h 30min to 11h 13min. The number of vars slightly decreases and the number of evals more than doubles.

Apparently our rsync-v3.4.1-gcc-nosignal.i still has some signal handlers left and still was making the analysis multi-threaded. The error improvements for "Thread not spawned" in this PR already paid off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants