Prevent devirtualization into unallocated types #73839
Merged
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.
If we were in a situation like in the regression test, we would devirtualize the
GrabObjectcall toSomeUnallocatedClass.GrabObject. But becauseSomeUnallocatedClasswas never allocated, the scanner didn't scan it, and bad things would happen.Prevent devirtualizing into types that were not seen as allocated.
This is not a real issue for non-generic (non-shareable) types because the tentative instance method optimization generates throwing bodies for these. But tentative method optimization doesn't run for shared generics:
runtime/src/coreclr/tools/Common/Compiler/MethodExtensions.cs
Line 115 in 4cbe6f9
This was rare enough that we haven't seen it until I did #73683 and there was one useless constructor that we stopped generating and triggered this.
This also includes what is essentially a rollback of dotnet/runtimelab#1700. This should have been rolled back with #66145 but I forgot we had this. It was not needed.