Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
106 changes: 106 additions & 0 deletions docs/check/DESIGN.md

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions docs/check/EDGE_CASES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Static checker edge cases

This matrix defines the first release's behavior for `null-deref` and `double-free` and provides regression cases for the shared framework. **Complete** means the selected rule covered the relevant operations in its advertised subset. **Partial** means a named limit affected coverage. A partial body can still produce a finding at an independent operation when the proof and reachability are supported. The [design](DESIGN.md#findings-and-coverage) defines confidence and when to withhold findings.

## Pointer values and evaluated operations

| Case | Required behavior |
| --- | --- |
| Typed `nullptr`, literal zero, and macro-expanded C `NULL` | Recognize supported null pointer conversions under the TU's language and standard. Keep the expanded operand and source provenance. A macro named `NULL` with an unrecognized value and an arbitrary integer-to-pointer cast supply no null evidence. |
| Unknown parameter, uninitialized local, and unmodeled return | Keep unknown values distinct from explicit null and unreachable state. Mark a relevant missing return contract partial. An uninitialized read belongs to its own rule. Track an uninitialized pointer as unknown with a coverage reason where needed. |
| Copies, casts, and updates | Copy the evaluated value, including its resource identity when known. A cast preserves identity only for a supported address-preserving conversion. A write to one slot leaves value copies in other slots intact. References to the same slot observe the write. A later guard refines the tested value at that point. |
| Attachment of a guard to stale state | In `if (p) { p = nullptr; return *p; }`, report a definite finding at the dereference. In a version that copies `p` after the guard and changes only the original slot, the copy retains its non-null value. |
| Raw reads and writes | Emit a checked access for supported `*p`, `p->field`, and `p[0]`, including scalar destinations and RHS forms with no PAG load or store. A member call with an implicit object or a call through a function pointer needs a dedicated access form or a coverage reason. |
| Address formation and pointer arithmetic | In C, `&*p` evaluates the pointer expression without an indirection. C `&p[i]` uses pointer arithmetic. Keep the arithmetic separate from a memory access. Spellings such as `&p->field`, nonzero offsets, and C++ address formation outside the supported subset get a coverage gap when their semantics are uncertain. |
| Unevaluated expressions with zero calls | Skip raw accesses in plain `sizeof(*p)` for a non-VLA C type, and in C++ `sizeof(*p)`, `decltype(*p)`, and `noexcept(*p)`. Skip the C `_Generic` controlling expression and run only a known selected association. An unresolved association gets partial coverage. |
| Potentially evaluated operands | A C `sizeof` involving variably modified types requires evaluation classification. For C++ `typeid`, distinguish unevaluated operands and evaluation of polymorphic glvalues, including the special exception behavior for null indirection. Record a gap for unresolved VLA or polymorphic cases. |
| Scope, hidden storage, and overloaded operators | Use declaration identity for shadowed locals and nested lambda captures. Globals, local statics, general aggregate fields, volatile or atomic pointer loads, and overloaded pointer-like operators need their own memory or call effects. Unsupported relevant reads become unknown with a coverage reason. |

[C11 draft, clauses 6.3.2.3, 6.5.1.1, 6.5.3.2, and 6.5.3.4](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) · [C++ evaluation contexts](https://eel.is/c++draft/expr.context) · [C++ type identification](https://eel.is/c++draft/expr.typeid)

## Control flow and evaluation order

| Case | Required behavior |
| --- | --- |
| Constant, contradictory, and short-circuit tests | Prune provably unreachable operations. In `p && *p` or `!p \|\| *p`, the RHS sees the non-null alternative. In `!p && *p`, the RHS sees the null alternative. An overloaded logical operator follows its call semantics. |
| Sequenced expressions and assignments | Observe the order in a built-in comma expression and the selected branch of `?:`. Check C++17 assignment operand order separately from C and earlier C++. An explicit release of an already released object ends that supported alternative before subsequent operations. |
| Competing argument effects | In C++17 `consume((p = nullptr), *p)` with an initially live pointer, the arguments can be evaluated in either order. The initial checker marks interference partial and withholds a finding based solely on an assumed order. Also test earlier C++ and C, where conflicting effects may be unsequenced. |
| Loop exits and jumps | Check zero iterations, a back edge, `continue`, `break`, and a switch case with fallthrough. Use the visited predecessor's state and preserve branch alternatives. Model a direct `goto` only when its destination and traversed scope transitions are known. |
| Exceptional successor and cleanup | In `try { p = new int; } catch (...) { ... }`, the handler sees the old binding when allocation throws. A destructor or cleanup that can mutate a tracked pointer or release a resource has an effect when modeled and a gap otherwise. Preserve edges for known `throw` and known nonreturning calls. |
| Ordered exception handlers | Match a known thrown type to the first applicable handler. Preserve an unmatched outcome for outer unwinding. Mark uncertain handler selection partial wherever reachability depends on it. [Exceptional dispatch](INTERPROCEDURAL.md#exceptional-dispatch) |
| Unknown control transfer | Computed `goto`, `setjmp`/`longjmp`, inline assembly with unknown destinations, coroutine suspension, and recovery nodes can introduce predecessor paths absent from the graph. Downgrade affected paths to partial. Withhold the variant's findings if possible re-entry points cannot be bounded. |

[C++17 draft, sections on execution and evaluation](https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2017/n4659.pdf) · [C++ function-call sequencing](https://eel.is/c++draft/expr.call) · [Pathologist CFG boundaries](../USAGE.md#boundaries-and-gaps)

## Allocation and release

| Case | Required behavior |
| --- | --- |
| Nullable allocation | Retain a null failure outcome and a distinct live success outcome. An unchecked `malloc` followed by a supported raw access gives a possible null finding. A null guard removes that outcome from the surviving branch. Only success establishes a resource identity. |
| Null release and overwrite | `free(NULL)` and ordinary `delete` of a null pointer leave resource state alone. A later write of null into one alias leaves the original object's release state available to a previously copied alias. |
| Proven base versus interior pointer | Require a release-compatible base pointer to establish a valid release. Test `p + 1`, a member address, and a one-past pointer followed by `free(p)`. Expect zero double-free findings and the applicable coverage reason. A future invalid-release rule can report the first operation. |
| Wrong family, stack address, and borrowed pointer | A scalar `delete` on an array allocation, `free` on stack storage, or a release of unknown ownership cannot seed a same-object double-free proof. Use a distinct invalid-release rule when available. A matching array `delete[]` follows the normal release contract. |
| Unknown incoming pointer | Two releases of an incoming non-null parameter with unknown allocation provenance have partial coverage in standalone analysis. A known live object imported from a caller supplies the identity and original live state for that context. |
| Repeatable sites and reused addresses | Treat an acquisition inside a CFG cycle as a summary. Releasing once per freshly allocated object in a loop yields zero double-free findings from site equality. Releasing a known pre-loop object twice can produce a finding with back-edge evidence. Different acquisitions may reuse the same address while remaining distinct resource identities. |
| Replacement allocation and other aliases | After `p = allocate()` returns a second object, `p` refers to the replacement. A copy retained before the assignment still refers to the first object. Test both pointers at the next release. |
| C++ allocation variants | Ordinary throwing `new` has a normal live outcome and an exceptional outcome without the initial store. For `new(std::nothrow)`, placement `new`, custom `operator new/delete`, and nontrivial construction or destruction, require a matching effect or record partial coverage. |
| Zero size and resizing | A zero-size `malloc` or `calloc` result can be null or releasable. Neither lifetime nor non-nullness establishes a payload extent. Treat `realloc` as a gap initially. A future model needs correlated success and failure, invalidation of old aliases on success, and the applicable policy for size zero. |

[C11 draft, clause 7.22.3](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) · [C++ allocation](https://eel.is/c++draft/expr.new) · [C++ deallocation](https://eel.is/c++draft/expr.delete)

## Calls and effects

| Case | Required behavior |
| --- | --- |
| Argument values and results | In `p = replace(p)`, the model sees the evaluated old actual and binds the return value after the call normally completes. Preserve explicit argument positions across missing operands, hidden receivers, and defaults. A required omitted argument or default expression outside the supported subset gets a gap. |
| Shadowing, overloads, and link targets | Use the same selected definition or declaration as resolution in that TU and link target. Test standard global and `std::` forms where provenance establishes the contract, a shadowing project function, a mismatched overload, and a strong definition that replaces a weak one. |
| Two overloads with compatible effect parameters | Declare `project::pool_free(int *)` and define `project::pool_free(const int *)` as a no-op. Keep them distinct through registration and TU merge. Only the mutable overload receives the release contract, even though both arguments satisfy the effect's type requirements. An empty override for its signature leaves any separately configured overload and the solver effects in place. [Signature acceptance cases](IMPLEMENTATION.md#signature-identity-and-call-resolution) |
| 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 missing or malformed signature selectors, conflicting contracts for one canonical signature within a file, and invalid parameter indices when the signature is known. An empty checker effect list disables the matching signature and permits eligible body inference. Both a checker override and an empty checker model preserve unrelated solver effects on the same symbol. |
| Preconditions and exposed state | A non-null precondition on an out-parameter applies at entry. The inferred body still writes through that parameter. When the body is unavailable and only the precondition is modeled, invalidate the exposed slot. [Function effects](DESIGN.md#function-effects) |
| 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. |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

| Deferred callable with no execution context | Discard `std::bind(dispose, p)` for a known live allocation, then release `p` once. Verify the graph still has the bind site's reachability edge to `dispose` and no execution context there. The checker excludes that edge from synchronous candidates and reports zero double frees. A companion fixture calls `dispose` through a resolved function pointer and checks that its release takes effect. [Synchronous call candidates](INTERPROCEDURAL.md#synchronous-call-candidates) |

## Source, merge, and output

| Case | Required behavior |
| --- | --- |
| Macro provenance and ignored macros | Two effects from one expansion can have the same LineMap position and different operation IDs. Preserve call spelling and outer expansion coordinates where available. A relevant omitted effect in a dependency or ignored macro records a gap. |
| Distinct headers and configurations | Test a header with identical call sequencing but different assignments, equivalent definitions across multiple TUs, and a body compiled under different language modes or link targets. Analyze each distinct retained variant without borrowing an effect from another variant. |
| Post-merge call replacement | If resolution attaches an alternate target or replaces a call record, update each checker invocation by occurrence and leave one invocation transfer. A removed required operand becomes unknown with a gap. |
| Complete, partial, and unavailable export | An enabled rule with zero applicable bodies yields an empty complete result. A disabled or unavailable rule differs from an enabled rule with zero findings. A partial reason is visible even when filtering findings returns zero rows. A marker with missing required structures raises a read error. |
| Deterministic widening and trace truncation | Reorder otherwise equivalent predecessors and target records in an engine fixture. Confidence depends on the state, and equivalent evidence is selected deterministically. Force a trace limit and verify that the evidence retains the primary operation and causative step. A transfer budget stop withholds the stopped body's findings. |
| Unsupported unrelated operation | Put an opaque call before an independent local null assignment and access. Expect a definite null finding if the opaque call cannot re-enter later in the body and the dereference is reachable. The coverage reason still appears for any affected rule and body. |

Run these as small engine and lowering fixtures and carry representative cases through export and inspection. The [interprocedural fixtures](INTERPROCEDURAL.md#interprocedural-acceptance-fixtures) cover call transfer and context-specific exceptions. The [implementation plan](IMPLEMENTATION.md#acceptance-criteria) adds release-level compatibility, determinism, and corpus checks.
Loading
Loading