Skip to content

JIT: Strip GC/reloc flags from the size in arm64 instGen_Set_Reg_To_Imm - #132269

Open
jakobbotsch wants to merge 1 commit into
dotnet:mainfrom
jakobbotsch:fix-arm64-byref-imm-datasize
Open

JIT: Strip GC/reloc flags from the size in arm64 instGen_Set_Reg_To_Imm#132269
jakobbotsch wants to merge 1 commit into
dotnet:mainfrom
jakobbotsch:fix-arm64-byref-imm-datasize

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

The immediate encoding helpers (emitIns_valid_imm_for_mov, canEncodeHalfwordImm, canEncodeBitMaskImm) take a plain 4/8 byte data size and assert on anything else. Every other caller strips the flags first, but instGen_Set_Reg_To_Imm only did so when relocations were disabled, so with relocations enabled a non-null byref constant reached them as EA_BYREF and tripped

Assertion failed 'isValidGeneralDatasize(size)' in emitarm64.cpp:3025

The movz/movk fallback had the same problem: its 'size == EA_8BYTE' tests would compute a 32 bit width for EA_BYREF and drop the upper halfwords.

Only reproduces when compiling ahead of time (crossgen2/NativeAOT), where compReloc is set.

Fixes #132268

The immediate encoding helpers (emitIns_valid_imm_for_mov, canEncodeHalfwordImm,
canEncodeBitMaskImm) take a plain 4/8 byte data size and assert on anything else.
Every other caller strips the flags first, but instGen_Set_Reg_To_Imm only did so
when relocations were disabled, so with relocations enabled a non-null byref
constant reached them as EA_BYREF and tripped

    Assertion failed 'isValidGeneralDatasize(size)' in emitarm64.cpp:3025

The movz/movk fallback had the same problem: its 'size == EA_8BYTE' tests would
compute a 32 bit width for EA_BYREF and drop the upper halfwords.

Only reproduces when compiling ahead of time (crossgen2/NativeAOT), where
compReloc is set.

Fixes dotnet#132268

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 17ed5289-947f-4243-a31e-6468f680a54c
Copilot AI lite review requested due to automatic review settings August 13, 2026 10:32
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 13, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an arm64 JIT correctness bug where instGen_Set_Reg_To_Imm could pass an emitAttr with GC/reloc flags (e.g., EA_BYREF) into immediate-encoding helpers that require a plain 4/8-byte size, causing assertions (and incorrect movz/movk width decisions) when relocations are enabled (AOT scenarios).

Changes:

  • In CodeGen::instGen_Set_Reg_To_Imm, compute immSize = EA_SIZE(size) and use it for emitIns_valid_imm_for_mov and the movz/movn/movk fallback width decisions.
  • Add a new JIT regression test for issue #132268.
  • Register the new test in Regression_ro_2.csproj.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/codegenarm64.cpp Strips flags from the size used by immediate-encoding decisions while preserving full emitAttr for emission/reloc handling.
src/tests/JIT/Regression/Regression_ro_2.csproj Includes the new JitBlue regression test source file in the merged regression project.
src/tests/JIT/Regression/JitBlue/Runtime_132268/Runtime_132268.cs Adds a repro-based xUnit regression test targeting the byref-constant path that triggered the arm64 AOT assertion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: Assertion failed 'isValidGeneralDatasize(size)' during 'Generate code'

2 participants