Skip to content

Commit 83df0ab

Browse files
committed
Handle multiple calling conventions at once
1 parent a04c0e4 commit 83df0ab

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,32 @@ static void LocalFunction()
129129
}
130130
}
131131

132+
public unsafe delegate* unmanaged[Cdecl, Fastcall]<void> AddressOfLocalFunction_CDeclAndFastcall()
133+
{
134+
return &LocalFunction;
135+
136+
[UnmanagedCallersOnly(CallConvs = new Type[] {
137+
typeof(CallConvCdecl),
138+
typeof(CallConvFastcall)
139+
})]
140+
static void LocalFunction()
141+
{
142+
}
143+
}
144+
145+
public unsafe delegate* unmanaged[Fastcall, Cdecl]<void> AddressOfLocalFunction_FastcallAndCDecl()
146+
{
147+
return &LocalFunction;
148+
149+
[UnmanagedCallersOnly(CallConvs = new Type[] {
150+
typeof(CallConvFastcall),
151+
typeof(CallConvCdecl)
152+
})]
153+
static void LocalFunction()
154+
{
155+
}
156+
}
157+
132158
#if NET60
133159
public unsafe delegate* unmanaged[Cdecl, SuppressGCTransition]<void> AddressOfLocalFunction_CDeclAndSuppressGCTransition()
134160
{

ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4611,7 +4611,7 @@ protected internal override TranslatedExpression VisitLdFtn(LdFtn inst, Translat
46114611
var builder = ImmutableArray.CreateBuilder<IType>(array.Length);
46124612
foreach (var type in array.Select(a => a.Value).OfType<IType>())
46134613
{
4614-
SignatureCallingConvention? foundCallingConvention = type.Namespace is not "System.Runtime.CompilerServices" ? null : type.Name switch {
4614+
SignatureCallingConvention? foundCallingConvention = type.Namespace is not "System.Runtime.CompilerServices" || callingConvention != SignatureCallingConvention.Unmanaged ? null : type.Name switch {
46154615
"CallConvCdecl" => SignatureCallingConvention.CDecl,
46164616
"CallConvFastcall" => SignatureCallingConvention.FastCall,
46174617
"CallConvStdcall" => SignatureCallingConvention.StdCall,

ICSharpCode.Decompiler/TypeSystem/FunctionPointerType.cs

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,30 @@ public static FunctionPointerType FromSignature(MethodSignature<IType> signature
4646
&& modReturn.Modifier.Namespace == "System.Runtime.CompilerServices")
4747
{
4848
returnType = modReturn.ElementType;
49-
switch (modReturn.Modifier.Name)
49+
if (callingConvention == SignatureCallingConvention.Unmanaged)
5050
{
51-
case "CallConvCdecl":
52-
callingConvention = SignatureCallingConvention.CDecl;
53-
break;
54-
case "CallConvFastcall":
55-
callingConvention = SignatureCallingConvention.FastCall;
56-
break;
57-
case "CallConvStdcall":
58-
callingConvention = SignatureCallingConvention.StdCall;
59-
break;
60-
case "CallConvThiscall":
61-
callingConvention = SignatureCallingConvention.ThisCall;
62-
break;
63-
default:
64-
customCallConvs.Add(modReturn.Modifier);
65-
break;
51+
switch (modReturn.Modifier.Name)
52+
{
53+
case "CallConvCdecl":
54+
callingConvention = SignatureCallingConvention.CDecl;
55+
break;
56+
case "CallConvFastcall":
57+
callingConvention = SignatureCallingConvention.FastCall;
58+
break;
59+
case "CallConvStdcall":
60+
callingConvention = SignatureCallingConvention.StdCall;
61+
break;
62+
case "CallConvThiscall":
63+
callingConvention = SignatureCallingConvention.ThisCall;
64+
break;
65+
default:
66+
customCallConvs.Add(modReturn.Modifier);
67+
break;
68+
}
69+
}
70+
else
71+
{
72+
customCallConvs.Add(modReturn.Modifier);
6673
}
6774
}
6875
else

0 commit comments

Comments
 (0)