Skip to content

Conversation

@jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Jan 7, 2026

Functions with GS cookie checks may furthermore shadow parameters to make sure that the GS cookie ends up above all parameters on the stack. This is done by creating a copy of parameters used like a pointer and redirecting all uses to act on the shadow. IR is inserted in the beginning of the function to copy the parameters to their shadows.

For async this introduces a problem when it comes to implicit byrefs. The shadowing ceremony introduces a pointer to a local (the storage area in the caller) and that pointer remains live across suspension points, resulting in illegal IR.

This PR moves the GS phase so that it runs after the async transformation. To do so rewrite the analysis to run on LIR and the IR insertion/rewriting to be compatible with LIR.

Fix #122954

… transformation

Functions with GS cookie checks may furthermore shadow parameters to
make sure that the GS cookie ends up above all parameters on the stack.
This is done by creating a copy of parameters used like a pointer and
redirection all uses to act on the shadow. IR is inserted in the
beginning of the function to copy the parameters to their shadows.

For async this introduces a problem when it comes to implicit byrefs.
The shadowing ceremony introduces a pointer to a local (the storage area
in the caller) and that pointer remains live across suspension points,
resulting in illegal IR.

Ideally we would move the shadowing pass to run after the async
transformation, but this requires rewriting the analysis from HIR to
LIR. This change instead fixes the issue by keeping the analysis where
it is, but by delaying the rewrite of the IR until after the async
transformation (for async functions only).
@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 Jan 7, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jakobbotsch
Copy link
Member Author

I think I will spend a bit more time and move the entire phase to unconditionally run on LIR. The current approach means that we are barely testing the LIR version of this.

@jakobbotsch jakobbotsch changed the title JIT: Delay rewriting IR for GS cookie shadow copies until after async transformation JIT: Make GS cookie phase run on LIR and move it after async phase Jan 9, 2026
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.

Test failure: _shared_generic::Async2SharedGeneric.TestEntryPoint()

1 participant