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

Merged
triggered02 merged 2 commits from upstream-pr/3869 into main 2026-12-02 15:58:49 +00:00
triggered02 commented 2026-12-02 15:46:42 +00:00 (Migrated from github.com)

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


Refs #3867. 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5609870991 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3869). Originally posted by [triggered02](https://github.com/triggered02) on 2026-12-02T15:46:42Z. --- Refs #3867. 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.
chatgpt-codex-connector[bot] commented 2026-12-02 15:46:54 +00:00 (Migrated from github.com)

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


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7350907805 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3869#issuecomment-7350907805). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/apps/chatgpt-codex-connector) on 2026-12-02T15:46:54Z. --- <!-- 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>
R0Y00 commented 2026-12-02 15:57:45 +00:00 (Migrated from github.com)

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

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6154394219 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3869#pullrequestreview-6154394219). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T15:57:45Z. **Review:** APPROVED --- 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.
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!3869
No description provided.