Registry Mirror
Skip to content

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Follow-up to #830. That PR added the address-of for an inline-array field decayed to a pointer, but the same logic also fired on a subscripted field lvalue.

IN6_SET_ADDR_LOOPBACK emitted:

 NativeMemory.Fill(&a->u.Byte, (uint)(sizeof(IN6_ADDR)), 0); // correct
-a->u.Byte[15] = 1;
+&a->u.Byte[15] = 1; // CS0131

A subscript indexes the inline array in place, so the decay feeding it is an lvalue, not a pointer bind. Skip the address-of when the decayed field is the base of an ArraySubscriptExpr (via IsPrevContextStmt<ArraySubscriptExpr>); the call-argument case still gets &, and compatible mode is unaffected.

Verified across all four configs: Default/Latest/Preview keep &pStruct->Data on the argument and emit a clean pStruct->Data[15] = 1; Compatible has no & on either. Extended ArrayFieldToPointerArgumentTest with the subscript assignment; full suite green (4205 passed, 0 failed).

The inline-array address-of also fired on a subscripted field lvalue, emitting
`&a->Byte[15] = 1` (CS0131). A subscript indexes the inline array in place, so
the decay there is an lvalue, not a pointer bind. Skip the address-of when the
decayed field is the base of an ArraySubscriptExpr.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit dbfa51b into dotnet:main Jul 19, 2026
12 checks passed
@tannergooding
tannergooding deleted the fix-inline-array-subscript-addressof branch July 19, 2026 20:02
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.

1 participant