tests: record SEH faults through a sink so clang-cl can build the probe #3871

Manually merged
github merged 2 commits from github-bot/gh-3869 into gh-pr/3869/base 2026-12-02 15:59:11 +00:00 AGit
Owner

@⁠triggered02 on GitHub · 2026-12-02 15:46 UTC · original
triggered02:fix/xmem-seh-clang-crash → main · +22 −8 · 1 files · 2 commits · merged 2026-12-02 15:58 UTC

Refs #3869. Second of the three gaps in that report — this one is a compiler crash, not a warning.

The crash. clang 19.1.1 dies in the frontend with exit 139 while outlining the SEH filter in this file:

clang-cl: error: clang frontend command failed with exit code 139
 #5 clang::CodeGen::CodeGenFunction::recoverAddrOfEscapedLocal
 #6 clang::CodeGen::CodeGenFunction::EmitCapturedLocals
 #7 clang::CodeGen::CodeGenFunction::startOutlinedSEHHelper
 #8 clang::CodeGen::CodeGenFunction::GenerateSEHFilterFunction

Reduced to ~20 lines. The trigger is an __except filter expression that both calls the GetExceptionInformation() intrinsic and takes the address of an escaping local:

Filter form Result
capture_fault(GetExceptionInformation(), &info) crash
capture_fault(plain_ep(), &info) — same shape, no intrinsic builds
capture_fault(GetExceptionInformation()) — no captured local builds

So the captured local is what clang must recover inside the outlined filter, and it fails only when the filter also references the exception record. The reproducer is small enough to report upstream; I have not filed it with LLVM, so say if you would rather I did.

Change. The filter captures nothing and records into a thread_local sink that the probe sets immediately before __try and clears after:

thread_local FaultInfo* fault_sink = nullptr;
DWORD capture_fault(EXCEPTION_POINTERS* ep) noexcept { FaultInfo* out = fault_sink; ... }
...
fault_sink = &info;
__try { *ptr = value; } __except (capture_fault(GetExceptionInformation())) { }
fault_sink = nullptr;

The fields written, their order and the return value are unchanged. The probe loop is single-threaded, and thread_local keeps it correct if that ever changes. MSVC accepts both forms, so this is not a workaround that costs MSVC anything.

Verified — Debian, clang-cl 19.1.1, xwin splat SDK 10.0.26100, Release, main 0939575e:

before: cmake --build out/build/clang --target xmem_commit_protection_check
        -> clang frontend command failed with exit code 139
after:  -> [2/2] Linking CXX executable xmem_commit_protection_check.exe

Not established. I could not run it: the executable imports xmem.dll and does not start under Wine here, so behaviour preservation is by construction, not measured. The Windows job is the real check for both correctness and the MSVC side.

**@⁠triggered02** on GitHub · 2026-12-02 15:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3869) `triggered02:fix/xmem-seh-clang-crash` → `main` · +22 −8 · 1 files · 2 commits · merged 2026-12-02 15:58 UTC Refs #3869. Second of the three gaps in that report — this one is a **compiler crash**, not a warning. **The crash.** `clang 19.1.1` dies in the frontend with exit 139 while outlining the SEH filter in this file: ``` clang-cl: error: clang frontend command failed with exit code 139 #5 clang::CodeGen::CodeGenFunction::recoverAddrOfEscapedLocal #6 clang::CodeGen::CodeGenFunction::EmitCapturedLocals #7 clang::CodeGen::CodeGenFunction::startOutlinedSEHHelper #8 clang::CodeGen::CodeGenFunction::GenerateSEHFilterFunction ``` **Reduced to ~20 lines.** The trigger is an `__except` filter expression that *both* calls the `GetExceptionInformation()` intrinsic *and* takes the address of an escaping local: | Filter form | Result | |---|---| | `capture_fault(GetExceptionInformation(), &info)` | **crash** | | `capture_fault(plain_ep(), &info)` — same shape, no intrinsic | builds | | `capture_fault(GetExceptionInformation())` — no captured local | builds | So the captured local is what clang must recover inside the outlined filter, and it fails only when the filter also references the exception record. The reproducer is small enough to report upstream; I have not filed it with LLVM, so say if you would rather I did. **Change.** The filter captures nothing and records into a `thread_local` sink that the probe sets immediately before `__try` and clears after: ```cpp thread_local FaultInfo* fault_sink = nullptr; DWORD capture_fault(EXCEPTION_POINTERS* ep) noexcept { FaultInfo* out = fault_sink; ... } ... fault_sink = &info; __try { *ptr = value; } __except (capture_fault(GetExceptionInformation())) { } fault_sink = nullptr; ``` The fields written, their order and the return value are unchanged. The probe loop is single-threaded, and `thread_local` keeps it correct if that ever changes. MSVC accepts both forms, so this is not a workaround that costs MSVC anything. **Verified** — Debian, clang-cl 19.1.1, `xwin splat` SDK 10.0.26100, Release, `main` 0939575e: ``` before: cmake --build out/build/clang --target xmem_commit_protection_check -> clang frontend command failed with exit code 139 after: -> [2/2] Linking CXX executable xmem_commit_protection_check.exe ``` **Not established.** I could not *run* it: the executable imports `xmem.dll` and does not start under Wine here, so behaviour preservation is by construction, not measured. The Windows job is the real check for both correctness and the MSVC side.
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.
clang 19.1.1 crashes in the frontend (exit 139, SIGSEGV) while outlining the
SEH filter in this file:

  clang::CodeGen::CodeGenFunction::recoverAddrOfEscapedLocal
  clang::CodeGen::CodeGenFunction::EmitCapturedLocals
  clang::CodeGen::CodeGenFunction::startOutlinedSEHHelper
  clang::CodeGen::CodeGenFunction::GenerateSEHFilterFunction

The trigger is an __except filter expression that both calls the
GetExceptionInformation() intrinsic and takes the address of an escaping local,
here '&info'. Reduced to ~20 lines and confirmed: the same filter with a plain
pointer argument builds, the same filter taking no local address builds, only the
intrinsic plus the captured local crashes.

So the filter now captures nothing: it records into a thread_local sink that the
probe sets immediately before __try and clears after. The fields written, their
order and the return value are unchanged; the probe loop is single-threaded and
thread_local keeps it correct if that changes.

Verified on Debian with clang-cl 19.1.1 and an xwin SDK 10.0.26100 splat, main
0939575e:
  before: cmake --build out/build/clang --target xmem_commit_protection_check
          -> clang frontend command failed with exit code 139
  after:  -> [2/2] Linking CXX executable xmem_commit_protection_check.exe
Not run: the executable imports xmem.dll and does not start under Wine here, so
the behaviour preservation is by construction, not measured. MSVC is unaffected:
it accepted both forms.

Refs #3867
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 15:50:20 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-12-02 15:46 UTC · original · edited 2026-12-02 15:48 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:48:07.286151Z c7a5e6d 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:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3869#issuecomment-7350907805) · edited 2026-12-02 15:48 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"c7a5e6d33dab5875e0d6890d656a577a63735611","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:48:07.286151Z">2026-12-02T15:48:07.286151Z</relative-time> | `c7a5e6d` | 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>
github-bot changed target branch from main to gh-pr/3869/base 2026-12-02 15:58:59 +00:00
github manually merged commit c7a5e6d33d into gh-pr/3869/base 2026-12-02 15:59:11 +00:00
Author
Owner

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

I reviewed c7a5e6d3 and verified the probe on Windows/MSVC Debug. cmake --build --preset dev --target xmem_commit_protection_check xmem_shim completed, and ctest --preset dev --no-tests=error -j 1 -R '^xmem_commit_protection$' --output-on-failure passed 1/1. Both probe paths set and clear the thread-local sink, and the handled exception still records its operation and address. The clang-cl 19.1.1 build evidence is from the author.

**@⁠R0Y00** on GitHub · 2026-12-02 15:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3869#pullrequestreview-6154394219) · **approved these changes** I reviewed c7a5e6d3 and verified the probe on Windows/MSVC Debug. `cmake --build --preset dev --target xmem_commit_protection_check xmem_shim` completed, and `ctest --preset dev --no-tests=error -j 1 -R '^xmem_commit_protection$' --output-on-failure` passed 1/1. Both probe paths set and clear the thread-local sink, and the handled exception still records its operation and address. The clang-cl 19.1.1 build evidence is from the author.
This discussion has been locked. Commenting is limited to contributors.
No description provided.