Skip to content

[RISC-V] Fix 64-bit constant truncation on LLP64 hosts - #136297

Merged
jkotas merged 1 commit into
dotnet:mainfrom
glomdom:fix/riscv64-loadimm-const-size
Oct 22, 2026
Merged

jkotas merged 1 commit into
dotnet:mainfrom
glomdom:fix/riscv64-loadimm-const-size

Conversation

@glomdom

@glomdom glomdom commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

emitLoadImmediate falls back to loading a 64-bit constant from the data section with ld, but sized the slot with sizeof(long). That's 4 on Windows, so a Windows-hosted cross JIT targeting riscv64 only emitted the low 4 bytes of the constant. Switched to sizeof(originalImm).

Repro from the issue (ulong / 10), __managedcode at the ld target:

Before:

0030 cdcccccc 00000000 00000000 00000000

After:

0030 cdcccccc cccccccc 00000000 00000000

Fixes #136034

emitLoadImmediate sized its data constant with sizeof(long), which is 4
on Windows hosts, so a Windows-hosted riscv64 JIT emitted only the low
4 bytes of 64-bit constants loaded via ld. Use sizeof(originalImm)
instead.

Fix dotnet#136034
@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 Oct 22, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 22, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 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.

@jkotas jkotas added the arch-riscv Related to the RISC-V architecture label Oct 22, 2026
@jkotas
jkotas merged commit 73cc9a3 into dotnet:main Oct 22, 2026
148 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 23, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-riscv Related to the RISC-V architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

riscv64: 64-bit constant in method data truncated to 4 bytes (ulong division by constant gives wrong results)

2 participants