Skip to content

Conversation

AndyAyersMS
Copy link
Member

If we retype a struct local we also need to retype any BLK operations on those locals.

Fixes #115832.

If we retype a struct local we also need to retype any BLK operations
on those locals.

Fixes dotnet#115832.
@Copilot Copilot AI review requested due to automatic review settings May 21, 2025 17:04
@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 May 21, 2025
@AndyAyersMS
Copy link
Member Author

AndyAyersMS commented May 21, 2025

@dotnet/jit-contrib PTAL

No diffs but a lot of missed contexts.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a JIT assertion by propagating updated struct layouts to BLK nodes during escape analysis retyping.

  • Extended UpdateAncestorTypes to accept a new ClassLayout* newLayout parameter.
  • Added SetLayout calls for GT_STORE_BLK and GT_BLK nodes when retypeFields is true.
  • Introduced a new repro test (Runtime_115832) to catch the original assertion.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/tests/JIT/opt/ObjectStackAllocation/*.csproj Added optimized test project for repro case
src/tests/JIT/opt/ObjectStackAllocation/Runtime_115832.cs New fuzz-generated test reproducing the JIT assert
src/coreclr/jit/objectalloc.h Updated UpdateAncestorTypes signature to include newLayout
src/coreclr/jit/objectalloc.cpp Implemented layout propagation to BLK nodes
src/coreclr/jit/gentree.h Added GenTreeBlk::SetLayout to allow runtime layout updates
Comments suppressed due to low confidence (2)

src/coreclr/jit/objectalloc.cpp:2196

  • Consider adding a unit test that exercises the GT_STORE_BLK retype path to ensure SetLayout is correctly applied and prevent future regressions.
if (retypeFields && parent->OperIs(GT_STORE_BLK))

src/coreclr/jit/objectalloc.cpp:2189

  • The removal of the addr->OperIs(GT_FIELD_ADDR) check broadens the STOREIND retyping logic beyond struct field stores, which conflicts with the existing comment. Consider restoring that guard or updating the comment to reflect the intended behavior.
if (parent->OperIs(GT_STOREIND) && varTypeIsGC(parent->TypeGet()))

// tree - Possibly-stack-pointing tree
// parentStack - Parent stack of the possibly-stack-pointing tree
// newType - New type of the possibly-stack-pointing tree
// newLayout - Layout for a retyped local struct
Copy link

Copilot AI May 21, 2025

Choose a reason for hiding this comment

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

You added a description for newLayout in the implementation comments; please update the corresponding declaration comment in objectalloc.h so the header and implementation stay in sync.

Copilot uses AI. Check for mistakes.

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib ping

@AndyAyersMS AndyAyersMS merged commit 1c653e9 into dotnet:main May 22, 2025
115 checks passed
SimaTian pushed a commit that referenced this pull request May 27, 2025
If we retype a struct local we also need to retype any BLK operations
on those locals.

Fixes #115832.
@github-actions github-actions bot locked and limited conversation to collaborators Jun 22, 2025
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

Development

Successfully merging this pull request may close these issues.

JIT: Assertion failed 'm_blockLayout->CanAssignFrom(m_src->GetLayout(m_comp))' during 'Morph - Global'

2 participants