Skip to content

MIR validator negative coverage: validate_mir_body and use-after-kill have no malformed-MIR cases #989

Closed

Description

@eas4ai

Restated 2026-10-25. src/MirValidationTests.w now constructs malformed MIR for the typed and ownership validators. What is left: negative cases for validate_mir_body (structural checks) and validate_use_after_kill_body.


Original report

Classification

Testability gap, medium-low (audit finding VALID-001). The validators' rejection logic is real (verified by reading); nothing exercises it with invalid input.

Source chain

validate_mir_body checks locals-vector skew/return-local presence, module level checks duplicate fn_sym bodies + index-map agreement (src/Mir.w:2765-2800), validate_use_after_kill_body implements kill-on-zero-fill / revive-on-write / linear-reach gating (:2657-2704, plus the #927 postmortem proving it bites). But coverage is positive-only (--validate-* snapshot tests on valid programs, e.g. test/phase/validate_ownership_basic.w). Negative testing is structurally blocked from outside the compiler package: MirBody/MirModule non-pub (:393,490 — contrast pub type InternPool), validate_all_mir_module/validate_mir_body/validate_ownership_* non-pub free fns, and the one pub validator takes the non-pub body type.

Precedent

The codebase already solved this exact problem: Arena/Ids/InternPool re-homed as compiler.foundation.* + hostile-input unit tests in test/internals/*_test.w (e.g. arena_id_invalid negative controls). MIR validators never got it.

Repair boundary

Re-home or re-export the validator entry points and add hostile-body units: blank-then-read, duplicate fn_sym bodies, locals-vector skew, out-of-range terminator refs (the last also covers the trigger class of #982's stub-label finding).

Activity

  1. ehartford commented on Sep 16, 2026

    @ehartford
    Contributor

    Review: reproduced at the reported revision; partially addressed on main since 2026-09-10

    Verdict. At 450733e the claim holds in full: no test fed malformed MIR to any validator, and the types and entry points needed to do so from outside the compiler package were private. One week after filing, commits ae79a08 through 62b7906 (2026-09-10) added src/MirValidationTests.w, an in-package module that constructs hostile bodies directly and asserts rejection verdicts, driven from test/internals/mir_uninitialized_drop_test.w. That closes the "structurally blocked" half by a different route than the report proposed (test code lives inside the package instead of re-homing the validators), and it gives the ownership validator real negative coverage. The other validators named in the report still have none, and the out-of-range terminator class has no validator to test at all (confirmed while reviewing #982 and #984).

    Tested revision and compiler

    item value
    reported revision 450733e: git show 450733e5:src/MirValidationTests.w fails (file absent)
    HEAD 5809ac1 (2026-09-14); source read, no execution needed for this claim
    platform macOS Darwin 25.6.0, arm64

    What exists on HEAD

    src/MirValidationTests.w (94 lines, use MirCore) builds bodies with MirBody.init_for_fn / new_block / push_stmt / set_terminator and asserts on validate_ownership_body and validate_ownership_mir_module:

    hostile case assertion
    drop of a never-initialised local, through Drop and DROP_AND_GOTO .contains("never initialized it (Uninit)")
    StorageDead parameter then drop same rejection
    drop of a non-global uninitialised local vs a marked global proxy rejected vs == ""
    zero-storage StorageLive then drop == ""
    two bodies both failing in one module verdict names fn sym1 and fn sym2

    plus mir_drop_plan_action sentinel checks. The file's header comment states the report's thesis verbatim: "testing only corrected source lowering would leave the validator's original false-green result untested."

    What is still missing (the report's list against HEAD)

    validator / class negative coverage on HEAD
    validate_ownership_body yes (above)
    validate_use_after_kill_body (kill-on-zero-fill, revive-on-write, linear-reach) none
    validate_mir_body structural checks (locals-vector skew, term-array length mismatch) none
    module-level duplicate fn_sym bodies / index-map agreement none (the two-body test uses distinct syms)
    validate_typed_mir_body none
    out-of-range terminator targets no validator exists (validate_mir_body checks array lengths only), so nothing to test yet

    Visibility is unchanged (src/MirCore.w:393 type MirBody, :493 type MirModule, validators non-pub except validate_use_after_kill), which is fine given the in-package test module pattern, but means every future hostile test must be added inside src/.

    Related PRs / commits

    Would I champion the remainder? Yes.

    Acceptance criteria:

    1. Extend MirValidationTests.w with hostile bodies for validate_use_after_kill_body (blank-then-read, revive-on-write), validate_mir_body (locals-vector skew), the module-level duplicate-fn_sym check, and validate_typed_mir_body (argument type/count mismatch, which await in fn-param defaults checks green but is invisible to the suspend artifact #986 and Impl method arity is not checked against the trait (types are, D140): an extra parameter fails late #988 showed slipping through).
    2. Add the terminator-range validator and its hostile test (out-of-range goto, switch target, call next block, and the switch default sentinel per Switch-default d2==0 means abort() in C but bb0 in LLVM (unenforced convention) #984's ruling).
    3. Record in docs/deep-debugging-tools.md that hostile-MIR tests live in src/MirValidationTests.w and are run by test/internals/mir_uninitialized_drop_test.w, so the next validator author finds the pattern.

    Untested

    I did not execute the internals lane; the assertions were read, not run. Whether the lane runs in :test on every platform was not checked.

  2. ehartford commented on Oct 25, 2026

    @ehartford
    Contributor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced, narrower than reported. Correction to an earlier triage note: there is a malformed-MIR harness. src/MirValidationTests.w builds invalid MIR directly (34 mir_test_* cases, run from test/internals/) and exercises validate_typed_mir_body and validate_ownership_body. What is still uncovered: no case reaches the rejection paths of validate_mir_body (locals-vector skew, return-local presence, duplicate bodies) or validate_use_after_kill_body; the one validate_all_mir_module case tests only a failed-lowering body.

    post-release: test coverage for two validators, the harness to extend already exists.

  3. changed the title [-]MIR validator rejection paths have no negative coverage (hostile-MIR testing structurally blocked)[/-] [+]MIR validator negative coverage: validate_mir_body and use-after-kill have no malformed-MIR cases[/+] on Oct 25, 2026
  4. added this to the post-v0.16.0 milestone on Oct 28, 2026
  5. added a commit that references this issue on Nov 11, 2026
  6. ehartford commented on Nov 11, 2026

    @ehartford
    Contributor

    Fixed in #3255 (6a905fd): test/internals/mir_structural_validator_test.w builds malformed MIR by hand and requires validate_mir_body and the use-after-kill validator to refuse each case (bad switch default, a use after a kill, a field through a reference).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions