Skip to content

Overflowing negative constants in printed x64 assembly #118813

@ashay

Description

@ashay

Description

https://godbolt.org/z/jfPx7oenM

When constants are smaller than -0x1000000 and DOTNET_JitDisasm is set, the runtime prints these as 64-bit constants, even if the instruction expects a 32-bit constant (based on the register widths of the instruction). This can result in invalid assembly code like mov eax, 0xFFFFFFFFFEFFFFFF.

To be precise, the assembled program is correct, only the printing of the program is incorrect.

Reproduction Steps

using System.Runtime.CompilerServices;

class Program
{
  public static void Main(string[] args)
  {
  }

  [MethodImpl(MethodImplOptions.NoInlining)]
  public int foo(int x)
  {
    return -0x1000001;
  }
}

Expected behavior

mov      eax, 0xFEFFFFFF

Actual behavior

mov      eax, 0xFFFFFFFFFEFFFFFF

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions