diff --git a/src/Generator/Passes/CheckAbiParameters.cs b/src/Generator/Passes/CheckAbiParameters.cs index 249299a2..ca6beb3d 100644 --- a/src/Generator/Passes/CheckAbiParameters.cs +++ b/src/Generator/Passes/CheckAbiParameters.cs @@ -1,4 +1,5 @@ using CppSharp.AST; +using CppSharp.AST.Extensions; using System.Linq; namespace CppSharp.Passes @@ -29,7 +30,15 @@ namespace CppSharp.Passes if (!VisitDeclaration(function)) return false; - if (function.IsReturnIndirect) + var isReturnIndirect = function.IsReturnIndirect || ( + Context.ParserOptions.IsMicrosoftAbi && + function is Method && + !function.ReturnType.Type.Desugar().IsAddress() && + function.ReturnType.Type.Desugar().TryGetDeclaration(out Class returnTypeDecl) && + returnTypeDecl.IsPOD && + returnTypeDecl.Layout.Size <= 8); + + if (isReturnIndirect) { var indirectParam = new Parameter() { diff --git a/tests/CSharp/CSharp.Tests.cs b/tests/CSharp/CSharp.Tests.cs index 081b4b91..17e6df53 100644 --- a/tests/CSharp/CSharp.Tests.cs +++ b/tests/CSharp/CSharp.Tests.cs @@ -159,6 +159,19 @@ public unsafe class CSharpTests : GeneratorTestFixture } } + [Test] + public void TestReturnSmallPOD() + { + using (var f = new Foo()) + { + foreach(var pod in new[] { f.SmallPodCdecl, f.SmallPodStdcall, f.SmallPodFastcall, f.SmallPodThiscall, f.SmallPodVectorcall }) + { + Assert.That(pod.A, Is.EqualTo(10000)); + Assert.That(pod.B, Is.EqualTo(40000)); + } + } + } + [Test] public void TestPropertyAccessModifier() { diff --git a/tests/CSharp/CSharp.cpp b/tests/CSharp/CSharp.cpp index 5141c808..6edabbef 100644 --- a/tests/CSharp/CSharp.cpp +++ b/tests/CSharp/CSharp.cpp @@ -130,7 +130,6 @@ const Foo& Bar::operator[](int i) const return m_foo; } - Quux::Quux() : _setterWithDefaultOverload(0) { diff --git a/tests/CSharp/CSharp.h b/tests/CSharp/CSharp.h index 958fcf71..88467bf1 100644 --- a/tests/CSharp/CSharp.h +++ b/tests/CSharp/CSharp.h @@ -9,6 +9,12 @@ #include "ExcludedUnit.hpp" #include "CSharpTemplates.h" +struct SmallPOD +{ + int a; + int b; +}; + class DLL_API Foo { public: @@ -40,6 +46,12 @@ public: static int propertyCall(); static int getGetPropertyCall(); + SmallPOD CDECL getSmallPod_cdecl() { return { 10000, 40000 }; } + SmallPOD STDCALL getSmallPod_stdcall() { return { 10000, 40000 }; } + SmallPOD FASTCALL getSmallPod_fastcall() { return { 10000, 40000 }; } + SmallPOD THISCALL getSmallPod_thiscall() { return { 10000, 40000 }; } + SmallPOD VECTORCALL getSmallPod_vectorcall() { return { 10000, 40000 }; } + int operator ++(); int operator --(); operator const char*() const; diff --git a/tests/Tests.h b/tests/Tests.h index f1389d18..5d72be6a 100644 --- a/tests/Tests.h +++ b/tests/Tests.h @@ -15,6 +15,19 @@ #ifndef CDECL #define CDECL __cdecl #endif + +#ifndef FASTCALL +#define FASTCALL __fastcall +#endif + +#ifndef THISCALL +#define THISCALL __thiscall +#endif + +#ifndef VECTORCALL +#define VECTORCALL __vectorcall +#endif + #else #define DLL_API __attribute__ ((visibility ("default"))) @@ -30,6 +43,21 @@ #ifndef CDECL #define CDECL __attribute__((cdecl)) #endif + +#ifndef FASTCALL +#define FASTCALL +#endif + +#ifndef THISCALL +#define THISCALL +#endif + +#ifndef VECTORCALL +#define VECTORCALL +#endif + +#define + #endif #define CS_OUT