Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Commit

Permalink
Bug 70 - dtor/destructor not called for (rvalue) struct used in opApply.
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain Buclaw committed Jul 9, 2013
1 parent e02b8eb commit 9a30148
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
5 changes: 5 additions & 0 deletions gcc/d/ChangeLog
@@ -1,3 +1,8 @@
2013-07-08 Iain Buclaw <ibuclaw@gdcproject.org>

* d-elem.cc(Expression::toElemDtor): Wrap temp variables destructor
calls in a try/finally expression.

2013-07-05 Johannes Pfau <johannespfau@gmail.com>

* patch-versym-os-4.8.x: Set versions on powerpc and alpha.
Expand Down
32 changes: 28 additions & 4 deletions gcc/d/d-elem.cc
Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit 9a30148

Please sign in to comment.