Stack underflow when `if` used in `raise`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 50/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- fsharp
- Domain
- compilers
Research direction
Start by running the FSI reproduction and comparing the generated IL with the control case; the issue includes the failing repro and ILVerify output. Trace the compiler path for an if expression used as the argument to raise, then verify that the emitted program no longer reports a stack underflow or throws InvalidProgramException.
Written by the indexing model from the issue text.
Description
Repro steps
// run in fsi
open System
let repro (b: bool) = Math.Max (1, raise (Exception (if b then "x" else "y")))
let control (b: bool) = Math.Max (1, String.length (if b then "x" else "y"))
try control true |> ignore; printfn "control: ok" with ex -> printfn "control: %s" (ex.GetType().Name)
try repro true |> ignore; printfn "repro: ok" with ex -> printfn "repro: %s" (ex.GetType().Name)
The original production code looked like
try
...
with ... ->
return raise (SerializationException (if data.Length > 0 then int data.[0] else 0, "index out of range"))
Expected behavior
control: ok
repro: ok
Actual behavior
control: ok
System.InvalidProgramException: Common Language Runtime detected an invalid program.
ILVerify reports [StackUnderflow] Repro::repro(bool) offset 0x0D
IL_0000: ldc.i4.1
IL_0001: ldc.i4.0
IL_0002: brfalse.s IL_000c
IL_0004: ldnull
IL_0005: unbox.any [System.Runtime]System.Int32
IL_000a: br.s IL_0033
IL_000c: stloc.0 // V_0
IL_000d: stloc.1 // V_1 <- saves a second value, but only one is on the stack -> underflow
Known workarounds
Bind the argument first.
Related information
- Win 11, SDK 11.0.100-rc.1.26425.128
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 877
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 139
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/fsharp
-
Needs-Triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Bug Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Needs-Triage
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Needs-Triage
Difficulty 5/5 Over a week Newbie friendliness 48/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
objectionary/jeo-maven-plugin#1758 ·
-
mlir
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
llvm/llvm-project#224908 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
secondlife/sl-vscode-plugin#147 ·