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

Manually merged
github merged 2 commits from github-bot/gh-3868 into gh-pr/3868/base 2026-12-02 16:18:07 +00:00 AGit
Owner

@⁠triggered02 on GitHub · 2026-12-02 15:43 UTC · original
triggered02:fix/gameinput-trace-clang-const → main · +4 −4 · 1 files · 2 commits · merged 2026-12-02 16:06 UTC

Refs #3869.

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 #3869 — the frontend crash in xmem_commit_protection_check and the unresolved intrinsics in startup_host_cpu_probe are reported there and not touched here.

**@⁠triggered02** on GitHub · 2026-12-02 15:43 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3868) `triggered02:fix/gameinput-trace-clang-const` → `main` · +4 −4 · 1 files · 2 commits · merged 2026-12-02 16:06 UTC Refs #3869. `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 #3869 — the frontend crash in `xmem_commit_protection_check` and the unresolved intrinsics in `startup_host_cpu_probe` are reported there and not touched here.
The four vtable calls in startup_gameinput_trace.cpp reinterpret_cast a
'const void*' (vtbl is 'const void* const*') straight to a function pointer.
MSVC accepts that; clang-cl rejects it:

  error: reinterpret_cast from 'const void *' to 'Fn' casts away qualifiers

so the documented clang-cl cross-compile in docs/non-windows-hosts.md could not
build this device-free test executable. Casting through const_cast<void*> first
is accepted by both compilers and changes no behaviour: the pointers are vtable
slots used for calls, not written through.

Verified on Debian, clang-cl 19.1.1, xwin SDK 10.0.26100, main 0939575e:
  before: cmake --build out/build/clang --target startup_gameinput_trace
          -> 4 x 'casts away qualifiers'
  after:  -> startup_gameinput_trace.exe links (lld-link)
The MSVC side is unchanged by inspection; Windows CI is the check for it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 15:50:17 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-02 15:44 UTC · original · edited 2026-12-02 15:45 UTC

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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-12-02 15:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3868#issuecomment-7350828147) · edited 2026-12-02 15:45 UTC <!-- 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>
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 15:58 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-12-02 15:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3868#pullrequestreview-6154408497) · **approved these changes** 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.
github-bot changed target branch from main to gh-pr/3868/base 2026-12-02 16:18:02 +00:00
github manually merged commit f33f2107b3 into gh-pr/3868/base 2026-12-02 16:18:07 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.