Skip to content

[X86] Preserve source SEH state ordering during nonlocal unwind - #4

Merged
gmh5225 merged 1 commit into
mainfrom
codex/x86-seh-unwind-state-order
Oct 15, 2026
Merged

gmh5225 merged 1 commit into
mainfrom
codex/x86-seh-unwind-state-order

Conversation

@gmh5225

@gmh5225 gmh5225 commented Oct 15, 2026 •

Copy link
Copy Markdown

A rewritten x86 SEH function can capture state 1, activate a finally at state 4, and longjmp back. The existing depth-first scope numbering can map source rows 0,1,2,3,4 to 0,3,4,1,2. MSVC local unwind compares current and saved states numerically, so the generated function stops before running the finally. Preserving enclosing links alone does not preserve this protocol.

For x86 MSVC functions carrying the registration-state rewrite attribute and complete scope identities, order rows by source state before assigning invoke/asynchronous states. Remap enclosing links and pad states together; reject duplicate identities and enclosing states that do not precede their scopes. Keep this logic in separate CodeGen files. Ordinary frontend and incomplete/unannotated graphs retain their existing numbering.

Validation:

  • A new regression fails on the previous compiler and passes at O0/O2, with and without IR optimization, with COFF emission. Duplicate identities and invalid enclosing order are rejected.
  • Existing callback state assembly, final-image receipt, malformed IR and MC tests pass; the existing EH4 cookie realignment RUN check passes.
  • The previously failing five-scope PE32 fixture passes 20 original/reconstructed/product/CLI/rebased executions under Wine with Microsoft x86 CRT. NeverD also independently checks the resulting numeric state order. The full 60-scenario runtime matrix also passed all 1,200 executions in NeverD PR #1016.

@gmh5225
gmh5225 merged commit 4a949c0 into main Oct 15, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

Hello @gmh5225 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants