Repository navigation
Document extensible static checker proposal - #303
Conversation
|
|
||
| **Status** — Design proposal. | ||
|
|
||
| Pathologist can use its C and C++ lowering, call graph, and function models to check properties that depend on execution order across function calls. The first release infers effects from resolved in-tree bodies for null dereference and double free. Use-after-free tests whether a third rule can reuse the same operations, object identities, and lifetime state. |
There was a problem hiding this comment.
Stale project name
The new proposal documents refer to the tool as "Pathologist" (also in RULES.md and EDGE_CASES.md), while the repository, AGENTS.md, and all crates use "trace". This is a confirmed documentation inconsistency: readers see a different tool name, and link text such as "Pathologist CFG boundaries" is misleading. Replace "Pathologist" with "trace" throughout, or explicitly document that Pathologist is a former name.
PR Reviewer Guide 🔍(Review updated until commit d9727b1)Here are some key observations to aid the review process:
✅ Resolved findingsdocs/check/README.md:5Stale project name The new proposal documents refer to the tool as "Pathologist" (also in RULES.md and EDGE_CASES.md), while the repository, AGENTS.md, and all crates use "trace". This is a confirmed documentation inconsistency: readers see a different tool name, and link text such as "Pathologist CFG boundaries" is misleading. Replace "Pathologist" with "trace" throughout, or explicitly document that Pathologist is a former name. |
DeepSeek review: Approved (
|
devnullexile
left a comment
There was a problem hiding this comment.
The proposal has no blocking findings. The inline comments cover exception dispatch, callback edges, checker contract semantics, and two documentation fixes.
|
|
||
| 1. Resolve the invocation within the caller's link target and configuration. An explicit applicable checker contract supplies the transfer. Otherwise select the retained body variant using the resolved declaration, TU and variant provenance. If the body cannot be selected with sufficient coverage, include an unknown successor. Candidate records for one invocation are alternatives with the same input. [Link targets and weak symbols](../ANALYSIS.md#link-targets-and-weak-symbols) | ||
| 2. Project the caller state onto the callee's explicit formals, supported receiver if available, exact exposed slots, and reachable tracked resources. Canonicalize object and slot identities by input position and alias relation. Treat by-value formals as new slots. A write to such a formal affects the callee's copy, and a release through it affects the shared object. An unsupported read or write invalidates affected state through the usual opaque-effect transfer. | ||
| 3. Run the existing worklist on the callee graph with those facts. Compute a summary of normal and exceptional outcomes containing return values, changed input slots, resource states, and applicable coverage. Record a violation inside the callee as a finding template with local source spans and references to the input facts that support it. Keep each normal result paired with the memory and resource effects of its path. A proven nonreturning outcome has no normal continuation. |
There was a problem hiding this comment.
[P2] Preserve handler matching in exceptional outcomes. If a helper throws an int and the caller has catch (double) followed by catch (int), the existing CFG walk gives both handlers an edge from the same landing block. An outcome carrying only the exceptional state could yield a definite null-dereference finding in the unreachable double handler. Carry the thrown type through summaries and dispatch to the first matching handler, or mark imprecise dispatch as a coverage gap that prevents definite findings on those edges.
| | Candidate outcomes and partial solve | Calls to a release target and to a no-op target are alternatives. A later release can have a possible finding from the first target, with that target named in evidence. Include an unknown alternative for unresolved indirect or virtual dispatch and where a partial solve cannot establish candidate completeness. | | ||
| | Unknown effects and escape | A by-value pointer can expose the pointee without exposing its caller-local slot. A reference or pointer-to-pointer can also expose the slot. A prior store to shared memory can expose an alias to a later call with no pointer arguments. Invalidate those reachable facts. Preserve an independent binding such as a separate local assigned null after the call. | | ||
| | Configuration validation and overrides | Reject malformed checker effects, conflicting contracts for one signature within a file, and invalid parameter indices when the signature is known. An empty checker effect list disables the matching contract and permits eligible body inference. Both a checker override and an empty checker model preserve unrelated solver effects on the same symbol. | | ||
| | Synthetic and asynchronous edges | IPC and task-start edges supply no synchronous memory effect from the remote or deferred body. Record a coverage gap when shared escaped state can be affected. Synchronous wrapper effects, if modeled, still apply at the initiating call. | |
There was a problem hiding this comment.
[P2] Exclude reachability-only callback edges from synchronous call candidates. A discarded std::bind(release, p) still gets an indirect edge to release at the bind site and has no execution_contexts row. Applying that edge as a call outcome can make the checker report a later first release as a possible double free. Specify how to identify these modeled edges and add a discarded-bind fixture.
| | Release | Check the named argument's identity and state, then transition the resource on a valid release. Specify the resource kind and what null or another invalid sentinel means for the API. | | ||
| | Require non-null | Require a non-null pointer in an explicit argument at entry. This contract alone describes a precondition. A modeled access needs a separate contract if a later rule depends on it. | | ||
|
|
||
| A project can describe a custom pool with the following proposed TOML fields. The release effect binds to explicit parameter zero. Its behavior follows the contract, including for wrappers with a body. Later files replace earlier checker contracts of the same name and applicable signature. An empty effect list disables that contract and permits inference from an eligible body. Calls without an applicable contract or eligible body get the opaque transfer. |
There was a problem hiding this comment.
[P2] Give checker contracts a signature selector. With project::pool_free(int*) and project::pool_free(const int*), the documented name and release parameter match both declarations. If the const overload is a no-op, modeling it as a release can make the next valid release look like a double free. Define how to target and disable a single overload, and test two overloads whose parameters both pass effect validation.
| | --- | --- | | ||
| | Acquire | A successful result produces a live resource identity of a named kind. Specify the failure value or outcome when applicable. | | ||
| | Release | Check the named argument's identity and state, then transition the resource on a valid release. Specify the resource kind and what null or another invalid sentinel means for the API. | | ||
| | Require non-null | Require a non-null pointer in an explicit argument at entry. This contract alone describes a precondition. A modeled access needs a separate contract if a later rule depends on it. | |
There was a problem hiding this comment.
[P2] Preserve memory effects when a contract only states a precondition. If init(int **out, int *in) writes *out = in, a Require non-null contract on out satisfies the precondition at init(&p, &value). Using that contract in place of the body can leave p abstractly null and produce a definite finding on a valid *p. Apply preconditions alongside inferred effects or opaque invalidation unless the contract explicitly specifies the call's writes.
| | Source identity | Macro-generated findings preserve original spelling and expansion attribution as applicable. Two evaluated operations sharing a mapped source span remain individually identifiable. | | ||
| | Coverage and limits | Force an unsupported construct, an omitted call, an alternative-cap overflow, and a worklist-budget stop. Report the matching reason. Withhold stopped-body findings, and still report an independently converged body's results. Unaffected facts retain usable evidence. | | ||
| | Rule composition | Run the two initial rules and the extension rule separately and together. Each of the three gives the same findings and confidence for the same bodies and budgets. Count transfers independently of the number of reporting rules. The use-after-free extension uses the existing graph, resolution, worklist, and lifetime transfer. | | ||
| | Reproducibility | Repeated runs and different `--jobs` produce identical normalized findings, evidence, coverage, and existing analysis relations for the same inputs. Ignore only run metadata such as timestamps. | |
There was a problem hiding this comment.
[P3] Run the reproducibility gate with the wall-clock solver cap disabled. Two runs with the same --solve-budget-secs can stop at different worklist checkpoints and supply different candidate edges to the checker. Use an uncapped solve or a fixed pop budget for the equality fixture and keep the timed-cutoff case under coverage tests.
| | [Rule catalog](RULES.md) | Candidate checks, examples, required facts, and suggested delivery order | | ||
| | [Implementation plan](IMPLEMENTATION.md) | Milestones, crate ownership, acceptance fixtures, and release checks | | ||
|
|
||
| The design calls for an opt-in pass after the existing Andersen solve. Explicit design approval is required before flow-sensitive implementation under the [contributor guide](../../AGENTS.md#invariants). |
There was a problem hiding this comment.
[P3] Point this approval link and the one in implementation milestone 0 to AGENTS.md#do-not. Both currently lead to the solver invariants, while the approval rule lives under “Do not.” AGENTS.md says, “Keep documentation rules in one authoritative section and link to it from summaries, comments, and change descriptions.”
175c0b2 to
876bf31
Compare
devnullexile
left a comment
There was a problem hiding this comment.
Five of my six earlier comments are resolved:
- Exception handler matching and imprecise-dispatch fallback (
INTERPROCEDURAL.md,DESIGN.md,EDGE_CASES.md,IMPLEMENTATION.md) - Excluding callback-only edges from synchronous call candidates (
INTERPROCEDURAL.md,EDGE_CASES.md,IMPLEMENTATION.md) - Preserving memory effects for precondition-only contracts (
DESIGN.md,INTERPROCEDURAL.md,EDGE_CASES.md) - Disabling the wall-clock solver cap in the reproducibility gate (
IMPLEMENTATION.md) - Pointing the design-approval links to
AGENTS.md#do-not(README.md,IMPLEMENTATION.md)
The signature-selector addition (DESIGN.md) mostly addresses the overload-matching comment, with one remaining IR/symbol-table gap noted inline.
|
|
||
| Extend `FnModelSet` and the existing `--models` loader with checker contracts in a separate `[[check_model]]` table. Ordinary `[[model]]` entries replace the same-name solver model. Separate registration lets checker contracts be overridden or disabled independently. Use the shared scope and link-target resolver to identify candidate declarations, then match each contract by qualified name and exact signature. Apply library contracts only to applicable library declarations or explicitly configured equivalents. Treat user-declared contracts as analysis assumptions and record the selected contract in evidence. [Function model matching and configuration](../MODELS.md#model-matching) · [Model registration code](../../crates/trace-analysis/src/summaries.rs) | ||
|
|
||
| The required `signature.params` array lists explicit parameter types in order. Use `[]` for a zero-parameter declaration. Optional `variadic`, `member_cv`, and `member_ref` fields default to non-variadic and unqualified. Compare declaration types after standard parameter adjustments and alias resolution in the declaration's scope. Preserve pointee qualifiers and reference kinds, so `int *` and `const int *` select distinct overloads. Validate effect indices against the selected declaration. If its signature is missing, ambiguous, or unsupported, use the eligible body or opaque transfer. Later files replace the same qualified-name and canonical-signature entry. An empty effect list disables that exact entry and permits body inference. [Function declaration types](https://eel.is/c++draft/dcl.fct) |
There was a problem hiding this comment.
[P2] Plan the IR, symbol-table, and overload-ranking changes required to distinguish pointee qualifiers and reference kinds (int * vs const int *, T & vs T &&). Today TypeDesc::Ptr carries no cv-qualifiers, Function stores only param_type_ids and reference_params: Vec<bool> (without per-parameter CvQualification or lvalue/rvalue reference kind), SymbolTable::redeclaration_compatible folds a project::pool_free(int *) declaration and a project::pool_free(const int *) {} body into one Function entry, and call-site argument ranking in trace-parse/src/lower.rs does not separate those overloads. Milestone 1 currently omits this metadata/registration work while Milestone 2 puts signature matching in summaries.rs; also note how separating these overloads interacts with the disabled-mode baseline-equality gate in IMPLEMENTATION.md.
876bf31 to
d9727b1
Compare
There was a problem hiding this comment.
Automated DeepSeek review found no blocking concerns in d9727b1.
ArcsinX
left a comment
There was a problem hiding this comment.
LGTM! The static checker proposal comprehensively addresses all previously raised review points (including exception dispatch, callback edge filtering, precondition memory effects, solver reproducibility without wall-clock dependency, and the milestone 1 prerequisite for C++ declaration signatures and overload resolution).
devnullexile
left a comment
There was a problem hiding this comment.
My earlier comment on planning the IR, symbol-table, overload-ranking, and baseline-gate work for qualified/reference signatures is resolved (DESIGN.md, EDGE_CASES.md, IMPLEMENTATION.md).
One new gap in the trace-merge persistence plan from this update is noted inline.
|
|
||
| 1. **Represent declaration types.** In `trace-ir`, add a shared declaration signature to function metadata. Each explicit parameter records its declared type shape before reference-to-address lowering, const and volatile qualification at the represented type layers, and whether it is a value, lvalue reference, or rvalue reference. Reuse interned type shapes and resolve the signature once per declaration. Record member qualification and variadic shape in that same view. Use explicit unknown metadata for declarations the parser cannot characterize. The PAG consumes flow types, and call wiring obtains its reference-binding flag from the declaration metadata where available. | ||
| 2. **Lower and normalize signatures.** Use the same declarator lowering for prototypes and definitions, including unnamed parameters and out-of-class definitions. Capture qualifications and reference kinds before building flow types, even when the TU has only one declaration of a name. Resolve aliases and reference collapsing. Apply the language's parameter adjustments, including array/function decay and removal of top-level cv on by-value parameters. Preserve pointee and referent qualification. The canonical signature compares `int *const` and `int *` as the same by-value parameter, while `const int *`, `T &`, and `T &&` retain their distinctions. Use explicit parameter positions that exclude the implicit object argument and preserve pack boundaries. [Parameter type adjustments](https://eel.is/c++draft/dcl.fct) · [References and reference collapsing](https://eel.is/c++draft/dcl.ref) | ||
| 3. **Use one signature view for symbol identity.** Extend the existing `SymbolTable::explicit_params` view and use it in `redeclaration_compatible` and signature-aware redirects and override matching. Reject known qualification or reference-kind mismatches before any tolerant spelling or arity fallback. Keep scope, C linkage, target ownership, and weak-definition selection in the existing resolver. Remap signature types with the unit's type map before registration and preserve them when a declaration adopts a definition, including shared-header and target merge. Track unresolved identity when information is insufficient to establish which overload owns a body. Carry the supported signature distinctions through exported linking facts for signature-aware reconstruction, with older facts represented as incomplete where they lack this metadata. [Link targets and weak symbols](../ANALYSIS.md#link-targets-and-weak-symbols) · [Linking metadata compatibility](../SQLITE_SCHEMA.md#version-and-capability-contract) |
There was a problem hiding this comment.
[P2] Specify how trace-merge handles functions.signature alongside linking_facts. Updating only linking_facts leaves trace-merge using functions.signature—which crates/trace-db/src/export.rs (function_signature) formats with const/volatile erased and T &/T && lowered to T*—for direct cross-repo call linking (matching_definitions in crates/trace-merge/src/lib.rs, noting LinkingFacts::collect excludes free functions without ::), duplicate strong-definition collision grouping, header deduplication (DbFunction::source_origin), and even post-CHA weak-vs-strong filtering in crates/trace-merge/src/linking.rs (reconstruct). Conversely, changing functions.signature in place conflicts with the additive v9 column contract in docs/SQLITE_SCHEMA.md#version-and-capability-contract and breaks exact d.signature == signature matching when merging a new database with an older v7–v9 database. Plan whether Milestone 1 keeps functions.signature unchanged and stores canonical declaration signatures in an additive column/table (with coarse fallback on older inputs) or bumps the schema version, and cover mixed old/new database merges in IMPLEMENTATION.md.
No description provided.