diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 52d696e5e13d3..d99c51d236950 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -592,7 +592,7 @@ private CorInfoCallConvExtension GetUnmanagedCallingConventionFromAttribute(Cust } } - if (found && memberFunctionVariant) + if (memberFunctionVariant) { callConv = GetMemberFunctionCallingConventionVariant(callConv); } @@ -603,6 +603,8 @@ private CorInfoCallConvExtension GetUnmanagedCallingConventionFromAttribute(Cust private bool TryGetUnmanagedCallingConventionFromModOpt(MethodSignature signature, out CorInfoCallConvExtension callConv, out bool suppressGCTransition) { suppressGCTransition = false; + // Default to managed since in the modopt case we need to differentiate explicitly using a calling convention that matches the default + // and not specifying a calling convention at all and using the implicit default case in P/Invoke stub inlining. callConv = CorInfoCallConvExtension.Managed; if (!signature.HasEmbeddedSignatureData || signature.GetEmbeddedSignatureData() == null) return false; @@ -649,9 +651,9 @@ private bool TryGetUnmanagedCallingConventionFromModOpt(MethodSignature signatur } } - if (found && memberFunctionVariant) + if (memberFunctionVariant) { - callConv = GetMemberFunctionCallingConventionVariant(callConv); + callConv = GetMemberFunctionCallingConventionVariant(found ? callConv : (CorInfoCallConvExtension)PlatformDefaultUnmanagedCallingConvention()); } return found;