diff --git a/gcc/d/ChangeLog b/gcc/d/ChangeLog index 6283a6580..1e232ad2d 100644 --- a/gcc/d/ChangeLog +++ b/gcc/d/ChangeLog @@ -1,3 +1,8 @@ +2013-07-08 Iain Buclaw + + * d-elem.cc(Expression::toElemDtor): Wrap temp variables destructor + calls in a try/finally expression. + 2013-07-05 Johannes Pfau * patch-versym-os-4.8.x: Set versions on powerpc and alpha. diff --git a/gcc/d/d-elem.cc b/gcc/d/d-elem.cc index 2ded669da..cdc91dd5b 100644 --- a/gcc/d/d-elem.cc +++ b/gcc/d/d-elem.cc @@ -1575,10 +1575,10 @@ Expression::toElemDtor (IRState *irs) tree tdtors = NULL_TREE; for (size_t i = starti; i != endi; ++i) { - VarDeclaration *vd = irs->varsInScope->tdata()[i]; + VarDeclaration *vd = (*irs->varsInScope)[i]; if (vd) { - irs->varsInScope->tdata()[i] = NULL; + (*irs->varsInScope)[i] = NULL; tree td = vd->edtor->toElem (irs); // Execute in reverse order. tdtors = maybe_compound_expr (tdtors, td); @@ -1587,8 +1587,32 @@ Expression::toElemDtor (IRState *irs) if (tdtors != NULL_TREE) { - exp = make_temp (exp); - exp = compound_expr (compound_expr (exp, tdtors), exp); + if (op == TOKcall) + { + // Wrap expression and dtors in a try/finally expression. + tree body = exp; + + if (type->ty == Tvoid) + exp = build2 (TRY_FINALLY_EXPR, void_type_node, body, tdtors); + else + { + body = maybe_make_temp (body); + tree tfexp = build2 (TRY_FINALLY_EXPR, void_type_node, body, tdtors); + exp = compound_expr (tfexp, body); + } + } + else if (op == TOKcomma && ((CommaExp *) this)->e2->op == TOKvar) + { + // Split comma expressions, so as don't require a save_expr. + tree lexp = TREE_OPERAND (exp, 0); + tree rvalue = TREE_OPERAND (exp, 1); + exp = compound_expr (compound_expr (lexp, tdtors), rvalue); + } + else + { + exp = maybe_make_temp (exp); + exp = compound_expr (compound_expr (exp, tdtors), exp); + } } return exp;