Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/src/dmd/funcsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2769,7 +2769,6 @@ void buildResultVar(FuncDeclaration fd, Scope* sc, Type tret)
* fbody.dsymbolSemantic() running, vresult.type might be modified.
*/
fd.vresult = new VarDeclaration(loc, tret, Id.result, null);
fd.vresult._init = new VoidInitializer(loc); // hdrgen requires _init
fd.vresult.storage_class |= STC.nodtor | STC.temp;
if (!fd.isVirtual())
fd.vresult.storage_class |= STC.const_;
Expand Down
15 changes: 15 additions & 0 deletions compiler/src/dmd/glue/s2ir.d
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,22 @@ void Statement_toIR(Statement s, ref IRState irs, StmtState* stmtstate)
{
// Reference return, so convert to a pointer
e = toElemDtor(s.exp, irs);

/* already taken care of for vresult in buildResultVar() and semantic3.d
* https://issues.dlang.org/show_bug.cgi?id=19384
*/
if (func.vresult)
if (BlitExp be = s.exp.isBlitExp())
{
if (VarExp ve = be.e1.isVarExp())
{
if (ve.var == func.vresult)
goto Lskip;
}
}

e = addressElem(e, s.exp.type.pointerTo());
Lskip:
}
else
{
Expand Down
15 changes: 7 additions & 8 deletions compiler/src/dmd/semantic3.d
Original file line number Diff line number Diff line change
Expand Up @@ -961,10 +961,8 @@ private extern(C++) final class Semantic3Visitor : Visitor

/* https://issues.dlang.org/show_bug.cgi?id=10789
* If NRVO is not possible, all returned lvalues should call their postblits.
* For functions with a __result variable, postblits will be called later
* during initialization of __result.
*/
if (!funcdecl.isNRVO && !funcdecl.vresult)
if (!funcdecl.isNRVO)
exp = doCopyOrMove(sc2, exp, f.next, true, true);

if (tret.hasPointers())
Expand All @@ -975,12 +973,13 @@ private extern(C++) final class Semantic3Visitor : Visitor

if (funcdecl.vresult)
{
Scope* scret = rs.fesFunc ? rs.fesFunc._scope : sc2;
// Create: return vresult = exp;
if (canElideCopy(exp, funcdecl.vresult.type))
exp = new ConstructExp(rs.loc, funcdecl.vresult, exp);
else
exp = new BlitExp(rs.loc, funcdecl.vresult, exp);

// Create: return (vresult = exp, vresult);
exp = new ConstructExp(rs.loc, funcdecl.vresult, exp);
exp = exp.expressionSemantic(scret);
exp = Expression.combine(exp, new VarExp(rs.loc, funcdecl.vresult));
exp.type = funcdecl.vresult.type;

if (rs.caseDim)
exp = Expression.combine(exp, new IntegerExp(rs.caseDim));
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/compilable/extra-files/vcg-ast.d.cg
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class C : Object
}
__require();
this.__invariant();
__result = 2 , __result;
__result = 2;
goto __returnLabel;
__returnLabel:
this.__invariant();
Expand Down
Loading