Skip to content

Commit

Permalink
Merge pull request #4124 from yebblies/issue13707
Browse files Browse the repository at this point in the history
[DDMD] Issue 13707 - msvc32 C++ struct return ABI not followed for structs with constructors
  • Loading branch information
MartinNowak committed Nov 10, 2014
2 parents 6e71574 + 69a5745 commit 452cfcc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/toir.c
Expand Up @@ -914,6 +914,15 @@ RET retStyle(TypeFunction *tf)
//printf(" 2 RETstack\n");
return RETstack; // 32 bit C/C++ structs always on stack
}
if (global.params.isWindows && tf->linkage == LINKcpp && !global.params.is64bit &&
sd->isPOD() && sd->ctor)
{
// win32 returns otherwise POD structs with ctors via memory
// unless it's not really a struct
if (sd->ident == Id::__c_long || sd->ident == Id::__c_ulong)
return RETregs;
return RETstack;
}
if (sd->arg1type && !sd->arg2type)
{
tns = sd->arg1type;
Expand Down
23 changes: 23 additions & 0 deletions test/runnable/cppa.d
Expand Up @@ -609,6 +609,28 @@ void test16()

/****************************************/

struct S13707
{
void* a;
void* b;
this(void* a, void* b)
{
this.a = a;
this.b = b;
}
}

extern(C++) S13707 func13707();

void test13707()
{
auto p = func13707();
assert(p.a == null);
assert(p.b == null);
}

/****************************************/

void main()
{
test1();
Expand All @@ -631,6 +653,7 @@ void main()
test13289();
test15();
test16();
func13707();

printf("Success\n");
}
19 changes: 19 additions & 0 deletions test/runnable/extra-files/cppb.cpp
Expand Up @@ -373,3 +373,22 @@ unsigned long testul(unsigned long ul)

/******************************************/

struct S13707
{
void* a;
void* b;
S13707(void *a, void* b)
{
this->a = a;
this->b = b;
}
};

S13707 func13707()
{
S13707 pt(NULL, NULL);
return pt;
}

/******************************************/

0 comments on commit 452cfcc

Please sign in to comment.