[Unsafe evolution] StructLayout with explicitly specified Pack or Size should require unsafe
Open
Area-Language Design
Feature - Unsafe Evolution
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
StructLayout with explicitly specific Pack or Size can be used to create misaligned fields that in turn allows creating misaligned managed references. Safe code must be prohibited from creating unaligned managed references - documented in https://github.com/dotnet/designs/blob/main/accepted/2025/memory-safety/caller-unsafe.md (look for "Alignment of managed references").
Context: https://github.com/dotnet/runtime/issues/133236
Contributor guide
Assessment
This issue has not been assessed yet.