Skip to content

Fix stack underflow when raise is used in an argument position - #20885

Merged
abonie merged 4 commits into
dotnet:mainfrom
pcshrosbree:fix/ilxgen-throw-spill
Nov 27, 2026
Merged

abonie merged 4 commits into
dotnet:mainfrom
pcshrosbree:fix/ilxgen-throw-spill

Conversation

@pcshrosbree

Copy link
Copy Markdown
Contributor

Fixes #20871
Fixes #20564

raise in an argument position produced IL with a stack underflow if building its exception spilled the stack; debug points have caused such spills since #19877. The fake value pushed on the never-taken branch stayed in the code generator's stack model on the path that throws; it is now dropped there.

Note

Prepared with AI assistance (Anthropic Claude, OpenAI Codex). I reviewed the change and the test runs before opening it.

A throw that must leave a value on the stack is emitted with a never-taken branch that pushes a fake value. The code generator also kept that fake value in its stack model on the path that throws. A spill while building the exception, such as one made by EmitDebugPoint, therefore emitted a store of a value that was not on the stack. Restore the stack model on the path that throws and at the join.
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

✅ Release notes checked


✅ Found changes and release notes in following paths:

Change path Release notes path Description
`src/Compiler` docs/release-notes/.FSharp.Compiler.Service/11.0.200.md

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 🕵️ AI review — verify independently.

@T-Gro T-Gro added the AI-reviewed PR reviewed by AI review council label Nov 2, 2026
@T-Gro
T-Gro self-requested a review November 2, 2026 12:25
With `run |> shouldSucceed`, an in-process run accepts any exit code the program returns, including Issue_20564's failure codes 1 and 2. Check for 0 explicitly.

@T-Gro T-Gro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 🕵️ Re-reviewed all recent changes as of 60ee025; LGTM

@pcshrosbree

Copy link
Copy Markdown
Contributor Author

@T-Gro, could this get a maintainer review when you have time? Your automated review on 3 November found nothing further at the current head, and CI is green.

@github-project-automation github-project-automation Bot moved this from New to In Progress in F# Compiler and Tooling Nov 25, 2026
@abonie
abonie enabled auto-merge (squash) November 25, 2026 14:24
@abonie
abonie merged commit 83b761e into dotnet:main Nov 27, 2026
55 checks passed
@pcshrosbree

Copy link
Copy Markdown
Contributor Author

Thank you for the review and merge!

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

Labels

AI-reviewed PR reviewed by AI review council

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

SDK 10.0.402 emits invalid IL for async raise with record copy from static member Stack underflow when if used in raise

3 participants