Repository navigation
Analyzer Modules Architecture
Hugo edited this page Sep 25, 2026
·
2 revisions
This page describes the module split around StackUsageAnalyzer that keeps orchestration concerns separate from pass logic and reporting.
- Reduce coupling between CLI/app orchestration and LLVM analysis details.
- Keep module responsibilities narrow and independently testable.
- Preserve existing behavior while improving maintainability.
Role:
- Coordinator for module-level analysis execution.
- Orders preparation, pass execution, and diagnostic emission.
Pattern:
- Facade over lower-level analyzer services.
Role:
- Builds prepared module context (
PreparedModule). - Computes stack metadata, filtered call graph, and recursion state.
Pattern:
- Application service with deterministic derivation logic.
Role:
- Resolves source file/line/column from LLVM debug metadata.
- Provides fallback logic for
alloca/debug intrinsics.
Pattern:
- Stateless domain service.
Role:
- Converts analysis findings to final
Diagnosticobjects. - Centralizes severity, rule IDs, message formatting, and CWE enrichment.
Pattern:
- Adapter between analysis-domain findings and report-domain output.
Role:
- Classifies findings in statically unreachable code paths.
Pattern:
- Isolated policy module.
These came with the shared-analysis-infrastructure work. They exist so several checks stop walking the same IR independently.
Role:
- The subscriber interface: a module registers interest in instruction kinds
(
AllocaInst,CallInst, …) and is called during one traversal. -
InstructionSubscriberRegistrydispatches to every registered subscriber.
Pattern:
- Observer over a single IR walk, replacing one walk per check.
Role:
- Collects
IRFactsfor a module in that single traversal, from the registered subscribers.
Role:
- A subscriber that keeps
PerFunctionData— the per-function instruction groupings the checks ask for repeatedly.
Role:
- Indexes derived once per module and reused:
DebugMetadataIndex,FunctionSymbolIndex,TypeFactIndex.
Role:
- Holds the derived artifacts for the run, so a later stage takes them instead of recomputing.
Role:
-
HotspotSample,HotspotProfilerand theScopedHotspotRAII helper behind--timing. - Produces the process-level hotspot ranking sorted by cumulative time
(
CTRACE_HOTSPOT_TOP=<N>, default 20, max 200).
- Input loading compiles/parses sources into an LLVM module.
-
ModulePreparationServicederives reusable analysis context. -
IRFactCollectorwalks the module once, feeding every registeredInstructionSubscriber; the derived indexes land in theAnalysisArtifactStore. - Analysis modules compute findings from those facts.
-
Reachabilityannotates/filters findings where needed. -
LocationResolvermaps findings to source coordinates. -
DiagnosticEmitteremits final diagnostics for human/JSON/SARIF outputs. - Optionally, the SMT layer refines the findings that remain imprecise.
- Better testability: each module has a narrow API and predictable inputs.
- Clear evolution path: adding checks does not require touching CLI/app orchestration.
- Lower regression risk: location/rule formatting logic is centralized.
Fine-grained unit tests:
test/unit/analyzer_module_unit_tests.cpp
Covered modules:
LocationResolverReachabilityModulePreparationService
Plus the resource ownership engine, in its own suites:
test/unit/ownership_engine_unit_tests.cpptest/unit/ownership_collector_input.cpp
Build target:
-
stack_usage_analyzer_unit_tests(enable with-DBUILD_ANALYZER_UNIT_TESTS=ON)