-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Description
Version Used: Microsoft.Net.Compilers.Toolset 4.4.0-2.22379.18 (current daily build)
Steps to Reproduce:
- Build
using System;
using System.Reflection;
using System.Runtime.InteropServices;
unsafe
{
StructWithRefField* p = stackalloc StructWithRefField[10];
MyClass o = new();
// This has GC hole. The stackallocated array of StructWithRefField is not reported to GC
p[0].RefField = ref o.ByteField;
}
ref struct StructWithRefField
{
public ref byte RefField;
}
class MyClass
{
public byte ByteField;
}sharplab is crashing on this repro.
Expected Behavior:
Build error. stackalloc should be disallowed for structs with ref fields.
Actual Behavior:
Builds successfully, the program has GC hole at runtime.
Reactions are currently unavailable