Repository navigation
fix(analysis): keep uninitialized-read states compact on large functions - #286
Draft
SizzleUnrlsd wants to merge 2 commits into
Draft
SizzleUnrlsd wants to merge 2 commits into
SizzleUnrlsd wants to merge 2 commits into
Conversation
Every block of a function kept an in-state and an out-state holding one heap vector of byte ranges per tracked object, so the uninitialized-read analysis needed memory in proportion to blocks times objects, and a large function killed the whole run (#218). A state now keeps one bit per object for the two common range sets, empty and covering the whole object, and stores only the other ones, sorted by object. The meet intersects only the objects stored on either side and ANDs the bits. The encoding stays canonical, so states compare equal exactly when their range sets do, and every range set read through a state is the one the old state held: the diagnostics do not change. On the issue's generated function (macOS, Release), n = 2000 peaks at 80 MiB instead of 1142 MiB, and n = 8000, killed above 12 GB in the issue, peaks at 191 MiB with all 8000 reads reported.
… locals Regression for #218. In a function of 2000 locals, each written in one case of a first switch and read in one case of a second, every local must still get its UninitializedLocalRead, and the analyzer's peak memory, measured by os.wait4 on that process alone, must stay within 384 MiB. On macOS the check fails before the fix (685 to 694 MiB, every read still reported) and passes with it (67 to 68 MiB).
This was referenced Nov 18, 2026
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.
Fixes #218.
Problem
UninitializedLocalReadgave every reachable block an in-state and an out-state. Each was astd::vector<RangeSet>holding one heap-allocated range vector per tracked object, and a fullstate was built at each block visit. Memory grew with blocks × tracked objects. On the issue's
generated function, it reached 6.8 GB at n = 4000, and the run was killed above 12 GB at n = 8000.
Change
InitRangeStatebecomes a class insrc/analysis/UninitializedVarAnalysis.cpp:state[idx]returns the same range set as before: the object's full range (shared by everystate), the stored set, or an empty set.
for the others.
exactly when their range sets do, and the fixpoint runs the same iterations.
There is no heuristic and no size cutoff, so the reported diagnostics are meant to stay the same.
The second commit adds
check_uninitialized_large_function_memorytorun_test.py.Evidence
Everything below ran on one macOS arm64 machine (Apple clang 17, LLVM 20.1.2), with a Release
build. Each measurement is a single run.
Memory and time on the issue's generator
The generator writes
if (c == i) v_i = i;then reads withif (c > i) s += v_i;.UninitializedLocalReadstepAt n = 4000 and n = 8000, one
UninitializedLocalReadis reported per variable.Diagnostics
The diagnostics are unchanged on every input compared:
compared as multisets without their
id.test/: 523.c/.cc/.cpp/.llfiles, analyzed one at a timewith both binaries. Exit codes and diagnostics are identical, with 714 diagnostics on each side,
49 of them
UninitializedLocalRead. Three sources undertest/unit/produce no report witheither binary, because they do not compile on their own.
stack_usage_analyzer_unit_tests: passes.The new check
check_uninitialized_large_function_memoryanalyzes a function of 2000 locals. Each local iswritten in one
caseof a firstswitchand read in onecaseof a second. The check requirestwo things:
UninitializedLocalReadper local;os.wait4on that process alone,since other checks run in parallel.
It ran 8 times with each binary, both with and without the CI's
--compile-ir-cache-dir:Full suite
The full suite ran with the CI's configuration:
run_test.py --jobs=8 --analyzer-timeout=120, where--jobsismin(8, CPUs)as in the CI;CORETRACE_RUN_TEST_EXTRA_ANALYZER_ARGS=--compile-ir-cache-dir=.cache/compile-ir;All 2917 tests passed (2917/2917) in 51 s, the new check included (65 MiB).
Limits
noise. The memory figures are peak RSS (
ru_maxrss).Its failing side, though, was shown on macOS only: the peak before the fix was not measured
on Linux, where
ru_maxrsscounts in KiB and the allocator differs.The local build used Apple clang 17.
generator only, not on external code bases.
It catches a regression the size of UninitializedLocalRead memory grows with blocks times locals and kills the run on large functions #218, not a small growth.
analyses, which this PR does not address. At n = 8000, the integer-overflow analysis took 147 s
and the duplicate-if-condition analysis 34 s.
CI results
The CI ran on
fdaca3c(Build run).All 14 checks pass. "Attach binaries to GitHub Release" is skipped, because it only runs for
tags.
run_test.pypasses 2917/2917 on each build job, and the new check reports all 2000 reads:run_test.pyjobs--fail-on error): passes, and the SARIF upload succeeds.UninitializedVarAnalysis.cpp(
Recursion.Detected, Info) were already open onmain.format-check,license-complianceandCheck conventional commits;Concurrency analysis;Test Consumer Project,Test Docker ImageandTest GitHub Action.