Skip to content

Conversation

@janvorli
Copy link
Member

@janvorli janvorli commented Nov 4, 2025

The interpreter compiler ignores tail call prefix for tail calls (and jmp) to pinvokes that are not marshalled. But it is not injecting "ret" IR opcode after the call returns, which results in BADCODE reported by the compiler.

There are several coreclr tests in the JIT/jit64/mcc/interop that fail due to that.

This change adds injecting proper form of "ret" IR opcode after such calls.

The interpreter compiler ignores tail call prefix for tail calls (and
jmp) to pinvokes that are not marshalled. But it is not injecting "ret"
IR opcode after the call returns, which results in BADCODE reported by
the compiler.

There are several coreclr tests in the JIT/jit64/mcc/interop that fail
due to that.

This change adds injecting proper form of "ret" IR opcode after such
calls.
@janvorli janvorli added this to the 11.0.0 milestone Nov 4, 2025
@janvorli janvorli self-assigned this Nov 4, 2025
@janvorli janvorli requested review from BrzVlad and kg as code owners November 4, 2025 00:00
Copilot AI review requested due to automatic review settings November 4, 2025 00:00
@dotnet-policy-service
Copy link
Contributor

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

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 an issue where tail calls to PInvoke methods (which are not marshaled) are incorrectly handled in the interpreter compiler. Since PInvokes are not IL code, they cannot be tail-called directly. The PR converts such tail calls to normal calls followed by an injected return instruction to preserve the intended semantics.

  • Adds logic to detect when a tail call target is a non-marshaled PInvoke and converts it to a normal call
  • Injects appropriate return instructions after the call based on the return type

@janvorli janvorli changed the title Fix interpreter tailcall to pinvoke Fix interpreter jmp to pinvoke Nov 4, 2025
@janvorli
Copy link
Member Author

janvorli commented Nov 4, 2025

/ba-g the android timeout is unrelated.

@janvorli janvorli merged commit 3650ff3 into dotnet:main Nov 4, 2025
92 of 97 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants