Don't denormalize enum return values on instance methods on x86. (#23816)
authorJeremy Koritzinsky <jkoritzinsky@gmail.com>
Tue, 9 Apr 2019 22:28:00 +0000 (15:28 -0700)
committerGitHub <noreply@github.com>
Tue, 9 Apr 2019 22:28:00 +0000 (15:28 -0700)
* Don't denormalize enum return values on instance methods on x86.

* Reuse closedElemType.

src/vm/mlinfo.cpp

index 2e675fd..985eefe 100644 (file)
@@ -1652,7 +1652,19 @@ MarshalInfo::MarshalInfo(Module* pModule,
     }
     else
     {
-        mtype = sig.PeekElemTypeClosed(pModule, pTypeContext);
+        SigPointer sigtmp = sig;
+        CorElementType closedElemType = sigtmp.PeekElemTypeClosed(pModule, pTypeContext);
+        if (closedElemType == ELEMENT_TYPE_VALUETYPE)
+        {
+            TypeHandle th = sigtmp.GetTypeHandleThrowing(pModule, pTypeContext); 
+            // If the return type of an instance method is a value-type we need the actual return type.
+            // However, if the return type is an enum, we can normalize it.
+            if (!th.IsEnum())
+            {
+                mtype = closedElemType;
+            }
+        }
+
     }
 #endif // _TARGET_X86_