Skip to content

Lower a type remapped to a fixed-size buffer to a pointer#745

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-unsafe-fixed-size-buffer
Jul 13, 2026
Merged

Lower a type remapped to a fixed-size buffer to a pointer#745
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-fix-unsafe-fixed-size-buffer

Conversation

@tannergooding

Copy link
Copy Markdown
Member

A type remapped to a fixed-size-buffer shape such as sbyte[8] was emitted verbatim, which is not a legal C# type in an unmanaged signature and was not detected as unsafe (yielding CS0214). Lower it to the equivalent pointer in GetRemappedTypeName, matching how C decays an array to a pointer at the ABI boundary. This makes the emission legal and marks the containing member unsafe via the existing * check.

The lowering is gated on a numeric subscript ([<digit>), so a managed array such as int[] (empty subscript) is left untouched.


Notably, no legal C input reaches this path -- real array parameters/returns already decay to *, pointer-to-array (int (*)[8]) decays to int**, and array fields lower to _e__FixedBuffer/InlineArray/fixed. The only trigger is an explicit --remap X=T[N], so this supersedes the substring ] heuristic previously considered for #593; pointer lowering is both legal and correctly unsafe.

Fixes #593

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

A type remapped to a fixed-size-buffer shape such as `sbyte[8]` was emitted verbatim, which is not a legal C# type in an unmanaged signature and was not detected as unsafe. Lower it to the equivalent pointer, matching how C decays an array to a pointer at the ABI boundary; this also marks the containing member unsafe via the existing `*` check.

Fixes dotnet#593

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding tannergooding merged commit 2906ceb into dotnet:main Jul 13, 2026
14 checks passed
@tannergooding tannergooding deleted the tannergooding-fix-unsafe-fixed-size-buffer branch July 13, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing Unsafe for Functions with Fixed Size Buffers

1 participant