Skip to content

JIT: (bug) single-field struct copy into a short local skips normalization (assert 'srcFld->IsIntegralConst()' / wrong value) #135394

Description

@EgorBo

Copying a single-short-field struct into a short local via Unsafe.As<short, W> skips the sign-extension, so Test returns 65535 instead of -1 (Checked builds assert).

Minimal Repro

using System;
using System.Runtime.CompilerServices;

struct W { public short F; }

class Program
{
    static void Main()
    {
        Console.WriteLine(Test(new W { F = -1 }));
    }

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static int Test(W w)
    {
        short s = 0;
        Unsafe.As<short, W>(ref s) = w;
        return s;
    }
}

Expected

-1

Actual

Checked:

Assertion failed 'srcFld->IsIntegralConst()' in 'Program:Test(W):int' during 'Morph - Global' (IL size 17; hash 0xadfebca2; FullOpts)
    File: src\coreclr\jit\morphblock.cpp:1401

Release runtimes (and Checked with DOTNET_ContinueOnAssert=1) print 65535: Test compiles to mov eax, ecx; ret, with no movsx.

Regression?

Yes, regression in .NET 10 (win-x64):

  • .NET 8.0.31, 9.0.20: -1 (correct)
  • .NET 10.0.12, 11.0.0-rc.2: 65535
  • main (Checked): the assert above

Notes

  • Unsafe.As<short, W> is a same-size, in-bounds reinterpretation (W is exactly one short), so the program is well-defined.
  • MorphCopyBlockHelper::CopyFieldByField (morphblock.cpp, m_dstSingleStoreLclVar path) turns the block copy into STORE_LCL_VAR int V01 of LCL_VAR short V03 (the promoted field) via gtNewStoreLclVarNode, without a normalizing cast for the normalize-on-store short local.
  • Correct with DOTNET_JitMinOpts=1.

Activity

  1. added this to the 12.0.0 milestone on Oct 8, 2026
  2. added
    area-CodeGen-coreclr
    on Oct 8, 2026
  3. dotnet-policy-service commented on Oct 8, 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 Nov 17, 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