From 18d53f89379d8eb3ec18642d66d226501cfa3b35 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Wed, 20 Nov 2013 21:29:50 +0100 Subject: [PATCH] Enable NRVO for static arrays. This is new in 2.064 and fixes a test failure in runnable/sdtor.d. --- gen/llvmhelpers.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index adee6112..99309520 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1139,13 +1139,21 @@ void DtoVarDeclaration(VarDeclaration* vd) T t = f(); // t's memory address is taken hidden pointer */ ExpInitializer *ei = 0; - if (vd->type->toBasetype()->ty == Tstruct && vd->init && - !!(ei = vd->init->isExpInitializer())) + if ((vd->type->toBasetype()->ty == Tstruct || + vd->type->toBasetype()->ty == Tsarray /* new in 2.064*/) && + vd->init && + (ei = vd->init->isExpInitializer())) { if (ei->exp->op == TOKconstruct) { AssignExp *ae = static_cast(ei->exp); - if (ae->e2->op == TOKcall) { - CallExp *ce = static_cast(ae->e2); + // The return value can be casted to a different type. + // Just look at the original expression in this case. + // Happens with runnable/sdtor, test10094(). + Expression *rhs = ae->e2; + if (rhs->op == TOKcast) + rhs = static_cast(rhs)->e1; + if (rhs->op == TOKcall) { + CallExp *ce = static_cast(rhs); TypeFunction *tf = static_cast(ce->e1->type->toBasetype()); if (tf->ty == Tfunction && tf->linkage != LINKintrinsic) { gABI->newFunctionType(tf);