[release/5.0] Fix for Issue 44895 - Incorrect codegen with multiple returns of a field of a Nullable or struct type #45989
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport of #45284 to release/5.0
Fixes: #44895
Customer Impact
Reported by customer running .net 5.0. When optimizing we would incorrectly optimize a method that returns a nullable type.
The method needed to have more than 4 returns in the method body. This is silent bad codegen when optimizing.
The user would see an invalid return value from the function call.
Note that this issue also applies to other struct types beyond the nullable types. It is just more commonly seen with a nullable type.
The return statement must be field of a struct that was struct promoted and the return value must be a struct with a single ref field.
Regression?
Yes, this is a regression from .NET Core 3.1
Testing
Manual, new unit test, CLR outerloop, asm diffs.
Risk
Low
Allow only GT_ADDR and GT_ASG as a parent node
Add test case Runtime_44895.cs
Change assert about Incompatible types to be a noway_assert in gtNewTempAssign
Added noway_assert in release build for an assignment of a TYP_REF to a TYP_STRUCT