Don't denormalize enum return values on instance methods on x86. (#23816)
[platform/upstream/coreclr.git] / 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_