Since #19548 inline functions are not inlined in debug builds, including those where inlining is not negotiable.
Repro steps
open System
open FSharp.NativeInterop
#nowarn 9
// without inlining the returned Span points at a stack position that is no longer valid
let inline stackalloc<'a when 'a: unmanaged> length =
Span<'a> (NativePtr.stackalloc<'a> length |> NativePtr.toVoidPtr, length)
let rec clobber n =
let mutable a = int64 n
let mutable b = a * 2L
let mutable c = b * 2L
let mutable d = c * 2L
if n > 0 then clobber (n - 1) + int (a + b + c + d) else 0
let demo () =
let b = stackalloc<char> 3
b.[0] <- 'a'
b.[1] <- 'b'
b.[2] <- 'c'
clobber 64 |> ignore
String b
let r = demo ()
printfn "expected: \"abc\" [97; 98; 99]"
printfn "actual: %A %A" r (r |> Seq.map int |> Seq.toList)
Expected behavior
> dotnet fsi .\stackalloc-inline-repro.fsx
expected: "abc" [97; 98; 99]
actual: "abc" [97; 98; 99]
> dotnet fsi --optimize- .\stackalloc-inline-repro.fsx
expected: "abc" [97; 98; 99]
actual: "abc" [97; 98; 99]
Actual behavior
> dotnet fsi .\stackalloc-inline-repro.fsx
expected: "abc" [97; 98; 99]
actual: "abc" [97; 98; 99]
> dotnet fsi --optimize- .\stackalloc-inline-repro.fsx
expected: "abc" [97; 98; 99]
actual: "?" [63; 0; 0]
Known workarounds
Optimize debug builds.
Related information
SDK 11.0.100-preview.6.26359.118
Since #19548
inlinefunctions are not inlined in debug builds, including those where inlining is not negotiable.Repro steps
Expected behavior
Actual behavior
Known workarounds
Optimize debug builds.
Related information
SDK 11.0.100-preview.6.26359.118