Skip to content

JIT: use the carry flag to detect SP wraparound in genLclHeap on ARM - #135599

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:arm64/fix-135524
Oct 14, 2026
Merged

EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:arm64/fix-135524

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

The non-zeroing localloc path checked 'sp - size' for wraparound with 'bvc' (signed overflow) instead of the carry flag, so a huge stackalloc set SP to a wrapped address without probing instead of overflowing.

Fixes #135524

A few diffs

The non-zeroing localloc path checked 'sp - size' for wraparound with
'bvc' (signed overflow) instead of the carry flag, so a huge stackalloc
set SP to a wrapped address without probing instead of overflowing.

Fixes dotnet#135524

Co-authored-by: Copilot <[email protected]>
@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 11, 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.

🟡 Changes recommended

The behavioral bug fix needs a process-isolated regression test covering oversized non-zeroing stack allocation.

1 open finding
What changed in this PR

Fixes ARM/ARM64 non-zeroing localloc wraparound detection by branching on carry/no-borrow rather than signed overflow.

Changes:

  • Replaces EJ_vc with EJ_hs on ARM and ARM64.
  • Updates corresponding assembly comments.
  • Correct approach, but lacks regression coverage.
File Description
src/​coreclr/​jit/​codegenarm64.cpp Uses carry-set to detect subtraction without borrow.
src/​coreclr/​jit/​codegenarm.cpp Applies the equivalent ARM fix.

🧠 Review effort: Balanced

Comment thread src/coreclr/jit/codegenarm64.cpp Resolved
@EgorBo

EgorBo commented Oct 12, 2026

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib, simple bug-fix, a few diffs

@EgorBo
EgorBo requested a review from a team October 12, 2026 12:07
@EgorBo

EgorBo commented Oct 13, 2026

Copy link
Copy Markdown
Member Author

PTAL @adamperlin

@EgorBo
EgorBo requested a review from adamperlin October 13, 2026 17:47
@JulieLeeMSFT

Copy link
Copy Markdown
Member

LGTM.

  Old check: bvc (V flag)  -> WRONG, may not catch unsigned wrap
  New check: bhs (C flag)  -> correct: C=1 means no borrow occurred
                              (i.e., SP >= size, no wraparound)
                              C=0 (bhs false) => wraparound => clamp regCnt=0

@EgorBo
EgorBo enabled auto-merge (squash) October 14, 2026 02:18
@EgorBo
EgorBo merged commit 6d39701 into dotnet:main Oct 14, 2026
135 checks passed
@EgorBo
EgorBo deleted the arm64/fix-135524 branch October 14, 2026 02:18
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

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

Projects

None yet

3 participants