Skip to content

WasmLowering: Empty struct detection doesn't exist for ABI purposes, and should #127361

Open

Description

@davidwrighton

The WebAssembly Basic C ABI (https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md) specifies that empty structs and unions are "ignored" for both parameters and returns. In WasmLowering.GetSignature, empty struct parameters are currently detected via
paramType.GetElementSize().AsInt == 0. However, .NET pads empty value types to a minimum size of 1 byte:

// MetadataFieldLayoutAlgorithm.cs:1177
// Pad the length of structs to be 1 if they are empty, so we have no zero-length structures
if (type.IsValueType && instanceSize == LayoutInt.Zero)
instanceSize = LayoutInt.One;

What needs to change

  1. Detect empty structs by instance field count (0 non-static fields), no explicit layout.
  2. Empty struct return/parameters should not contribute to the arguments of the function at the Wasm level.
  3. This applies to all calling conventions (managed and unmanaged).

Location

src/coreclr/tools/Common/JitInterface/WasmLowering.cs — the GetSignature(MethodSignature, LoweringFlags) method.

Activity

  1. added
    untriaged
    on Apr 23, 2026
  2. added
    arch-wasm
    on Jul 1, 2026
  3. added this to the 11.0.0 milestone on Jul 1, 2026
  4. removed
    untriaged
    on Jul 1, 2026
  5. dotnet-policy-service commented on Jul 1, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
    See info in area-owners.md if you want to be subscribed.

  6. modified the milestones: 11.0.0, 12.0.0 on Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-wasmarea-TypeSystem-coreclr

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions