-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Generalize check for dynamic scopes when saving EH clauses #116217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The Task returning thunks generated for runtime async methods have a `catch (Exception ex)` in them. During EH we were lazily trying to resolve the dynamic type token to a type handle using the metadata scope from the original IL method. Ensure we do this during JIT time instead, using the right resolver.
Tagging subscribers to this area: @mangod9 |
There was a problem hiding this 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 generalizes exception handling (EH) clause token resolution by switching from a method-specific dynamic check to a scope-based approach, ensuring the correct resolver is used at JIT time.
- Replace
m_pMethodBeingCompiled->IsDynamicMethod()
withIsDynamicScope(m_MethodInfo.scope)
- Switch from
AsDynamicMethodDesc()->GetResolver()
toGetDynamicResolver(m_MethodInfo.scope)
- Resolve dynamic type tokens during JIT compilation rather than lazily at EH time
Comments suppressed due to low confidence (2)
src/coreclr/vm/jitinterface.cpp:12780
- Add tests that cover EH clause resolution for both dynamic and non-dynamic scopes to verify
ResolveToken
is invoked only when intended.
if (IsDynamicScope(m_MethodInfo.scope) &&
src/coreclr/vm/jitinterface.cpp:12785
- Potential null dereference:
GetDynamicResolver
may return null if the scope isn't dynamic. Consider adding a null check or assertion before callingResolveToken
.
GetDynamicResolver(m_MethodInfo.scope)->ResolveToken(clause->ClassToken, &resolved);
I have a testcase for the repro in https://github.com/VSadov/runtime/tree/asyncEhBug. May be useful to cherry-pick into this PR. |
The test is passing on my machine now (with this change). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
I have not generally been adding regression tests for these very basic issues found by Fuzzlyn. Fuzzlyn finds these issues in a few seconds, so I think it would be better to get the coverage by adding Fuzzlyn testing of runtime async to the CI (it's on my TODO list...). |
The Task returning thunks generated for runtime async methods have a
catch (Exception ex)
in them. During EH we were lazily trying to resolve the dynamic type token to a type handle using the metadata scope from the original IL method. Ensure we do this during JIT time instead, using the right resolver.Fix #115779