Extra tail instruction corrupts stack?
See original GitHub issueRepro steps
Clone https://github.com/kerams/repro/, open Program.fs, target either net6.0
or net7.0
, run in Release mode.
Expected behavior
Byte - 53, in total 1
[|146uy; 1uy; 53uy|]
Printed 10 times.
Actual behavior
This is printed the first 2 times:
Byte - 53, in total 1
[|146uy; 1uy; 0uy|]
Byte - 53, in total 1
[|146uy; 1uy; 112uy|]
Known workarounds
Remove [<Struct>]
from MyResult
.
OR
Put ()
at the end of the writeString
function. The before and after diff is here. That extra tail instruction is a bit suspicious.
Related information
dotnet --info
.NET SDK: Version: 7.0.100-preview.5.22307.18 Commit: bd8b088037Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100-preview.5.22307.18\
global.json file: Not found
Host: Version: 7.0.0-preview.5.22301.12 Architecture: x64 Commit: 425fedc0fb
.NET SDKs installed: 6.0.400-preview.22301.10 [C:\Program Files\dotnet\sdk] 7.0.100-preview.5.22307.18 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0-preview.5.22303.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0-preview.5.22301.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0-preview.5.22302.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Issue Analytics
- State:
- Created a year ago
- Comments:18 (18 by maintainers)
Top GitHub Comments
The call is passing a
Span<byte>
that is pointing to local stack memory. Looks like F#'s address exposure analysis is incorrect here, it should not be marking the call astail.
when it takes byrefs that might point to the local frame.The same argument applies, SysV ABI (used on Intel Macs) probably does not need the portable tailcall helper for the call to
writeString
while windows-x64 ABI does.