tooling: add a deterministic differential fuzz test for the CPU translators #446
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#446
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@grahamster2 on GitHub · 2026-11-22 03:48 UTC · original
Proposal
Add a deterministic differential fuzz test for the CPU translators to the suite, so every PR runs native code and its translation side by side on generated functions, not only on hand-written fixtures.
Why
Out-of-tree differential runs found these, none of which a fixture or CI caught:
jccto its own fallthrough was accepted, but its translation did not compile (merged).pe_mapfault inside the map, whereLoadLibraryExWmaps or refuses the file.b9935bc).7fb6a9aadopted the rule)./O2in three translators. @bosseurdinternet's execution tool found the first one.The generators produce only forms each translator documents as accepted: leaf ALU at all widths, flags producer→consumer pairs, loops, frames with PUSH and MOV saves, spills at partial overlaps, mid-body RSP changes, chains of calls, shared callees and tail jumps. So a refusal of an accepted shape is reported as an over-refusal, and any value difference is a translator bug. Each function is assembled with ML64, translated, built with
cl, and compared on RAX plus a 256-byte buffer over a few hundred inputs. Planted translator faults (a skipped volatile clobber, the wrong callee, a dropped flag) are detected.Shape, for you to accept or narrow
tools/fuzz_cpu.py, a source generator plus runner. It needs only ML64,link,cland the existing Python environment, writes underout/, and adds no new dependency.cpu_aot_fuzz_smoke: a few fixed seeds × about 20 functions per area (leaf, frames, calls), so it takes seconds in the Windows job and is deterministic. A failure prints the seed, the minimized MASM and native vs translated values.docs/experiments.md, for contributors to run before larger translator changes.pe_mapheader mutation, x87 and shared-lifter areas, and a bad-pointer mode that checks fault equivalence (the #437 class).Questions: is an in-tree fuzz test welcome, and with what CI time budget? Should the smoke test cover only
cpu_switch_aotfirst? Should generated failures turn into fixed fixtures through a documented workflow, or stay seed-only?I'd send it as one PR after your answer.
@RonLogic on GitHub · 2026-11-22 12:10 UTC · original
I measured the proposed CI budget with a local, source-built register-alias sample on Windows 11 build 26300.9974, x64 MSVC 19.52.37029.0, at
0f8e7fa. One ML64 DLL held all the generated exports. One translation and two C++ builds (/Odand/O2) compared RAX and 16 output bytes against native execution. The generated chains mixed partial-register ALU operations and shifts, then used one CMP for SETcc and CMOVcc.0xA9020xA9020xCCD1There were no differences in this leaf-only sample. Batching exports into one native DLL and one translation kept the small configuration under one second on this machine. Frame and call generation still need their own timing and diagnostics. This is a timing data point for your proposed harness.
AI-assisted.
@triggered02 on GitHub · 2026-11-23 16:18 UTC · original
Opened #894 as the smoke shape discussed: 20 generated leaf functions on
cpu_switch_aot, one native DLL, one translation, default and/O2builds, 313 inputs each. Default run: 0.37 s and 12,520 comparisons in both dev and release. Long run: 96 functions at seed0xCCD1, 1.09 s and 60,096 comparisons. Scope, seed, promotion path and follow-ups are in the PR. Happy to narrow the first smoke or adjust the seed/CI budget.AI-assisted.
@R0Y00 on GitHub · 2026-11-23 17:11 UTC · original
#894 landed the first deterministic smoke. Both Windows jobs run it, and the reviewed commit independently matched 12,520 native/default/O2 comparisons for 20 generated leaf functions. The manual seed and function-count options are documented, and invalid reproduction filters now fail. This issue stays open for the proposed frame and call generators. A focused next fixture could start with fixed frames, include a saved/restored register and a partial spill overlap, and demonstrate a planted error before adding call graphs.
@denn0x on GitHub · 2026-11-23 17:18 UTC · original
I'd like to take the fixed-frame generator suggested above, unless @triggered02 (who wrote #894) or @grahamster2 (who has the out-of-tree generators) already has it in progress. If so, I'll step back and review.
Scope: only the four items listed above.
PUSHof RBX, RSI, RDI and R12–R15, andSUB/ADD RSPby multiples of 8, with real.pushreg/.allocstack/.saveregunwind directives. There is no RBP anchor and noLEAVE, so #907 and #895 can changeFramewithout breaking it.PUSH/POPand through MSVC'sMOV [rsp+8], rbxhome-space save. Each register is overwritten from the arguments before use, so the generator never reads an entry value.cpu_aot_stack_framesnotes, so I won't use it.It would be a separate CTest,
cpu_aot_fuzz_frames, with its own seed stream. The existing smoke at0xA902keeps its 20 functions and 12,520 comparisons byte-identical. There are no calls or call graphs.AI-assisted (Claude Code).
@roansystemlabs on GitHub · 2026-11-24 01:29 UTC · original
I'd like to take the next follow-up after #927: direct calls, unless @grahamster2 or @denn0x already has it in progress (if so, I'll step back and review).
Scope, one focused slice, no call graphs yet:
It would be a separate CTest (
cpu_aot_fuzz_calls) with its own seed stream, leavingcpu_aot_fuzz_smokeandcpu_aot_fuzz_framesbyte-identical, with the same manual seed and function-count options as #927 and adocs/experiments.mdparagraph with timings and comparison counts in dev and release. Recursion, indirect calls, mid-body RSP changes and fault equivalence stay out. Environment: Windows 11 26200, MSVC 19.44,devandreleasepresets.AI-assisted.
@tedin7 on GitHub · 2026-11-24 01:30 UTC · original
Claiming Stage 3 of the CPU fuzzer: a "calls" generator (call chains, shared callees, tail jumps) in tools/fuzz_cpu.py with a native-versus-lifted check and a --mutant negative control. Environment: Linux with LLVM 19 locally; I rely on the Ubuntu LLVM 15 job and the Windows WARP jobs for the rest. AI-assisted.
@R0Y00 on GitHub · 2026-11-24 01:45 UTC · original
@roansystemlabs, please take the first direct-call PR since your claim came in first. @tedin7, the two claims cover the same generator. Please coordinate on one PR. An independent review of the shared-callee and tail-jump cases, or a second run of the wrong-callee mutation, would be useful. Keep the existing seed streams unchanged and include one case where two callers reach the same callee with different values and observe the expected volatile-register clobbers.
@roansystemlabs on GitHub · 2026-11-24 01:50 UTC · original
Thanks, @R0Y00. I'll open the first direct-call PR shortly, with the shared-callee case extended so two callers reach the same callee with different values and the expected volatile-register clobbers are observed.
@tedin7, thanks for the parallel work in #1129. To end with one PR: would you review the shared-callee and tail-jump cases on mine and run the wrong-callee mutation independently on your Linux/LLVM setup? If your call-chain generator goes beyond what mine covers, it could follow as the next slice on top. I'll link the PR here as soon as it's up.
AI-assisted.
@roansystemlabs on GitHub · 2026-11-24 02:09 UTC · original
The direct-call PR is up: #1164
@tedin7, a review of the shared-callee and tail-jump cases or an independent run of the wrong-callee mutation on your setup would be very welcome there.
AI-assisted.
@RenzoWit35 on GitHub · 2026-11-24 10:52 UTC · original
I'd like to take the mid-body RSP changes area, unless someone already has it in progress (if so, I'll step back and review).
Scope, one generator for
cpu_switch_aot:--area rspintools/fuzz_cpu.pyand a separate CTest,cpu_aot_fuzz_rsp, with its own seed (0xB0D1, 36 exports).SUB/ADD RSPby 8 to 48 bytes,PUSH/POPof saved registers that hold data, two branch arms that reach the same depth in different ways, aSUB RSPthat aligns RSP for a direct call, and RBP-anchored frames that end withLEAVEorPOP RBP. Stores and reloads reach the same frame bytes through different[RSP+d]and[RBP+d]displacements. The generator reads only bytes the translator treats as defined.ADD RSPreleased, a join reached at two depths, a read below RSP, andSUB RSP, 4.[RSP+d]against the RSP left by the prologue's allocation, as if no later adjustment had moved RSP. The test fails unless that mutant gives at least one mismatch at the default seed.The smoke, frames, calls, chains, switches and scalar_fp areas keep their seeds, and their
emitoutput stays byte-identical. On #1329: the switch area has merged since it was listed, so this adds oneAREASand oneMUTANTSentry and a separate CMake block aftercpu_aot_fuzz_scalar_fp. No open PR touchestools/fuzz_cpu.py. x87,pe_mapheader mutation and bad-pointer fault equivalence stay out. Environment: Windows 11 build 26300, MSVC 19.51, ML64 14.51,devandreleasepresets.AI-assisted.
@roansystemlabs on GitHub · 2026-11-24 11:14 UTC · original
Claiming the loops area next. It isn't covered by an open PR or a claim here; if someone already has it in progress, I'll step back and review instead.
Scope, one generator for
cpu_switch_aot:--area loopsintools/fuzz_cpu.pyand a separate CTest,cpu_aot_fuzz_loops, with its own seed so the existing seed streams stay unchanged./O2comparison on RAX plus the buffer, as in the other areas.--mutant, a retargeted back edge) that must report mismatches, as the negative control.I'll verify it on Windows 11 with MSVC 19.44 in Debug and Release, with several runs and the exact CTest filter in the PR.
AI-assisted.
@R0Y00 on GitHub · 2026-11-24 11:22 UTC · original
The bounded loops generator can proceed independently of #1409's mid-body RSP cases. Please use a distinct seed and preserve the existing generators' emitted cases. In the back-edge control, keep execution bounded even under the mutation, then require a native/AOT mismatch at the fixed test seed. If both PRs touch the same CMake or generator registration, let's update the second after #1409 lands.
@RenzoWit35 on GitHub · 2026-11-24 16:44 UTC · original
I'd like to take the x87 area, which has no claim or PR yet. If someone already has it in progress, I'll step back and review.
Scope:
--area x87intools/fuzz_cpu.pyand a separate CTest,cpu_aot_fuzz_x87, with its own seed (0x8087, 40 exports). It emits straight-line code through the x87 profile of the shared lowering (ffx_version_query.lowerwithx87=True): loads of floats, integers, constants and ST(i), arithmetic in every operand form, unary operations, stores,FCOMIwithSETcc, status-word compares throughFNSTSW AX, andFCMOVcc. The generator tracks the stack depth, so nothing overflows or underflows. Four refused controls are included, and a planted mutant that lowersFSUBRasFSUBmust be detected.The existing areas' seeds, MASM output and translations stay byte-identical. It leaves out
FXTRACT,FSCALE, the checked entry (FLDCW,FNINIT,FPREM,FBLD),FFREE, and x87 state across branches or calls.Environment: Windows 11 build 26300, MSVC 14.51 / ML64 14.51,
devandreleasepresets.AI-assisted.
@roansystemlabs on GitHub · 2026-11-24 17:34 UTC · original
Claiming a bits area next. It isn't covered by an open PR or a claim here; if someone already has it in progress, I'll step back and review instead.
Scope, one generator for
cpu_switch_aot:--area bitsintools/fuzz_cpu.pyand a separate CTest,cpu_aot_fuzz_bits, with its own seed so the existing seed streams and emitted cases stay unchanged.Verification on Windows 11 with MSVC 19.44 (Intel i7-10700, BMI1/ABM present), Debug and Release, several runs, with the exact CTest filter in the PR. If it ends up touching the same registration as #1667, I'll rebase after that lands.
AI-assisted.
@louisdibiasi on GitHub · 2026-11-24 23:14 UTC · original
I'd like to investigate the register-offset memory forms of BT, BTS, BTR and BTC in
cpu_switch_aot. #1209 left this bit-string addressing as a follow-up; the existingcpu_aot_switch_bit_testsfixture currently checks that it is refused. I plan a source-built native-versus-translated fixture for signed offsets across word boundaries, carry, memory writes and adjacent bytes, with a planted addressing fault as a negative control. I'll preserve refusal for any forms whose frame or fault semantics I cannot model.I see that #1784 adds a fuzzing refusal control for the same form. If that PR is still open when this is ready, I'll coordinate the control and shared lifter changes with its author; if someone is already implementing the lowering, I'll step back. I haven't identified a measured startup blocker for this form, so I am not claiming one.
Environment: x64 Windows 11, MSVC and the project's local Python environment. AI-assisted (Codex).