-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add support for IntPtr conversion in the call arguments optimizer. #11752
Conversation
IntPtr conversion can stay in the bound tree past lowering in a case where a COM method is invoked in an Expression Tree lambda. Fixes: dotnet#11751
@dotnet/roslyn-compiler - please review |
@MattGertz - for Update3 signoff The bug results in crashes/watsons when upgrading to VS2015 and rebuilding. COM + Expression Trees combination is not so uncommon as it might seem. Some mocking frameworks use expression trees extensively and when the tested scenario involves COM methods, it could result in crashing scenarios. The combination results in IntPtr argument conversions staying in the bound tree past the Call lowering and argument optimizer was not expecting them. |
Approved pending CRs. |
LGTM |
case ConversionKind.ExplicitUserDefined: | ||
case ConversionKind.ImplicitUserDefined: | ||
// expression trees rewrite this later. | ||
// it is a kind of user defined conversions on IntPtr and in some cases can fail | ||
case ConversionKind.IntPtr: |
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.
Can we assert that this is happening only when we are producing an expression tree?
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.
If we are not in an expression tree, IntPtr will cause an assert in codegen anyways. And that one is more reliable since it is not conditional on optimizations being performed.
Also, this method does not have enough context to know we are in an expression tree and I do not want to change that just to get an assert earlier, sometimes.
LGTM, but do consider adding an assert. |
Will add an assert. |
I've decided against an assert specifically for IntPtr conversions. There are many conversion kinds there, which can be seen only under certain conditions, so I do not want to single out just IntPtr one. In particular since this method is static and only needs to sort conversions into "pure" ones and others by kind. I will replace the exception with an assert though, since there is a correct default behavior. |
… behavior that is not a crash.
IntPtr conversion can stay in the bound tree past lowering in a case where a COM method is invoked in an Expression Tree lambda.
Fixes: #11751