diff options
author | Jan Kotas <jkotas@microsoft.com> | 2017-01-26 12:41:45 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-26 12:41:45 -0800 |
commit | 0bc4bffb923a792ac15b070610fe40a4e4629146 (patch) | |
tree | fc9639d595942b41dd3bd4269d1a549652721052 | |
parent | 63b07cc9c659642d6fb00fecf5a7b2683c82f4b1 (diff) | |
download | coreclr-0bc4bffb923a792ac15b070610fe40a4e4629146.tar.gz coreclr-0bc4bffb923a792ac15b070610fe40a4e4629146.tar.bz2 coreclr-0bc4bffb923a792ac15b070610fe40a4e4629146.zip |
Fix encoding of native signatures in the presence of Enum.GetHashCode optimization (#9138)
Fixes #9118
-rw-r--r-- | src/vm/jitinterface.cpp | 8 | ||||
-rw-r--r-- | tests/src/readytorun/main.cs | 5 | ||||
-rw-r--r-- | tests/src/readytorun/test.cs | 7 |
3 files changed, 20 insertions, 0 deletions
diff --git a/src/vm/jitinterface.cpp b/src/vm/jitinterface.cpp index 0b3c9f2605..2a88ed9b4b 100644 --- a/src/vm/jitinterface.cpp +++ b/src/vm/jitinterface.cpp @@ -5180,6 +5180,14 @@ void CEEInfo::getCallInfo( { // Pretend this was a "constrained. UnderlyingType" instruction prefix constrainedType = TypeHandle(MscorlibBinder::GetElementType(constrainedType.GetVerifierCorElementType())); + + // Native image signature encoder will use this field. It needs to match that pretended type, a bogus signature + // would be produced otherwise. + pConstrainedResolvedToken->hClass = (CORINFO_CLASS_HANDLE)constrainedType.AsPtr(); + + // Clear the token and typespec because of they do not match hClass anymore. + pConstrainedResolvedToken->token = mdTokenNil; + pConstrainedResolvedToken->pTypeSpec = NULL; } } diff --git a/tests/src/readytorun/main.cs b/tests/src/readytorun/main.cs index bbdd101759..783c1fd3cb 100644 --- a/tests/src/readytorun/main.cs +++ b/tests/src/readytorun/main.cs @@ -99,6 +99,11 @@ class Program { ((Object)s).ToString(); } + + // Enum.GetHashCode optimization requires special treatment + // in native signature encoding + MyEnum e = MyEnum.Apple; + e.GetHashCode(); } static void TestConstrainedMethodCalls_Unsupported() diff --git a/tests/src/readytorun/test.cs b/tests/src/readytorun/test.cs index 40199b41e8..8a6beaea15 100644 --- a/tests/src/readytorun/test.cs +++ b/tests/src/readytorun/test.cs @@ -403,3 +403,10 @@ public class ByteChildClass : ByteBaseClass ChildByte = 67; } } + +public enum MyEnum +{ + Apple = 1, + Banana = 2, + Orange = 3 +} |