Skip to content

Conversation

@max-charlamb
Copy link
Member

Bug when both an asyncContinuationArg and compTypeCtxtArg are present due to mutating value used for comparison.

There are four separate checks for special parameters which are hidden and decrement the actual var number. These are:

  • Type context arg
  • Vararg Handle
  • Async Continuation
  • Return buffer

Previously, the value would be decremented then compared in the order listed. This causes problems if multiple of these hidden parameters are present since the decremented value would be equal or lower to the hidden var number and would not be decremented.

Example - Async method with a hidden generic type context:

Both the type context and async continuation hidden vars are present:
info.compTypeCtxtArg = 1
and
lvaAsyncContinuationArg = 2

For varNum = 3:

  1. varNum > info.compTypeCtxtArg -> 3 > 2 -> true and therefore varNum is decremented to 2
  2. varNum > lvaAsyncContinuationArg -> 2 > 2 -> false and therefore varNum is not decremented.
  3. The ILVarNum assigned is 2

For varNum = 4:

  1. varNum > info.compTypeCtxtArg -> 4 > 2 -> true and therefore varNum is decremented to 3
  2. varNum > lvaAsyncContinuationArg -> 3 > 2 -> true and therefore varNum is decremented to 2.
  3. The ILVarNum assigned is also 2

This leads to two AsyncContinuationVarInfo both having VarNumber = 2

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Dec 3, 2025
Copy link
Contributor

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 critical bug in the JIT compiler's debug info generation where async methods with multiple hidden parameters (specifically async continuation and generic type context) would produce duplicate IL variable numbers.

Key Changes:

  • Introduced originalVarNum to preserve the input value during hidden parameter processing
  • Updated all four hidden parameter checks to use originalVarNum for comparisons instead of the mutating varNum

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

Thanks for finding this.

@max-charlamb max-charlamb added area-Diagnostics-coreclr runtime-async and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Dec 3, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

@max-charlamb
Copy link
Member Author

/ba-g unrelated transient test failure

@max-charlamb max-charlamb merged commit 8695b5c into dotnet:main Dec 4, 2025
119 of 123 checks passed
@max-charlamb max-charlamb deleted the fix-debug-info-arg-numbering branch December 4, 2025 18:14
@github-actions github-actions bot locked and limited conversation to collaborators Jan 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants