Adapt to new special-ref result variables in out contracts

The AST now features special-ref result variables (storage classes:
ref, temp, result) after rewriting out contracts; from dmd/func.d:

/*   out(id1) { statements1... }
 *   out(id2) { statements2... }
 *   ...
 * becomes:
 *   out(__result) { { ref id1 = __result; { statements1... } }
 *                   { ref id2 = __result; { statements2... } } ... }
 */

We are talking about the `id1` and `id2` variables here.
There's an existing assertion that we don't set a special-ref variable's
lvalue (T**) to the sret pointer (T*) which was already triggered when
compiling Phobos without unittests.
This commit is contained in:
Martin Kinkelin 2018-06-20 21:31:52 +02:00
parent 2b76e23bfe
commit 6dfaebb33e

View file

@ -966,9 +966,10 @@ void DtoVarDeclaration(VarDeclaration *vd) {
if (isIrLocalCreated(vd)) {
// Nothing to do if it has already been allocated.
} else if (gIR->func()->sretArg && ((gIR->func()->decl->nrvo_can &&
gIR->func()->decl->nrvo_var == vd) ||
vd->isResult())) {
} else if (gIR->func()->sretArg &&
((gIR->func()->decl->nrvo_can &&
gIR->func()->decl->nrvo_var == vd) ||
(vd->isResult() && !isSpecialRefVar(vd)))) {
// Named Return Value Optimization (NRVO):
// T f() {
// T ret; // &ret == hidden pointer