Skip to content
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

Fix incorrect devirtualization in CG2 #37370

Merged
merged 2 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ private void ceeInfoGetCallInfo(
//
// Note that it is safe to devirtualize in the following cases, since a servicing event cannot later modify it
// 1) Callvirt on a virtual final method of a value type - since value types are sealed types as per ECMA spec
devirt = (constrainedType ?? targetMethod.OwningType).IsValueType || targetMethod.IsInternalCall;
devirt = targetMethod.OwningType.IsValueType || targetMethod.IsInternalCall;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, this code is still different from what crossgen does - the comment above ends at 1), but the VM side special cases 3 things - this seems to be missing an optimization around Delegate.Invoke - we probably generate less efficient code for that as a result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the two other cases (delegates and intrinsics) so we line with up with CG1


callVirtCrossingVersionBubble = true;
}
Expand Down
21 changes: 21 additions & 0 deletions src/coreclr/tests/src/readytorun/crossgen2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,26 @@ private static bool ObjectToStringOnGenericParamTestVersionBubbleLocalStruct()
return true;
}

enum TestEnum
{
A,
B
}

private static bool EnumValuesToStringTest()
{
string buffer = "";
foreach (TestEnum val in Enum.GetValues(typeof(TestEnum)))
{
buffer += val.ToString();
}

if (buffer != "AB")
return false;

return true;
}

private static string EmitTextFileForTesting()
{
string file = Path.GetTempFileName();
Expand Down Expand Up @@ -1253,6 +1273,7 @@ public static int Main(string[] args)
RunTest("ObjectGetTypeOnGenericParamTest", ObjectGetTypeOnGenericParamTest());
RunTest("ObjectToStringOnGenericParamTestSByte", ObjectToStringOnGenericParamTestSByte());
RunTest("ObjectToStringOnGenericParamTestVersionBubbleLocalStruct", ObjectToStringOnGenericParamTestVersionBubbleLocalStruct());
RunTest("EnumValuesToStringTest", EnumValuesToStringTest());

File.Delete(TextFileName);

Expand Down