Skip to content

Non-optimized inlining regression #20063

Description

@kerams

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions