Skip to content

Clarify CoreCLR IL constant emission - #137988

Merged
jakobbotsch merged 2 commits into
dotnet:mainfrom
jakobbotsch:stub-linker-load-constants
Nov 23, 2026
Merged

jakobbotsch merged 2 commits into
dotnet:mainfrom
jakobbotsch:stub-linker-load-constants

Conversation

@jakobbotsch

Copy link
Copy Markdown
Member

#137931 is not the first time we've had a bug around EmitLDC and confusion about what type ends up on the stack. This PR:

  • Splits EmitLDC into EmitLDC_I4 and EmitLDC_I
  • Removes the stub linker's transformation that turns ldc_i8 into ldc_i4 when it fits, which is the source of these bugs
  • Changes all callers to use EmitLDC_I4 or EmitLDC_I explicitly depending on what type they want.

No caller needs an int64 loaded constant so I didn't add an EmitLDC_I8.

Replace EmitLDC with EmitLDC_I4 and EmitLDC_I to make stack types explicit.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 16f37459-2fa9-4520-85bb-15e9be5208cc
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 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: @agocke
See info in area-owners.md if you want to be subscribed.

Comment thread src/coreclr/vm/stubgen.cpp Resolved
@jakobbotsch

Copy link
Copy Markdown
Member Author

/azp run runtime-coreclr outerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

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.

🟢 Approval recommended

No active review issues remain for the changes making integer constant stack types explicit in IL stub generation.

No open issues 🎉

What changed in this PR

This PR makes integer constant stack types explicit in CoreCLR’s IL stub generator, addressing the ambiguity behind pointer-constant bugs such as #137931.

Changes:

  • Splits EmitLDC into EmitLDC_I4 and EmitLDC_I, with native-int conversion handled by the latter.
  • Removes implicit ldc.i8-to-ldc.i4 lowering and migrates callers to the appropriate typed helper.
  • Removes EmitLoadNullPtr and updates the JIT comment describing tolerated function-pointer types.
File Description
src/​coreclr/​vm/​tailcallhelp.cpp Uses explicit integer and pointer constants in tail-call stubs.
src/​coreclr/​vm/​stubgen.h Declares typed constant helpers and removes the null-pointer helper.
src/​coreclr/​vm/​stubgen.cpp Implements typed emission and limits constant shortening to ldc.i4.
src/​coreclr/​vm/​prestub.cpp Uses native-int constants for target addresses and generic contexts.
src/​coreclr/​vm/​jitinterface.cpp Uses native-int constants in async resumption stubs.
src/​coreclr/​vm/​ilmarshalers.h Migrates inline marshaler code to typed helpers.
src/​coreclr/​vm/​ilmarshalers.cpp Distinguishes integer constants from native null pointers in marshalers.
src/​coreclr/​vm/​dllimport.cpp Migrates interop stubs to explicit constant types.
src/​coreclr/​vm/​comdelegate.cpp Separates delegate-loop integers from debugger-state addresses.
src/​coreclr/​vm/​array.cpp Uses explicit int32 constants for array offsets, flags, and sizes.
src/​coreclr/​jit/​importercalls.cpp Updates only the comment explaining int32 function-pointer tolerance.

Review effort: Balanced

@BrzVlad BrzVlad left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@jakobbotsch

Copy link
Copy Markdown
Member Author

/ba-g Unknown failure is the one fixed by #138094

1 similar comment
@jakobbotsch

Copy link
Copy Markdown
Member Author

/ba-g Unknown failure is the one fixed by #138094

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants