Skip to content

Commit 97819eb

Browse files
committed
Merge pull request #1109 from klickverbot/fix-struct-lval
Properly mark stack slot for struct return as lvalue
2 parents 66900eb + e624a96 commit 97819eb

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

gen/tocall.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
802802
(returnTy == Tstruct && !isaPointer(retllval)) ||
803803
(returnTy == Tsarray && isaArray(retllval));
804804

805+
bool retValIsAlloca = false;
806+
805807
// Ignore ABI for intrinsics
806808
if (!intrinsic && !retinptr)
807809
{
@@ -812,6 +814,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
812814
LLValue* mem = DtoAlloca(returntype);
813815
irFty.getRet(returntype, retllval, mem);
814816
retllval = mem;
817+
retValIsAlloca = true;
815818
storeReturnValueOnStack = false;
816819
}
817820
else
@@ -827,6 +830,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
827830
{
828831
Logger::println("Storing return value to stack slot");
829832
retllval = DtoAllocaDump(retllval, returntype);
833+
retValIsAlloca = true;
830834
}
831835

832836
// repaint the type if necessary
@@ -955,7 +959,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
955959
// if we are returning through a pointer arg
956960
// or if we are returning a reference
957961
// make sure we provide a lvalue back!
958-
if (retinptr || (tf->isref && returnTy != Tvoid))
962+
if (retinptr || (tf->isref && returnTy != Tvoid) || retValIsAlloca)
959963
return new DVarValue(resulttype, retllval);
960964

961965
return new DImValue(resulttype, retllval);

0 commit comments

Comments
 (0)