Repository: dotnet/runtime
File: src/coreclr/jit/emitwasm.cpp (C++)

Code before:
            }
        }
    };

    // The reference for the following style of display is wasm-objdump output.
    //
    switch (fmt)
    {
        case IF_OPCODE:
        case IF_BLOCK:
            break;

        case IF_RAW_ULEB128:
        case IF_ULEB128:
        {
            cnsval_ssize_t imm = emitGetInsSC(id);
            printf(" %llu", (uint64_t)imm);
            dispJumpTargetIfAny();
        }
        break;

        case IF_LOCAL_DECL:
        {
            cnsval_ssize_t count   = emitGetLclVarDeclCount(id);
            WasmValueType  valType = emitGetLclVarDeclType(id);
            int            offs    = id->idDebugOnlyInfo()->lclOffset;
            assert(count > 0); // we should not be declaring a local entry with zero count

            if (m_debugInfoSize > 0)
            {
                // With debug info: print the local offsets being declared
                if (count > 1)
                {
                    printf("[%llu..%llu] type=%s", offs, offs + (uint64_t)count - 1, WasmValueTypeName(valType));
                }
                else // single local case
                {
                    printf("[%llu] type=%s", offs, WasmValueTypeName(valType));
                }
            }
            else
            {
                // No debug info case: just print the count and type of the locals
                printf(" count=%llu type=%s", (uint64_t)count, WasmValueTypeName(valType));
                break;
            }
        }
        break;

        case IF_SLEB128:
        {

Review comment (bug):
I would move this down to the `if (m_debugInfoSize > 0)` branch. Right now it is going to access nominally uninitialized memory with `m_debugInfoSize == 0`.

Code after:
        }
    };

    // The reference for the following style of display is wasm-objdump output.
    //
    switch (fmt)
    {
        case IF_OPCODE:
        case IF_BLOCK:
            break;

        case IF_RAW_ULEB128:
        case IF_ULEB128:
        {
            cnsval_ssize_t imm = emitGetInsSC(id);
            printf(" %llu", (uint64_t)imm);
            dispJumpTargetIfAny();
        }
        break;

        case IF_LOCAL_DECL:
        {
            unsigned int  count   = emitGetLclVarDeclCount(id);
            WasmValueType valType = emitGetLclVarDeclType(id);
            assert(count > 0); // we should not be declaring a local entry with zero count

            if (m_debugInfoSize > 0)
            {
                // With debug info: print the local offsets being declared
                int offs = id->idDebugOnlyInfo()->lclOffset;
                if (count > 1)
                {
                    printf("[%u..%u] type=%s", offs, offs + count - 1, WasmValueTypeName(valType));
                }
                else // single local case
                {
                    printf("[%u] type=%s", offs, WasmValueTypeName(valType));
                }
            }
            else
            {
                // No debug info case: just print the count and type of the locals
                printf(" count=%u type=%s", count, WasmValueTypeName(valType));
            }
        }
        break;

        case IF_SLEB128:
        {
            cnsval_ssize_t imm = emitGetInsSC(id);
            printf(" %lli", (int64_t)imm);