Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
dacaf41
build(deps): pin coretrace-compiler to its per-compilation working di…
SizzleUnrlsd Nov 12, 2026
f56e979
perf(input): compile sources in parallel, each in its directory
SizzleUnrlsd Nov 12, 2026
dd3ba41
docs(readme): say that --jobs compiles the sources in parallel
SizzleUnrlsd Nov 12, 2026
d642039
docs(changelog): announce that sources compile in parallel
SizzleUnrlsd Nov 12, 2026
e6ae53e
build(deps): pin coretrace-compiler to its fix of the files -MJ writes
SizzleUnrlsd Nov 12, 2026
18d032f
fix(input): bring the process back after a compilation that moves it
SizzleUnrlsd Nov 16, 2026
bbaab08
test(unit): check that a load leaves the process in its directory
SizzleUnrlsd Nov 16, 2026
1e0ffa3
Merge branch 'main' into perf/parallel-compilation
SizzleUnrlsd Nov 24, 2026
7a50b51
build(deps): update coretrace-compiler to v0.13.0
SizzleUnrlsd Nov 24, 2026
1735f86
perf(app): load the inputs at once, on two workers or min(N, 4) with …
SizzleUnrlsd Nov 24, 2026
7199bd4
perf(app): give back to the system the memory that the loading freed
SizzleUnrlsd Nov 24, 2026
b8ec354
test(app): check how many inputs load at once, by --jobs
SizzleUnrlsd Nov 24, 2026
bbdbf8a
test(input): compare the reports of an empty and a filled compile IR …
SizzleUnrlsd Nov 24, 2026
6af8a1a
docs(help): say on how many workers --jobs loads the inputs
SizzleUnrlsd Nov 24, 2026
3f9717a
docs(readme): say that --jobs loads the inputs in parallel, on bounde…
SizzleUnrlsd Nov 24, 2026
460529b
docs(changelog): describe the bounded loading and the compiler's update
SizzleUnrlsd Nov 24, 2026
3445f89
test(app): check the loading bound without the cross-TU summaries
SizzleUnrlsd Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ Notable changes are grouped by release. See [all releases](https://github.com/Co
- Added an authors file and linked the repository documents from the README.
- SARIF rules carry a title (`shortDescription`) and a description (`fullDescription`) instead
of their id, and `describeRule` (`RuleCatalog.hpp`) gives them to programs linking the analyzer.
- In a multi-file run, the inputs load at once and their sources compile in parallel: on at
most two workers when `--jobs` is left to the machine (the default, or `--jobs=auto`), and on
`min(N, 4)` with `--jobs=N`, as each compilation in progress holds its own memory. The other
phases use `--jobs` as before. Each compilation runs in its compile command's directory through
coretrace-compiler's `-working-directory`, instead of moving the whole process there under a
lock that let one source compile at a time. Compilations that pass `-mllvm`, `-mdebug-pass`,
`-mlimit-float-precision`, `-ftime-report` or `-fno-integrated-cc1` still run one at a time.
Under glibc, the memory the compilations freed is given back to the system once the inputs are
loaded. coretrace-compiler is updated to v0.13.0, which gives each compilation a working
directory of its own.

## v0.22.0

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Ready-to-adapt workflow examples:
--compdb=<path> alias for --compile-commands
--compdb-fast drops heavy build flags for faster analysis
--include-compdb-deps includes `_deps` entries when inputs are auto-discovered from compile_commands.json
--jobs=<N|auto> parallel jobs for the cross-TU summaries of multi-file runs (default: auto)
--jobs=<N|auto> parallel jobs of multi-file runs: N for the cross-TU summaries, min(N, 4) to load the inputs, or 2 with auto (default: auto)
--escape-model=<path> loads external noescape rules for stack pointer escape analysis (`noescape_arg`)
--buffer-model=<path> loads external buffer write rules for copy/string overflow checks (`bounded_write`/`unbounded_write`)
--resource-model=<path> loads external acquire/release rules for generic resource lifetime checks
Expand Down Expand Up @@ -295,7 +295,9 @@ To generate `compile_commands.json` with CMake, configure with

If analysis feels slow, `--compdb-fast` disables heavy flags (optimizations,
sanitizers, profiling) while keeping include paths and macros.
For multi-file runs, `--jobs=<N|auto>` parallelizes the construction of cross-TU summaries; the inputs are loaded one at a time.
For multi-file runs, `--jobs=<N|auto>` parallelizes the construction of cross-TU summaries and the loading of the inputs, compilations included.
Each compilation in progress holds its own memory, so the loading is bounded apart from the summaries:
it takes `min(N, 4)` workers with `--jobs=N`, and 2 with `auto`, the default.
`--compile-ir-cache-dir=<path>` reuses compiled LLVM IR for unchanged translation units
based on source/dependency stamps, which reduces repeated C/C++ frontend cost across runs.
IR that another compiler produced (another coretrace-compiler revision or LLVM version) is compiled again.
Expand Down Expand Up @@ -574,7 +576,7 @@ Cross-TU summary behavior:
- `--no-resource-cross-tu` forces local-only (single-file) resource reasoning.
- `--resource-summary-cache-dir=<path>` controls where per-module summary cache files are stored.
- `--resource-summary-cache-memory-only` disables filesystem cache writes and uses an in-process cache only.
- `--jobs=<N>` parallelizes per-module summary extraction during each fixpoint iteration; modules are loaded one at a time.
- `--jobs=<N>` parallelizes per-module summary extraction during each fixpoint iteration; modules are loaded on `min(N, 4)` workers, or on 2 with `--jobs=auto`.
- The CLI prints an explicit status line to `stderr` to indicate whether resource inter-procedural
analysis is enabled or unavailable/disabled (with reason).
- If a local release depends on an unmodeled/external callee and no summary is available, the tool
Expand Down
2 changes: 1 addition & 1 deletion cmake/compiler/coretrace-compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ endif()
FetchContent_Declare(
cc
GIT_REPOSITORY https://github.com/CoreTrace/coretrace-compiler.git
GIT_TAG b4ad33638e9020a93f052a7a299e4105bd48f975 # v0.10.0
GIT_TAG e21305389a2e639460b2bf619b3a800c15c94fe1 # v0.13.0
)
FetchContent_MakeAvailable(cc)

Expand Down
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ static void printHelp()
<< " --compdb-fast Speed up compdb builds (drops heavy flags)\n"
<< " --include-compdb-deps Include _deps entries when auto-discovering files from "
"compile_commands.json\n"
<< " --jobs=<N|auto> Parallel jobs for the cross-TU summaries of multi-file runs "
"(default: auto)\n"
<< " --jobs=<N|auto> Parallel jobs of multi-file runs: N for the cross-TU "
"summaries, min(N, 4) to load the inputs, or 2 with auto (default: auto)\n"
<< " If no input files are provided, supported files are loaded\n"
<< " from compile_commands.json automatically.\n"
<< " --timing Print compilation/analysis timing to stderr\n"
Expand Down
138 changes: 138 additions & 0 deletions run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1744,6 +1744,142 @@ def run_and_capture(fmt: str) -> tuple[bool, str]:
return ok


def _write_loading_sources(root: Path, count: int = 12) -> list[Path]:
"""
Write `count` C files for the checks of the loading. Each one reads a global of its own before
any write, which the analyzer reports, calls the next one, and includes three standard
headers, so that its compilation lasts long enough to overlap the others'.
"""
sources = []
for index in range(count):
callee = f"unit_{index + 1:02d}" if index + 1 < count else None
source = root / f"unit_{index:02d}.c"
source.write_text(
"#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n"
f"int table_{index:02d}[4];\n"
+ (f"int {callee}(int i);\n" if callee else "")
+ f"int unit_{index:02d}(int i)\n{{\n int s = 0;\n s += table_{index:02d}[i & 3];\n"
+ (f" return s + {callee}(i);\n" if callee else " return s;\n")
+ "}\n"
)
sources.append(source)
return sources


def _most_loads_at_once(timing_log: str) -> int:
"""
The most inputs loading at once, from the log of --timing: an input logs `Compiling` when its
load starts, and `Bitcode parse done in` once its module is there.
"""
in_flight = most = 0
for line in timing_log.splitlines():
if "Compiling " in line:
in_flight += 1
most = max(most, in_flight)
elif "Bitcode parse done in" in line:
in_flight -= 1
return most


def check_loading_jobs() -> bool:
"""
The inputs of a multi-file run load at once, their sources compiling in parallel, on fewer
workers than --jobs allows, as each compilation in progress holds its own memory: two when
the count is left to the machine (no --jobs, or --jobs=auto), and min(N, 4) with --jobs=N.
The bound holds without the cross-TU summaries that the options can turn off: every
multi-file run loads its inputs that way.
"""
print("=== Testing how many inputs load at once ===")
automatic = min(2, os.cpu_count() or 1)
ok = True
with tempfile.TemporaryDirectory(prefix="ct_loading_jobs_") as tmp:
root = Path(tmp)
sources = _write_loading_sources(root)
analyzer = str(Path(RUN_CONFIG.analyzer).resolve())
for jobs, expected in (
([], automatic),
(["--jobs=auto"], automatic),
(["--jobs=1"], 1),
(["--jobs=2"], 2),
(["--jobs=3"], 3),
(["--jobs=4"], 4),
(["--jobs=8"], 4),
(["--jobs=8", "--no-resource-cross-tu", "--no-uninitialized-cross-tu"], 4),
):
label = " ".join(jobs) if jobs else "no --jobs"
try:
result = subprocess.run([analyzer, "--timing", *jobs, *map(str, sources)], cwd=root,
capture_output=True, text=True,
timeout=RUN_CONFIG.analyzer_timeout)
except subprocess.TimeoutExpired:
ok = fail_check(f"{label}: the analyzer timed out")
continue
started = result.stderr.count("Compiling ")
loaded = result.stderr.count("Bitcode parse done in")
if result.returncode != 0 or (started, loaded) != (len(sources), len(sources)):
ok = fail_check(f"{label}: exit code {result.returncode}, {started} loads started and "
f"{loaded} done for {len(sources)} inputs", result.stderr)
continue
most = _most_loads_at_once(result.stderr)
if most != expected:
ok = fail_check(f"{label}: {most} at once, expected {expected}")
continue
print(f" ✅ {label}: {most} at once")
print()
return ok


def check_reports_of_an_empty_and_a_filled_compile_ir_cache() -> bool:
"""
A multi-file run gives the diagnostics and the functions of a run that loads its inputs one
at a time without a cache, when its inputs load at once from an empty compile IR cache, which
they fill together, and when they load from the cache they filled.
"""
print("=== Testing the reports of an empty and a filled compile IR cache ===")
ok = True
with tempfile.TemporaryDirectory(prefix="ct_loading_cache_") as tmp:
root = Path(tmp)
sources = _write_loading_sources(root)
analyzer = str(Path(RUN_CONFIG.analyzer).resolve())

def run(*args):
try:
result = subprocess.run(
[analyzer, "--timing", "--format=json", *args, *map(str, sources)], cwd=root,
capture_output=True, text=True, timeout=RUN_CONFIG.analyzer_timeout)
payload = json.loads(result.stdout)
except (subprocess.TimeoutExpired, json.JSONDecodeError):
return None, 0
# A diagnostic's id follows its place in the report, which is not compared.
report = (
sorted(json.dumps({key: value for key, value in d.items() if key != "id"}, sort_keys=True)
for d in payload.get("diagnostics", [])),
sorted(json.dumps(f, sort_keys=True) for f in payload.get("functions", [])),
)
return report, result.stderr.count("Compilation cache hit for")

reference, _ = run("--jobs=1")
if reference is None or not all(reference):
print(" ❌ no diagnostics or no functions without a cache, at --jobs=1")
print()
return False
for index, jobs in enumerate(([], ["--jobs=4"])):
label = jobs[0] if jobs else "no --jobs"
cache = f"--compile-ir-cache-dir={root / f'compile-ir-{index}'}"
for state, expected_hits in (("an empty cache", 0), ("the cache it filled", len(sources))):
report, hits = run(*jobs, cache)
if report == reference and hits == expected_hits:
print(f" ✅ {label}, {state}: the report of a run without a cache, "
f"{hits} of {len(sources)} inputs read from the cache")
else:
ok = False
print(f" ❌ {label}, {state}: the report of a run without a cache: "
f"{report == reference}; {hits} inputs read from the cache, "
f"expected {expected_hits}")
print()
return ok


def check_pipeline_subscriber_rollout_parity() -> bool:
"""
Integration check: diagnostics must remain stable when toggling the
Expand Down Expand Up @@ -5978,6 +6114,8 @@ def record_ok(ok: bool):
check_unresolved_call_max_stack,
check_cycle_max_stack,
check_compile_ir_format_switch,
check_loading_jobs,
check_reports_of_an_empty_and_a_filled_compile_ir_cache,
check_pipeline_subscriber_rollout_parity,
check_pipeline_timing_traversal_instrumentation,
check_only_func_uninitialized,
Expand Down
Loading
Loading