startup: refuse a short operand list in the scalar ALU handlers #2469
No reviewers
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!2469
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2469/head"
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?
@ChazY11 on GitHub · 2026-11-25 17:36 UTC · original
ChazY11:startup/salu-arity→main· +156 −0 · 6 files · 3 commits · merged 2026-11-25 18:51 UTCEleven of the 44
SCAentries readops[1]without checking the count, so a short list came back astranslator crash in <op>: IndexError— the batch translator's marker for a translator defect, not for textit does not lower.
s_add_u32with no operands was the shortest repro.What changed
Stage.scalaris the single entry for the wholeSCAtable, so the guard is one check rather than eleven:op_s_bfm_b32keeps its own body (it folds constant masks and inspectsops[0]for them0destination), soit gets the same check in place.
s_movk_i32keeps its existing exact check for the immediate it folds.s_cselect_b32,s_abs_i32,s_bcnt1_i32_b32,s_addk_i32and thes_cmp*forms already refused thesecorrectly and are unaffected.
The check
tests/startup_gfx2hlsl_scalar_arity_check.pycovers, for all 44SCAentries, one accepted shape and bothshort forms, plus the refusal text for three of them and a negative control that loads the translator with
the guard removed:
Guard removal proof, one at a time:
Registered in
CMakeLists.txt(visible asstartup_gfx2hlsl_scalar_arityinctest -N), in the LinuxRun Python checkslist, and inAGENTS.md.Verification
tests/startup_gfx2hlsl_*_check.pyexit 0 on this branch;ctest --preset dev -R startup_gfx2hlslpasses 131/131 (658 s), so no accepted form changed;AI-assisted.
Every SALU form in `SCA` is written destination, source, and `Stage.scalar` reads `ops[0]` and `ops[1]` before it formats the template. A short list indexed past the end, so the batch translator recorded `translator crash in s_add_u32: IndexError` — its marker for a translator defect, not for text it does not lower — and the single-shader path did not catch it at all. 18 of the 44 `SCA` entries had this shape; `s_cselect_b32`, `s_abs_i32`, `s_bcnt1_i32_b32`, `s_addk_i32` and the `s_cmp*` forms already refused correctly. before: s_add_u32 -> translator crash in s_add_u32: IndexError after: s_add_u32 -> s_add_u32 with 0 operands, expected 2 before: s_add_u32 s0 -> translator crash in s_add_u32: IndexError after: s_add_u32 s0 -> s_add_u32 with 1 operands, expected 2 `op_s_bfm_b32` keeps its own body (it folds constant masks and reads `ops[0]` for the `m0` destination), so it gets the same count check in place rather than through `scalar`. `tests/startup_gfx2hlsl_scalar_arity_check.py` covers one accepted shape per entry, both short forms for all 44 `SCA` entries, the refusal text, and a control that loads the translator with the guard removed and requires `IndexError` for `s_add_u32`, `s_mov_b32`, `s_mul_hi_u32` and `s_not_b64` — so the check cannot pass without the guard: python out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_scalar_arity_check.py scalar ALU operand count checks: 0 failed PASS All 63 `tests/startup_gfx2hlsl_*_check.py` exit 0, and the `startup_gfx2hlsl` ctest subset passes 131/131 on this branch (658 s), so no accepted form changed.The check added by the previous commit needs the three registration points every pure-Python fixture has: `CTest` (name `startup_gfx2hlsl_scalar_arity`, visible in `ctest -N`), the Linux `Run Python checks` list in `.github/workflows/windows.yml`, and the "Pure-Python checks" list in `AGENTS.md`. Both production guards are pinned by removing them one at a time and requiring the new check to fail: scalar guard removed -> exit 1 bfm guard removed -> exit 1 restored -> exit 0 `cmake --preset dev` regenerates and `ctest --preset dev -N -R scalar_arity` finds the test, so it is not a file that exists without being run.@ChazY11 on GitHub · 2026-11-25 17:42 UTC · original
One addition that every other open PR here has and mine did not: a
docs/experiments.mdentry. I checked beforewriting it — my two earlier merged refusal PRs (#2360, #2373) carried no docs change, so this is not a gate,
but four of the five refusal/lowering PRs open right now document their rule, and the rule behind these count
checks was only in the code comments.
bbd4b69eadds one section todocs/experiments.md: whytranslator crash in <op>: <ExcType>is the wrongoutcome for a short operand list (
Stage.translaterecords it as a translator defect andrefusals_reportgroups by that text), which four entry points now refuse instead, and which check pins each. No behaviour
change;
tests/docs_links_check.pypasses (19 files, 466 links) and the scalar check still exits 0 on the head.If you would rather keep the docs out of this PR, say so and I will drop the commit; it is separable.
AI-assisted.
@ChazY11 on GitHub · 2026-11-25 17:59 UTC · original
Review-cost note, not a request: #2396 (5 handlers), #2408 (7 image forms) and this one (44
SCAentries) are allgreen and independent, and all three are refusal-only. If the size of this one is the reason it is waiting, it
splits cleanly into the 18 entries that actually crashed (
s_add_u32,s_sub_u32,s_mul_i32,s_and_b32,s_or_b32,s_xor_b32,s_lshl_b32,s_lshr_b32,s_ashr_i32,s_min_i32,s_max_u32,s_mov_b32,s_not_b32,s_brev_b32,s_mul_hi_u32, pluss_bfm_b32in its own body) and the rest, which thesingle
Stage.scalarguard covers for free but which never produced the marker. I can reduce the fixture to the18 and drop the docs commit to make a smaller first merge, and follow with the remainder.
The measurements behind it, in one place, so nothing needs re-running to decide:
One limitation I should state rather than leave implied: this machine cannot complete the full C++ build
(
archive_reader.exeand friends fail in DXC withunable to create compilation: AccessDenied, unrelated toany branch here), so my local evidence is limited to the pure-Python and
gfx2hlslside. The PRs arePython-only and CI builds them on the runners.
AI-assisted.
@ChazY11 on GitHub · 2026-11-25 18:27 UTC · original
Self-review of the table this PR adds to
docs/experiments.md, since a table that looks exhaustive is the easiestplace to mislead. I checked it against every operand-count refusal in the tree on
c887a65a:So the classification holds, but three refusal sites (
saveexec,wrexec,scalar select) are reachable andunnamed. Nothing is wrong with the behaviour they describe — all three already refuse — the question is only whether
the table should enumerate them.
Two readings, and I would rather you pick than guess:
translator crash in <op>: <ExcType>— then it iscorrect as written, and I should add one sentence saying so explicitly, because "four rows" reads like "four
sites" to someone comparing against the source.
saveexec,wrexecandscalar selectbelong in it, and I will extend it.
My own preference is (1) plus the sentence, since the crash is what the section is about and a longer table invites
the reader to think the list is the whole of the refusal surface. Say which and I will adjust; the docs commit is
separable from the guard commit either way.
While here, one measurement that supports the section's claim that a short operand list is the failure mode and not
a hypothetical: with the
Stage.scalarguard removed,s_add_u32with 0 operands raisesIndexErrorfrom%s with %d operands, expected 2→opsindexing, i.e. exactly thetranslator crash in s_add_u32: IndexErrorline the table's third column records.
AI-assisted.