Skip to content

[release/11.0] JIT: Don't clobber an ECX call result when popping x86 caller-pop args - #138552

Open
EgorBo wants to merge 2 commits into
dotnet:release/11.0from
EgorBo:backport-137821-release-11.0
Open

EgorBo wants to merge 2 commits into
dotnet:release/11.0from
EgorBo:backport-137821-release-11.0

Conversation

@EgorBo

@EgorBo EgorBo commented Nov 30, 2026

Copy link
Copy Markdown
Member

Fixes Issue #137798

main PR #137821

Description

Backport of #137821 to release/11.0. Since #125214, LSRA may allocate a call's result to ECX. On x86, genRemoveAlignmentAfterCall then clobbered it with pop ecx after cdecl calls with 4 bytes of stack args. It now uses add esp, 4 when ECX holds the result. The DEBUG-only JitStackChecks code had the same issue and is fixed too.

Customer Impact

  • Customer reported
  • Found internally

Silent bad codegen on Windows x86: the return value of a cdecl call (e.g. a P/Invoke) is replaced by its argument.

Regression

  • Yes
  • No

Introduced in .NET 11 by #125214. Works on .NET 10.

Testing

Test is backported.

Risk

Low. x86 only, and only when the call's result is in ECX.

Note

PR description generated with GitHub Copilot.

EgorBo and others added 2 commits November 30, 2026 23:35
dotnet#137821)

Fixes dotnet#137798

Since dotnet#125214, LSRA may allocate a call's result to ECX (e.g. when it's
passed as the first arg of the next call). On x86,
`genRemoveAlignmentAfterCall` then clobbered it with `pop ecx` for cdecl
calls with 4 bytes of stack args:

```asm
call     eax ; abs(int)
mov      ecx, eax
pop      ecx            ; clobbers the result
call     [Consume(int):int]
```

Use `add esp, 4` when ECX holds the result. The DEBUG-only
`JitStackChecks` after calls had the same issue (used ECX as a temp), so
it now adjusts the saved SP slot instead of needing a scratch register.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 5d4045a5-f371-42f9-8340-91c7c44f2eab
(cherry picked from commit efd8294)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8c6b9802-8643-479e-bbb4-f4e04e60fc0a
@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 Nov 30, 2026
@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.

@EgorBo
EgorBo requested a review from jakobbotsch November 30, 2026 22:48

This branch has not been deployed

No deployments
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.

2 participants