Skip to content

JIT: (bug) Reinterpreting a one-byte load as a float reads four bytes #133580

Closed

Description

@EgorBo

Repro

using System;
using System.Runtime.CompilerServices;

class Program
{
    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static unsafe uint Test(byte* p)
    {
        return BitConverter.SingleToUInt32Bits(BitConverter.Int32BitsToSingle(*p));
    }

    static unsafe void Main()
    {
        byte* buf = stackalloc byte[4];
        buf[0] = 0x01;
        buf[1] = 0x02;
        buf[2] = 0x03;
        buf[3] = 0x04;
        Console.WriteLine(Test(buf).ToString("X8"));
    }
}

Expected

00000001

Actual

04030201

A Checked build additionally asserts while jitting Test:

Assertion failed 'varTypeIsInt(op1)' in 'Program:Test(ptr):uint' during 'Importation'

The single-byte load is turned into a four-byte load, so the three adjacent bytes leak into the
result; a ushort* source is widened to four bytes the same way.

Platform

Windows x64, .NET 11 (dotnet/runtime main @ a0b86b1). Reproduces on both Checked and Release
builds with DOTNET_TieredCompilation=0; no special CPU features needed.

Activity

  1. added this to the 12.0.0 milestone on Sep 10, 2026
  2. added
    area-CodeGen-coreclr
    on Sep 10, 2026
  3. dotnet-policy-service commented on Sep 10, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. self-assigned this
    on Sep 10, 2026
  5. added a commit that references this issue on Sep 14, 2026
    c87bb8c
  6. added a commit that references this issue on Sep 18, 2026
    73b8a68
  7. EgorBo commented on Sep 18, 2026

    @EgorBo
    MemberAuthor

    Affected SDK versions:

    • 10.0.401
    • 11.0.100-rc.2.26467.112
  8. locked and limited conversation to collaborators on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions