Skip to content

Conversation

@radekdoulik
Copy link
Member

@radekdoulik radekdoulik commented Dec 1, 2025

Fix regression introduced in #121799

Force intrinsic expansion for new runtime helpers in the interpreter.

Added the new methods and also
NI_System_StubHelpers_NextCallReturnAddress, which has also // Unconditionally expanded intrinsic comment.

This was happening on wasm and possibly on other platforms too, resulting in unhandled exception. Possibly only on platforms, which use generic instantiation IL stubs.

Unhandled exception. System.Diagnostics.UnreachableException: The program executed an instruction that was thought to be unreachable.
   at System.Runtime.CompilerServices.RuntimeHelpers.SetNextCallGenericContext(Void* value) in /Users/rodo/git/runtime-clean/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs:line 186
   at InterpreterTest.TestVirtual() in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 1960
   at InterpreterTest.RunInterpreterTests() in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 896
   at InterpreterTest.Main(String[] args) in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 731
Aborted(native code called abort())

Fix regression introduced in dotnet#121799

Force intrinsic expansion for new runtime helpers in the interpreter.

Added the new methods and also
NI_System_StubHelpers_NextCallReturnAddress, which has also `//
Unconditionally expanded intrinsic` comment.

This was happening on wasm and possibly on other platforms too,
resulting in unhandled exception. Possibly only happening on platforms
using generic instantiation IL stubs.

```
Unhandled exception. System.Diagnostics.UnreachableException: The program executed an instruction that was thought to be unreachable.
   at System.Runtime.CompilerServices.RuntimeHelpers.SetNextCallGenericContext(Void* value) in /Users/rodo/git/runtime-clean/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs:line 186
   at InterpreterTest.TestVirtual() in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 1960
   at InterpreterTest.RunInterpreterTests() in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 896
   at InterpreterTest.Main(String[] args) in /Users/rodo/git/runtime-clean/src/tests/JIT/interpreter/Interpreter.cs:line 731
Aborted(native code called abort())
```
@radekdoulik
Copy link
Member Author

I wonder if we can find better way to detect these.

Copilot finished reviewing on behalf of radekdoulik December 1, 2025 11:55
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 regression in the interpreter where virtual generic calls were causing unhandled exceptions due to certain runtime helper intrinsics not being expanded. The fix ensures that intrinsics marked as "Unconditionally expanded" are always processed by the interpreter's intrinsic expansion logic.

Key Changes

  • Added four runtime helper intrinsics to the isMustExpand condition in the interpreter's call emission code
  • These intrinsics must be unconditionally expanded to prevent infinite recursion and stack overflow
  • The fix specifically addresses virtual generic method calls that were failing on WebAssembly and potentially other platforms using generic instantiation IL stubs

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