Repository navigation
[AUTOMATED] fix(p4): evalcurrentproto - honor the compiler spec's <eval_current_prototype> so register arguments are recovered (DIV-71) - #290
Merged
Conversation
…al_current_prototype> so register arguments are recovered (DIV-71) Most functions in an x86 Windows binary rendered as `(void)` though they take arguments, with their ECX/EDX arguments surviving as locals READ BEFORE THEY ARE EVER WRITTEN -- not merely less informative, but not something a C function can do. A compiler spec can nominate one of its registered models for evaluating a function's OWN unlocked prototype, and x86win.cspec does exactly that: a `<resolveprototype name="__fastcall/__thiscall/__stdcall">` union followed by `<eval_current_prototype name=...>`. Every consumer of that nomination was already ported and wired -- ActionPrototypeTypes installs `glb->evalfp_current` on any unlocked prototype (coreaction.cc:4843), ActionInputPrototype calls FuncProto::resolveModel on it (fspec.cc:3772), and ProtoModelMerged::selectModel scores the active trials against each constituent. Only the `<eval_current_prototype>` element ITSELF was never read: the pass that registered named models deliberately stopped short of it, since honoring it changes which model every function is evaluated with. So evalfp_current stayed null, every function fell back to `<default_proto>` = __stdcall, whose <input> list is stack-only, and a register-passed argument was not a *possible* parameter at all -- it never became a trial. The merged-model machinery, fully ported and tested, had no live producer. Reading the element is the whole fix. The nominated name resolves against the model registry at `<default_proto>` time and is handed to each function through the arch handle; the union then resolves PER FUNCTION against the trials that are actually active, so a function that touches neither register still comes out __stdcall. Precedence is explicit: `option protoeval <model>` outranks the nomination (same slot), and the nomination outranks `option defaultprototype` for an unlocked prototype, which is upstream's own ordering. `<eval_called_prototype>` stays unread -- no vendored spec declares one. Six vendored specs nominate a model (x86win, x86borland, x86gcc __cdecl/__regparm, CR16, HCS12, HCS12X); every other language is untouched whichever way the option is set. Measured on a 3,153-function i386 PE: functions rendering as (void) 1,553 -> 602, functions carrying an ECX/EDX local read before written 2,128 -> 636. Ground truth from a COFF object of the same project, whose MSVC-mangled names encode the declared arity: 11 of 13 recovered arities match exactly, and the two that do not are UNDER-recovery of a parameter the body never reads. Wrongness audit over all 3,153 functions: 2,126 gained arguments, 0 lost any, and the set of called functions is identical in 3,152 of 3,153. Selective rather than blanket: a second i386 PE moves only 36 functions. Off-Windows, i386 gcc `ls` moves 1 of 537 and libpthread.so.0 34 of 467 -- every one a genuine glibc regparm internal recovered with the argument the source declares. Speed (decompile-all, interleaved, min of 3): +0.27% / +1.91%, with an unaffected-language control at +1.31% as the instrument's noise floor. Gates: make test 675/675 PARITY OK with the raw flip (no re-pin, no datatest opt-out), make test-stages PARITY OK (436/436) with one per-test opt-out on ghdec-cspecprotos.xml (it exists to pin this very bug), make rust-test green, make check-spec OK lenient and strict, kuna catalog --check OK. Web: integrations/web parity 19/19 and the real browser UI renders the recovered arguments. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01DQNaY1pwg8rskYRksC9qbh
mahaloz
added a commit
that referenced
this pull request
Aug 12, 2026
…hile the catalog is 103 `main` is red on the cargo workspace suite at 80f8f29: thread 'fixture_has_all_102_settables' panicked at crates/kuna-decomp/tests/catalog_bytecompat.rs:82:5: assertion `left == right` failed left: 103 right: 102 Nothing is wrong with the catalog. `phases.toml` has 103 settable rows, the fixture `tests/fixtures/phase_catalog.json` carries 103, and `kuna_phases/tests.rs` correctly asserts 103. Only this one test's three hard-coded copies of the same number were left behind: #287 regenerated the fixture and bumped `kuna_phases/tests.rs`, but did not touch `catalog_bytecompat.rs`, which #290 had last set to 102. This is the fourth time this class of counter has broken in two days -- three of the four during the round-4 merge train, where `main` and a branch had made the identical `N -> N+1` edit and git auto-merged them silently at the wrong value with no conflict marker. It reaches `main` because the workspace suite is skipped for internal PRs (#274), so nothing runs it until after the merge. Exactly one test failed in the whole CI run and the spec-tree guards never fired, so this assert is the entire breakage. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH
mahaloz
added a commit
that referenced
this pull request
Aug 12, 2026
…hile the catalog is 103 (#292) `main` is red on the cargo workspace suite at 80f8f29: thread 'fixture_has_all_102_settables' panicked at crates/kuna-decomp/tests/catalog_bytecompat.rs:82:5: assertion `left == right` failed left: 103 right: 102 Nothing is wrong with the catalog. `phases.toml` has 103 settable rows, the fixture `tests/fixtures/phase_catalog.json` carries 103, and `kuna_phases/tests.rs` correctly asserts 103. Only this one test's three hard-coded copies of the same number were left behind: #287 regenerated the fixture and bumped `kuna_phases/tests.rs`, but did not touch `catalog_bytecompat.rs`, which #290 had last set to 102. This is the fourth time this class of counter has broken in two days -- three of the four during the round-4 merge train, where `main` and a branch had made the identical `N -> N+1` edit and git auto-merged them silently at the wrong value with no conflict marker. It reaches `main` because the workspace suite is skipped for internal PRs (#274), so nothing runs it until after the merge. Exactly one test failed in the whole CI run and the spec-tree guards never fired, so this assert is the entire breakage. Claude-Session: https://claude.ai/code/session_01C8UQbPqALzdUQ3cLLjUeKH Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The defect
Most functions in an x86 Windows binary rendered as
(void)though they take arguments:The left column is not merely less informative —
v4is read before it is ever written, which is not something a C function can do. (IDA Pro reports this one aslong __fastcall Load_CBPZ(struct _VQAHandleP *, unsigned long)— two arguments.)Root cause
A compiler spec can nominate one of its registered models for evaluating a function's own unlocked prototype.
x86win.cspecdoes exactly that:Every consumer of that nomination was already ported and wired:
ActionPrototypeTypesinstallsglb->evalfp_currenton any unlocked prototype (coreaction.cc:4843),ActionInputPrototypecallsFuncProto::resolveModelon it (fspec.cc:3772), andProtoModelMerged::selectModelscores the active trials against each constituent. Only the<eval_current_prototype>element itself was never read — the pass that registered named models deliberately stopped short of it, because honoring it changes which model every function is evaluated with.So
evalfp_currentstayed null, every function fell back to<default_proto>=__stdcall, whose<input>list is stack-only — and a__fastcall/__thiscallfunction's ECX/EDX arguments were not possible parameters at all, so they never became trials. The merged-model machinery, fully ported and tested, had no live producer.The fix
Read the element (
p0_knowledge/kuna_evalcurrentproto.rs), resolve the nominated name against the model registry at<default_proto>time, and hand it to each function through the arch handle. The union then resolves per function against the trials that are actually active, so a function that touches neither register still comes out__stdcall.Behind
option evalcurrentproto(default-on, DIV-71). Precedence is explicit:option protoeval <model>outranks the nomination (same slot); the nomination outranksoption defaultprototypefor an unlocked prototype, which is upstream's own ordering.<eval_called_prototype>stays unread — no vendored spec declares one.Six vendored specs nominate a model —
x86win,x86borland,x86gcc(__cdecl/__regparm),CR16,HCS12,HCS12X. Every other language has no such element and is untouched whichever way the option is set.Measured
3,153-function i386 PE game binary:
(void)Ground truth. The COFF object from the same project carries MSVC-mangled names, which encode the declared arity independently of the decompiler. Across its 13 functions the recovered arity matches the mangled signature in 11 (counting a by-value
Coordas the slots it occupies); the 2 that do not are under-recovery of a parameter the body never reads (Get_Explosion_Z, whose whole body isreturn 0) — never over-recovery.Wrongness audit (standing requirement 8) over all 3,153 PE functions: 2,126 gained arguments, 0 lost any, and the set of called functions is identical in 3,152 of 3,153 — the exception is an unaligned
pushf/popfflags-probe stub whose return widens toint8.Selective, not blanket. A second i386 PE of comparable size (3,015 functions) moves only 36, because the union resolves most of it to
__stdcall.Off-Windows, since
x86gccnominates__cdecl/__regparm: i386ls1 of 537 (it is_start, whose EAX/EDX really are live at process entry), i386all0 of 23, andlibpthread.so.034 of 467 — every one a genuine glibcregparminternal recovered with the argument the source declares (__pthread_mutex_lock_full(uint4 *a0),change_stack_perm(int4 a0)).Speed (whole-binary
decompile-all, arms interleaved, minimum of 3): the 3,153-function PE +0.27% (159.98 → 160.42 s), the second PE +1.91% (53.54 → 54.56 s), x86-64ls+1.31% (31.27 → 31.68 s).lsis a language with no<eval_current_prototype>, so both arms run identical code — its +1.31% is this instrument's noise floor, and the two real arms sit at or below it — against the 5% budget.Tests & gates
New two-pass stage test
tests/stages/kuna-evalcurrentproto.xml(a clang-target i386-pc-windows-msvc__fastcallbody: off = one stack argument + an// ecxlocal, default = all three arguments).One per-test opt-out:
tests/stages/ghdec-cspecprotos.xmlexists to pin this very bug (getfield(void)with an// ecxlocal) and reach the fix by naming__thiscallby hand, so it now setsoption evalcurrentproto offto keep testing what it was written for.make test675/675 PARITY OK with the raw flip — no re-pin, no datatest opt-out (only 3 of the 83 files are on an affected language and all 11 of their assertions are unmoved) ·make test-stagesPARITY OK (436/436) ·make rust-testgreen ·make check-specOK lenient and strict ·kuna catalog --checkOK.Counters re-derived from the built artifact: live catalog 102,
catalog_bytecompat.rs102,kuna_phases/tests.rs102 / tiers (22, 45, 35) /},\n101 / live readers 31,phase_catalog.json102,docs/options.md102,xml.rscorpus 200.Web UI
integrations/webrebuilt: parity 19/19 native==wasm, glue/worker/fnfilter/auto-mode/zip green. Under WASI the same PE function comes outsub_6ae390(int4 a0,int4 a1), and the real browser UI (headless Chrome over CDP, uploading through the actual file input) rendersChain_Reaction_Damage(uint4 a0)where it used to render(void).Docs:
docs/spec/04-calls-and-prototypes.md(the section that previously recorded this element as deliberately ignored),phases.tomlrow + regenerateddocs/options.mdand catalog fixture, DIV-71 indocs/history.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01DQNaY1pwg8rskYRksC9qbh