tests: cast the GameInput vtbl slots through const_cast for clang-cl #3868

Merged
triggered02 merged 2 commits from upstream-pr/3868 into main 2026-12-02 16:06:22 +00:00
triggered02 commented 2026-12-02 15:43:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-12-02T15:43:54Z.


Refs #3867.

startup_gameinput_trace.cpp calls through GameInput vtable slots with

using Fn = std::uint64_t(__stdcall*)(IGameInputReading*);
return static_cast<std::uint32_t>(reinterpret_cast<Fn>(vtbl[2])(this));

vtbl is const void* const*, so each reinterpret_cast<Fn>(vtbl[n]) drops const. MSVC accepts that; clang-cl rejects it, which means the documented clang-cl route in docs/non-windows-hosts.md cannot build this device-free executable:

tests/startup_gameinput_trace.cpp(41,43): error: reinterpret_cast from 'const void *' to 'Fn'
  (aka 'unsigned long long (*)(...::IGameInputReading *)') casts away qualifiers
tests/startup_gameinput_trace.cpp(46,16): error: ... 'bool (*)(...IGameInputReading *, GamepadState *)' ...
tests/startup_gameinput_trace.cpp(55,43): error: ... 'unsigned long long (*)(...IGameInput *)' ...
tests/startup_gameinput_trace.cpp(60,16): error: ... 'long (*)(...IGameInput *, unsigned int, void *, ...IGameInputReading **)' ...

Change. Four sites now cast through const_cast<void*> first:

return static_cast<std::uint32_t>(reinterpret_cast<Fn>(const_cast<void*>(vtbl[2]))(this));

Both compilers accept it and nothing changes at runtime: these are vtable slots used for calls, never written through. No test is weakened and no expectation moves.

Verification — Debian, clang-cl 19.1.1 + lld-link, xwin splat SDK 10.0.26100, Release, main at 0939575e:

before: cmake --build out/build/clang --target startup_gameinput_trace
        -> FAILED, 4 x "casts away qualifiers"
after:  -> [2/2] Linking CXX executable startup_gameinput_trace.exe

Not established. No MSVC here, so the MSVC side is unchanged-by-inspection; Windows CI is the check. This is only the first of the three gaps in #3867 — the frontend crash in xmem_commit_protection_check and the unresolved intrinsics in startup_host_cpu_probe are reported there and not touched here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5609822509 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3868). Originally posted by [triggered02](https://github.com/triggered02) on 2026-12-02T15:43:54Z. --- Refs #3867. `startup_gameinput_trace.cpp` calls through GameInput vtable slots with ```cpp using Fn = std::uint64_t(__stdcall*)(IGameInputReading*); return static_cast<std::uint32_t>(reinterpret_cast<Fn>(vtbl[2])(this)); ``` `vtbl` is `const void* const*`, so each `reinterpret_cast<Fn>(vtbl[n])` drops `const`. MSVC accepts that; clang-cl rejects it, which means the documented clang-cl route in `docs/non-windows-hosts.md` cannot build this device-free executable: ``` tests/startup_gameinput_trace.cpp(41,43): error: reinterpret_cast from 'const void *' to 'Fn' (aka 'unsigned long long (*)(...::IGameInputReading *)') casts away qualifiers tests/startup_gameinput_trace.cpp(46,16): error: ... 'bool (*)(...IGameInputReading *, GamepadState *)' ... tests/startup_gameinput_trace.cpp(55,43): error: ... 'unsigned long long (*)(...IGameInput *)' ... tests/startup_gameinput_trace.cpp(60,16): error: ... 'long (*)(...IGameInput *, unsigned int, void *, ...IGameInputReading **)' ... ``` **Change.** Four sites now cast through `const_cast<void*>` first: ```cpp return static_cast<std::uint32_t>(reinterpret_cast<Fn>(const_cast<void*>(vtbl[2]))(this)); ``` Both compilers accept it and nothing changes at runtime: these are vtable slots used for calls, never written through. No test is weakened and no expectation moves. **Verification** — Debian, clang-cl 19.1.1 + lld-link, `xwin splat` SDK 10.0.26100, Release, `main` at `0939575e`: ``` before: cmake --build out/build/clang --target startup_gameinput_trace -> FAILED, 4 x "casts away qualifiers" after: -> [2/2] Linking CXX executable startup_gameinput_trace.exe ``` **Not established.** No MSVC here, so the MSVC side is unchanged-by-inspection; Windows CI is the check. This is only the first of the three gaps in #3867 — the frontend crash in `xmem_commit_protection_check` and the unresolved intrinsics in `startup_host_cpu_probe` are reported there and not touched here.
chatgpt-codex-connector[bot] commented 2026-12-02 15:44:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-12-02T15:44:04Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T15:45:28.424326Z 7ad9c36 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7350828147 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3868#issuecomment-7350828147). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-12-02T15:44:04Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7ad9c36b924a1161195a12bf97378f3484337986","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-12-02T15:45:28.424326Z">2026-12-02T15:45:28.424326Z</relative-time> | `7ad9c36` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
R0Y00 commented 2026-12-02 15:58:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T15:58:33Z.

Review: APPROVED


Reviewed f33f2107. The four calls keep their vtable indices, signatures and receivers. The explicit const cast only normalizes the intermediate pointer conversion. The GameInput test and shim built with MSVC Debug at 7ad9c36b. The merged head leaves the GameInput fixture source unchanged. The runtime test returned capability skip 77 because XInput pad 0 is connected. The clang-cl build result is from the author.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6154408497 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3868#pullrequestreview-6154408497). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T15:58:33Z. **Review:** APPROVED --- Reviewed f33f2107. The four calls keep their vtable indices, signatures and receivers. The explicit const cast only normalizes the intermediate pointer conversion. The GameInput test and shim built with MSVC Debug at 7ad9c36b. The merged head leaves the GameInput fixture source unchanged. The runtime test returned capability skip 77 because XInput pad 0 is connected. The clang-cl build result is from the author.
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!3868
No description provided.