Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Program crashes on second hot reload with stackalloc on method body #69027

Closed
isadorasophia opened this issue Jul 13, 2023 · 2 comments · Fixed by #69059
Closed

Program crashes on second hot reload with stackalloc on method body #69027

isadorasophia opened this issue Jul 13, 2023 · 2 comments · Fixed by #69059
Assignees
Milestone

Comments

@isadorasophia
Copy link
Contributor

Version Used: 17.7 Preview 3

Steps to Reproduce:

  1. Debug the following app
namespace ExceptionSample
{
    internal class Program
    {
        static void Main(string[] args)
        {
            bool something = false;
            if (!something) // break here
            { 
                // edit 1: add lines here
                Span<bool> stuff = stackalloc bool[64];
                // edit 2: add lines
            }
        }
    }
}
  1. Add lines on first edit and apply code changes
  2. Add lines on second edit and apply code changes

Expected Behavior:
Successfully applied changes.

Actual Behavior:
App immediately crashes and exits with:

Fatal error. Unspecified error (0x80004005 (E_FAIL))
   at ExceptionSample.Program.Main(System.String[])

Remarks
The hot reload itself was successful:

13:37 25.53 Starting session.
13:37 35.38 Checking for updates...
13:37 35.42 Applying updates...
13:37 35.43 ConsoleApp39 (2): Sending updates to running application.
13:37 35.43 Changes were successfully applied.
13:37 35.53 ConsoleApp39 (2): Updates applied successfully.
13:37 47.40 Checking for updates...
13:37 47.45 Applying updates...
13:37 47.45 ConsoleApp39 (2): Sending updates to running application.
13:37 47.45 ConsoleApp39 (2): Updates applied successfully.
13:37 47.45 Changes were successfully applied.
13:37 48.18 Ending session.
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 13, 2023
@isadorasophia
Copy link
Contributor Author

@tmat fyi

@tmat tmat self-assigned this Jul 13, 2023
@tmat tmat removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 13, 2023
@tmat tmat added this to the 17.8 milestone Jul 13, 2023
@tmat
Copy link
Member

tmat commented Jul 15, 2023

Simpler repro:

using System;

internal class Program
{
    static void Main()
    {
        Span<bool> stuff = stackalloc bool[64];
    }
}

Insert comment anywhere in the variable declaration statement.

Deltas we emit:
Repro.zip

The compiler doesn't correctly map variables (the IL should be unchanged):

Original:

Method 'Program.Main' (0x06000006)
  Locals: System.Span`1<bool>, System.Span`1<bool> (#1b)
{
  // Code size       17 (0x11)
  .maxstack  2
  IL_0000:  nop
  IL_0001:  ldc.i4.s   64
  IL_0003:  conv.u
  IL_0004:  localloc
  IL_0006:  ldc.i4.s   64
  IL_0008:  newobj     'System.Span`1<bool>..ctor' (0x0a00000e)
  IL_000d:  stloc.1
  IL_000e:  ldloc.1
  IL_000f:  stloc.0
  IL_0010:  ret
}

Delta:

Method 'Program.Main' (0x06000006)
  Locals: System.Span`1<bool>, System.Span`1<bool>, System.Span`1<bool> (#19d/1:1)
{
  // Code size       17 (0x11)
  .maxstack  2
  IL_0000:  nop
  IL_0001:  ldc.i4.s   64
  IL_0003:  conv.u
  IL_0004:  localloc
  IL_0006:  ldc.i4.s   64
  IL_0008:  newobj     'System.Span`1<bool>..ctor' (0x0a000014/1:1)
  IL_000d:  stloc.2
  IL_000e:  ldloc.2
  IL_000f:  stloc.0
  IL_0010:  ret
}

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

Successfully merging a pull request may close this issue.

3 participants