[cfe-commits] [Review] Partial fix for PR 11645: put destructor calls before a return statement.

Xu Zhongxing xuzhongxing at gmail.com
Mon Jan 16 22:18:49 PST 2012


I think the first approach makes more sense from a pragmatic point of view.
The semantics of the return stmt 'return A();' has 3 parts:
1. construct temp object A().
2. copy the object into the return value slot.
3. destruct A().
Since in the analyzer the CFG is linearized, we have to no way to know that
the temp object A() should be copied into the return value slot (whatever
this means for the analysis engine) until we see the ReturnStmt. But if the
dtor is put before the ReturnStmt, the temp object is already destructed
when we want to return it.

So the ReturnStmt is the indicator that the returned value should be
prepared. We should not destruct the object before that.

Plus, the ReturnStmt is not handled as block terminator in the CFG builder
currently. It is only treated as a normal block element.

On Tue, Jan 17, 2012 at 1:29 PM, Ted Kremenek <kremenek at apple.com> wrote:

>  Hi Erik,
>
> Thanks for working on this.  I've commented in the PR.
>
> My concern is that I am having second thoughts about whether or not this
> is the right direction.  If there are temporaries in the return expression,
> should those destructors appear before the 'return' statement (but after
> the subexpression of 'return' gets evaluated)?  I can see it both ways.
>
> For example:
>
>   return A();
>
> where 'A' converts to whatever the return value type should be, and ~A()
> is non-trivial.  Technically, ~A() evaluates after the enclosing statement.
>  We're giving 'return' special treatment in your patch.
>
> One clean representation of this is to put all the destructors after the
> 'return' in the CFGBlock.  The other way is to have the destructors appear
> after the subexpression of 'return', but before the 'return' itself.  The
> former requires clients of the CFG to rethink where they expect 'return' to
> be in a CFGBlock.
>
> What do you think?
>
> Ted
>
> On Thursday, January 12, 2012 at 6:30 AM, Erik Verbruggen wrote:
>
> Hello,
>
> Attached is a patch for one of the things mentioned in PR 11645, which
> is that in the CFG the destructor calls end up after the return statement.
>
> -- Erik.
>
> Attachments:
>  - 0001-CFG-Partial-fix-for-PR-11645-put-destructor-calls-be.patch
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120117/305b1169/attachment.html>


More information about the cfe-commits mailing list