Browse Source

Handle multiple calling conventions at once

pull/3620/head
ds5678 1 month ago committed by Jeremy Pritts
parent
commit
83df0ab9b9
  1. 26
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/FunctionPointers.cs
  2. 2
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  3. 39
      ICSharpCode.Decompiler/TypeSystem/FunctionPointerType.cs

26
ICSharpCode.Decompiler.Tests/TestCases/Pretty/FunctionPointers.cs

@ -129,6 +129,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -129,6 +129,32 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
}
public unsafe delegate* unmanaged[Cdecl, Fastcall]<void> AddressOfLocalFunction_CDeclAndFastcall()
{
return &LocalFunction;
[UnmanagedCallersOnly(CallConvs = new Type[] {
typeof(CallConvCdecl),
typeof(CallConvFastcall)
})]
static void LocalFunction()
{
}
}
public unsafe delegate* unmanaged[Fastcall, Cdecl]<void> AddressOfLocalFunction_FastcallAndCDecl()
{
return &LocalFunction;
[UnmanagedCallersOnly(CallConvs = new Type[] {
typeof(CallConvFastcall),
typeof(CallConvCdecl)
})]
static void LocalFunction()
{
}
}
#if NET60
public unsafe delegate* unmanaged[Cdecl, SuppressGCTransition]<void> AddressOfLocalFunction_CDeclAndSuppressGCTransition()
{

2
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -4611,7 +4611,7 @@ namespace ICSharpCode.Decompiler.CSharp @@ -4611,7 +4611,7 @@ namespace ICSharpCode.Decompiler.CSharp
var builder = ImmutableArray.CreateBuilder<IType>(array.Length);
foreach (var type in array.Select(a => a.Value).OfType<IType>())
{
SignatureCallingConvention? foundCallingConvention = type.Namespace is not "System.Runtime.CompilerServices" ? null : type.Name switch {
SignatureCallingConvention? foundCallingConvention = type.Namespace is not "System.Runtime.CompilerServices" || callingConvention != SignatureCallingConvention.Unmanaged ? null : type.Name switch {
"CallConvCdecl" => SignatureCallingConvention.CDecl,
"CallConvFastcall" => SignatureCallingConvention.FastCall,
"CallConvStdcall" => SignatureCallingConvention.StdCall,

39
ICSharpCode.Decompiler/TypeSystem/FunctionPointerType.cs

@ -46,23 +46,30 @@ namespace ICSharpCode.Decompiler.TypeSystem @@ -46,23 +46,30 @@ namespace ICSharpCode.Decompiler.TypeSystem
&& modReturn.Modifier.Namespace == "System.Runtime.CompilerServices")
{
returnType = modReturn.ElementType;
switch (modReturn.Modifier.Name)
if (callingConvention == SignatureCallingConvention.Unmanaged)
{
case "CallConvCdecl":
callingConvention = SignatureCallingConvention.CDecl;
break;
case "CallConvFastcall":
callingConvention = SignatureCallingConvention.FastCall;
break;
case "CallConvStdcall":
callingConvention = SignatureCallingConvention.StdCall;
break;
case "CallConvThiscall":
callingConvention = SignatureCallingConvention.ThisCall;
break;
default:
customCallConvs.Add(modReturn.Modifier);
break;
switch (modReturn.Modifier.Name)
{
case "CallConvCdecl":
callingConvention = SignatureCallingConvention.CDecl;
break;
case "CallConvFastcall":
callingConvention = SignatureCallingConvention.FastCall;
break;
case "CallConvStdcall":
callingConvention = SignatureCallingConvention.StdCall;
break;
case "CallConvThiscall":
callingConvention = SignatureCallingConvention.ThisCall;
break;
default:
customCallConvs.Add(modReturn.Modifier);
break;
}
}
else
{
customCallConvs.Add(modReturn.Modifier);
}
}
else

Loading…
Cancel
Save