Skip to content

[wasm][interp] conv.i8 of a managed pointer on 32-bit stops the runtime ("transform.c:1132", Store local stack type mismatch) or returns a garbage high word #137923

Open

Description

@LostBeard

Description

In Blazor WebAssembly (Mono interpreter, wasm32), (long) of an Unsafe.AsPointer result, inlined into a method, stops the
.NET runtime while the interpreter compiles that method. The browser console shows

[MONO] /__w/1/s/src/runtime/src/mono/mono/mini/interp/transform.c:1132 <disabled>

and nothing in the page's .NET code runs after that. Where the converted value is not stored into a local, the conversion
instead returns a 64-bit value whose low 32 bits are right and whose high 32 bits are garbage.

Reproduction Steps

Live page (runs by itself, controls first): https://lostbeard.github.io/dotnet-wasm-aspointer-long-test/
Source: https://github.com/LostBeard/dotnet-wasm-aspointer-long-test

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static unsafe long AsPointerToLong(uint address) => (long)(IntPtr)Unsafe.AsPointer(ref Unsafe.AsRef<byte>((void*)address));

for (int round = 0; round < 100_000; round++)
{
    uint a = 2654435761u * (uint)(round + 1) & 0x7FFF_FFF0u;
    long got = AsPointerToLong(a);           // the runtime stops here
    if (got != a) wrong++;
}

Expected behavior

got == a (the pointer is never dereferenced), as on desktop .NET and in the ahead-of-time compiled build.

Actual behavior

Build Runtime Result
.NET 10 default (interpreter + jiterpreter), the live page (built by GitHub Actions) 10.0.15 runtime stops, transform.c:1132
.NET 10 default (interpreter + jiterpreter) 10.0.14 runtime stops, transform.c:1132
.NET 10 interpreter only (BlazorWebAssemblyJiterpreter=false) 10.0.14 runtime stops, transform.c:1132
.NET 10 ahead-of-time (RunAOTCompilation) 10.0.14 right (100,000 of 100,000)
.NET 9 default 9.0.22 runtime stops, transform.c:1132
.NET 8 default 8.0.33 runtime stops, transform.c:1146

Controls on the same page are right in every build: (long)(ulong)Unsafe.AsPointer(...) (conv.u8), (long)(nint)address,
and the same (long)(IntPtr)Unsafe.AsPointer(...) in its own [NoInlining] method.

Windows 11, Chrome 157.

Regression?

Not a recent one: .NET 8, 9 and 10 behave the same.

Known Workarounds

Avoid conv.i8 of a managed pointer: convert through (ulong) / (nuint), or compute addresses with integer arithmetic.

Configuration

Blazor WebAssembly, browser-wasm, IntPtr.Size == 4.

Other information

The cause appears to be in src/mono/mono/mini/interp/transform.c (v10.0.14; the same on main today):

  • Unsafe.AsPointer is a no-op typing the value STACK_TYPE_MP (L2162).

  • CEE_CONV_I8, STACK_TYPE_MP, 32-bit (L6593-L6595):

    case STACK_TYPE_MP:
    #if SIZEOF_VOID_P == 4
        interp_add_ins (td, MINT_CONV_I8_I4);

    interp_add_ins adds the instruction without source/destination registers and the stack entry keeps its 4-byte MP type.
    The CEE_CONV_U8 MP case (L6671)
    uses interp_add_conv (td, td->sp - 1, STACK_TYPE_I8, MINT_CONV_I8_U4);.

  • Stored into a long local, store_local then hits g_error ("%s.%s: Store local stack type mismatch %d %d", ...)
    (L1130); its implicit
    nint/int32 conversions are #if SIZEOF_VOID_P == 8 only.

The likely fix: interp_add_conv (td, td->sp - 1, STACK_TYPE_I8, MINT_CONV_I8_I4); in that case.

Found in SpawnDev.ILGPU, where a device copy computed (long)view.LoadEffectiveAddressAsPtr() (new IntPtr(Unsafe.AsPointer(ref ...)))
and, in a busy page (after tier-up inlining), got offsets such as 30064771072 (= 7 * 2^32) and 412316860744 (= 96 * 2^32 + 328):
right low word, garbage high word. It now computes the address with integer arithmetic.

Activity

  1. added a commit that references this issue on Nov 19, 2026
  2. dotnet-policy-service commented on Nov 19, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @vitek-karas, @BrzVlad, @kotlarmilos
    See info in area-owners.md if you want to be subscribed.

  3. kotlarmilos commented on Nov 20, 2026

    @kotlarmilos
    Member

    @pavelsavara Could you please take a look?

  4. dotnet-policy-service commented on Nov 20, 2026

    @dotnet-policy-service
    Contributor

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

  5. added this to the 11.0.0 milestone on Nov 20, 2026
  6. removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions