test: refuse a numeric read of a descriptor register #1762

Merged
ChazY11 merged 2 commits from upstream-pr/1769 into main 2026-11-24 21:11:14 +00:00
ChazY11 commented 2026-11-24 18:17:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T18:17:05Z.


What

Stage.S (the uint expression for scalar register n) answers for constants, uniform data and the two copy shapes, and
refuses everything else:

if s[0] == 'const': ...
if s[0] == 'ud': ...
if s[0] in ('execcopy', 'fixed_buffer_word'): ...
raise Unsupported('numeric use of s%d holding %s' % (n, s[0]))

No check reached that raise. Two mutations, each reverted:

raise -> return '0'                    all seven gfx2hlsl checks green
raise -> used_s.add(n); return 's%d'    all seven gfx2hlsl checks green

The second one matters most: falling through to s<n> would emit a register name for something that is not a 32-bit
value, which is the failure the raise exists to prevent.

Change

One case that builds the symbol state for a table pointer and for a descriptor and asserts the refusal, and that the
register is not added to used_s:

+    for shape in (('ptr', ('table', 0)), ('desc', ('table', 0), 0, 0)):
+        try:
+            got = stage.S(8)
+        except gfx2hlsl.Unsupported as error:
+            if 'numeric use of s8' not in str(error): ...
+        else:
+            failures.append('numeric symbol %r was read as %s' % (shape, got))
+        if stage.used_s:
+            failures.append('numeric symbol %r marked s8 as used' % (shape,))

The used_s assertion is deliberate: a refused read must not look like a use, or a later dead-code decision would keep a
register alive for a value that was never read.

Tested

out/pe-env/Scripts/python.exe -B tests/startup_translator_check.py
with the case, raise intact        startup translator checks: 0 failed
raise -> return '0'                FAIL (both shapes report a value)
raise -> fall through to s<n>      FAIL
reverted                           0 failed

Scope

One test file, no behaviour change. Related: in #1767 I noted this raise and the one at the end of descriptor as both
unreached; I have since corrected that comment — the descriptor one is reached by startup_inline_sampler_check.py, so
only this one needed a case.

Notes

  • AI-assisted.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6588469555 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1769). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T18:17:05Z. --- ## What `Stage.S` (the uint expression for scalar register `n`) answers for constants, uniform data and the two copy shapes, and refuses everything else: ```python if s[0] == 'const': ... if s[0] == 'ud': ... if s[0] in ('execcopy', 'fixed_buffer_word'): ... raise Unsupported('numeric use of s%d holding %s' % (n, s[0])) ``` No check reached that raise. Two mutations, each reverted: ```text raise -> return '0' all seven gfx2hlsl checks green raise -> used_s.add(n); return 's%d' all seven gfx2hlsl checks green ``` The second one matters most: falling through to `s<n>` would emit a register name for something that is not a 32-bit value, which is the failure the raise exists to prevent. ## Change One case that builds the symbol state for a table pointer and for a descriptor and asserts the refusal, and that the register is not added to `used_s`: ```diff + for shape in (('ptr', ('table', 0)), ('desc', ('table', 0), 0, 0)): + try: + got = stage.S(8) + except gfx2hlsl.Unsupported as error: + if 'numeric use of s8' not in str(error): ... + else: + failures.append('numeric symbol %r was read as %s' % (shape, got)) + if stage.used_s: + failures.append('numeric symbol %r marked s8 as used' % (shape,)) ``` The `used_s` assertion is deliberate: a refused read must not look like a use, or a later dead-code decision would keep a register alive for a value that was never read. ## Tested ```powershell out/pe-env/Scripts/python.exe -B tests/startup_translator_check.py ``` ```text with the case, raise intact startup translator checks: 0 failed raise -> return '0' FAIL (both shapes report a value) raise -> fall through to s<n> FAIL reverted 0 failed ``` ## Scope One test file, no behaviour change. Related: in #1767 I noted this raise and the one at the end of `descriptor` as both unreached; I have since corrected that comment — the `descriptor` one is reached by `startup_inline_sampler_check.py`, so only this one needed a case. ## Notes - AI-assisted.
tedin7 commented 2026-11-24 20:00:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T19:34:09Z.

Review: COMMENTED


Reviewed head a511dbb07322bc2c14929f201baf7331f1b0c7d6. No P1/P2 findings.

The new check_numeric_symbol_refusal covers both ('ptr', ...) and ('desc', ...) registers. It asserts that Stage.S(8) raises Unsupported with "numeric use of s8", and that used_s stays empty. This matches Stage.S in tools/startup/gfx2hlsl.py. The test covers the refusal and the lack of side effects, so a refused read can no longer leave an s8 declaration behind. It is test-only, and the comments describe behavior without outside material.

Commands run locally on Linux in a clean worktree:

  • git diff --check origin/main...HEAD -> rc 0
  • python -B tests/bidi_controls_check.py -> rc 0
  • python -B tests/startup_translator_check.py -> rc 0 (0 failed)

Mutations in tools/startup/gfx2hlsl.py (each reverted with git checkout -- .):

  1. Add 'ptr' and 'desc' to the allowed tuple in S (they are read as s8) -> the check FAILS (rc 1, 4 failures).
  2. Call self.used_s.add(n) before the raise -> the check FAILS (rc 1, 2 failures).

Windows 2025 will be verified before any merge, once the overlap with the other PR touching tests/startup_translator_check.py is resolved. This is a review comment only, not an approval.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046008733 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1769#pullrequestreview-6046008733). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:34:09Z. **Review:** COMMENTED --- Reviewed head `a511dbb07322bc2c14929f201baf7331f1b0c7d6`. No P1/P2 findings. The new `check_numeric_symbol_refusal` covers both `('ptr', ...)` and `('desc', ...)` registers. It asserts that `Stage.S(8)` raises `Unsupported` with "numeric use of s8", and that `used_s` stays empty. This matches `Stage.S` in `tools/startup/gfx2hlsl.py`. The test covers the refusal and the lack of side effects, so a refused read can no longer leave an `s8` declaration behind. It is test-only, and the comments describe behavior without outside material. Commands run locally on Linux in a clean worktree: - `git diff --check origin/main...HEAD` -> rc 0 - `python -B tests/bidi_controls_check.py` -> rc 0 - `python -B tests/startup_translator_check.py` -> rc 0 (0 failed) Mutations in `tools/startup/gfx2hlsl.py` (each reverted with `git checkout -- .`): 1. Add `'ptr'` and `'desc'` to the allowed tuple in `S` (they are read as `s8`) -> the check FAILS (rc 1, 4 failures). 2. Call `self.used_s.add(n)` before the `raise` -> the check FAILS (rc 1, 2 failures). Windows 2025 will be verified before any merge, once the overlap with the other PR touching `tests/startup_translator_check.py` is resolved. This is a review comment only, not an approval. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 21:00:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:29:05Z.

Review: COMMENTED


Review of head a511dbb073 (tests/startup_translator_check.py only; pure-Python fast path). No P1, no P2.

Commands run locally:

  • git diff --check origin/main...HEAD: rc=0
  • python3 tests/docs_links_check.py: rc=0
  • python3 tests/bidi_controls_check.py: rc=0
  • python3 tests/startup_translator_check.py: rc=0 (0 failed)

Mutations of the logic in tools/startup/gfx2hlsl.py, each reverted with git checkout:

  1. Stage.S returns '0x0u' for a ptr/desc symbol instead of raising: check fails, rc=1 (2 failed).
  2. Stage.S falls through to s and marks the register used: check fails, rc=1 (4 failed, including the used_s assertion).

The new check kills both mutations the commit message names. Windows 2025 runs are not applicable (tests/**/*.py only).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046859665 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1769#pullrequestreview-6046859665). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:29:05Z. **Review:** COMMENTED --- Review of head a511dbb07322bc2c14929f201baf7331f1b0c7d6 (tests/startup_translator_check.py only; pure-Python fast path). No P1, no P2. Commands run locally: - git diff --check origin/main...HEAD: rc=0 - python3 tests/docs_links_check.py: rc=0 - python3 tests/bidi_controls_check.py: rc=0 - python3 tests/startup_translator_check.py: rc=0 (0 failed) Mutations of the logic in tools/startup/gfx2hlsl.py, each reverted with git checkout: 1. Stage.S returns '0x0u' for a ptr/desc symbol instead of raising: check fails, rc=1 (2 failed). 2. Stage.S falls through to s<n> and marks the register used: check fails, rc=1 (4 failed, including the used_s assertion). The new check kills both mutations the commit message names. Windows 2025 runs are not applicable (tests/**/*.py only). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 21:01:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:43:23Z.


Thanks for this test. #1767 has just merged and touches the same lines of tests/startup_translator_check.py, so this branch now conflicts with main. Could you rebase on main and keep both checks? Once the head changes I will re-run the review checks on the new commit.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7143969110 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1769#issuecomment-7143969110). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:43:23Z. --- Thanks for this test. #1767 has just merged and touches the same lines of tests/startup_translator_check.py, so this branch now conflicts with main. Could you rebase on main and keep both checks? Once the head changes I will re-run the review checks on the new commit. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 21:27:21 +00:00
tedin7 commented 2026-11-24 21:27:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:09:38Z.

Review: COMMENTED


Review of head 3e62f7167f3d0a2c32063db2b477b5f7a7d77871 (tests/startup_translator_check.py only; pure-Python fast path). No P1, no P2.

Scope. git diff origin/main...HEAD touches one file: tests/startup_translator_check.py (+20 lines, new check_numeric_symbol_refusal, registered in main). No C++, no CMakeLists.txt. The head moved since the earlier review (a511dbb0) by a merge of main (3e62f716); the PR diff itself is unchanged. GitHub Build and test on Windows: pass; Run platform-independent Python checks on Linux: pass. Mergeable, state CLEAN.

Commands run locally on this head:

  • git diff --check origin/main...HEAD: rc=0
  • python3 tests/docs_links_check.py: rc=0 (18 Markdown files, 380 links)
  • python3 tests/bidi_controls_check.py: rc=0 (1342 files)
  • python3 tests/startup_translator_check.py: rc=0 (0 failed)

Mutations in Stage.S of tools/startup/gfx2hlsl.py (each reverted with git checkout -- ., tree clean after):

  1. A ptr/desc register falls through to s<n> and is marked used instead of raising: check fails, rc=1 (4 failed: read as s8 and marked used, for both shapes).
  2. used_s.add(n) before the raise Unsupported: check fails, rc=1 (2 failed: marked s8 as used, for both shapes).

The new check protects real behaviour: a refused numeric read of a descriptor or buffer-pointer register raises and leaves no s8 declaration. Windows 2025 runs are not applicable (tests/**/*.py only). This is a review comment, not an approval.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047452785 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1769#pullrequestreview-6047452785). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T21:09:38Z. **Review:** COMMENTED --- Review of head `3e62f7167f3d0a2c32063db2b477b5f7a7d77871` (tests/startup_translator_check.py only; pure-Python fast path). No P1, no P2. **Scope.** `git diff origin/main...HEAD` touches one file: `tests/startup_translator_check.py` (+20 lines, new `check_numeric_symbol_refusal`, registered in `main`). No C++, no CMakeLists.txt. The head moved since the earlier review (`a511dbb0`) by a merge of main (`3e62f716`); the PR diff itself is unchanged. GitHub `Build and test on Windows`: pass; `Run platform-independent Python checks on Linux`: pass. Mergeable, state CLEAN. **Commands run locally on this head:** - `git diff --check origin/main...HEAD`: rc=0 - `python3 tests/docs_links_check.py`: rc=0 (18 Markdown files, 380 links) - `python3 tests/bidi_controls_check.py`: rc=0 (1342 files) - `python3 tests/startup_translator_check.py`: rc=0 (0 failed) **Mutations in `Stage.S` of `tools/startup/gfx2hlsl.py` (each reverted with `git checkout -- .`, tree clean after):** 1. A ptr/desc register falls through to `s<n>` and is marked used instead of raising: check fails, rc=1 (4 failed: read as s8 and marked used, for both shapes). 2. `used_s.add(n)` before the `raise Unsupported`: check fails, rc=1 (2 failed: marked s8 as used, for both shapes). The new check protects real behaviour: a refused numeric read of a descriptor or buffer-pointer register raises and leaves no `s8` declaration. Windows 2025 runs are not applicable (tests/**/*.py only). This is a review comment, not an approval. AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-24 21:27:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:05:06Z.


Resolved the test overlap with #1767 on main. The root-descriptor key check and this branch's numeric pointer/descriptor refusal both run from startup_translator_check.py, which passed on Windows. No translator behaviour changes in this merge.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7144453726 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1769#issuecomment-7144453726). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T21:05:06Z. --- Resolved the test overlap with #1767 on main. The root-descriptor key check and this branch's numeric pointer/descriptor refusal both run from startup_translator_check.py, which passed on Windows. No translator behaviour changes in this merge.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1762
No description provided.