[cfe-commits] r89773 - in /cfe/trunk: lib/CodeGen/CGStmt.cpp lib/CodeGen/CodeGenFunction.h test/CodeGenCXX/condition.cpp

Douglas Gregor dgregor at apple.com
Thu Dec 3 09:21:28 PST 2009


On Nov 30, 2009, at 12:06 PM, Daniel Dunbar wrote:

> On Mon, Nov 30, 2009 at 11:52 AM, Douglas Gregor <dgregor at apple.com> wrote:
>> 
>> On Nov 30, 2009, at 11:48 AM, Daniel Dunbar wrote:
>> 
>>> Hi Doug,
>>> 
>>> On Tue, Nov 24, 2009 at 8:43 AM, Douglas Gregor <dgregor at apple.com> wrote:
>>>> 
>>>> Author: dgregor
>>>> Date: Tue Nov 24 10:43:22 2009
>>>> New Revision: 89773
>>>> 
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=89773&view=rev
>>>> Log:
>>>> Introduce cleanup scopes for "if" statements in two places:
>>>>  - Outside the "if", to ensure that we destroy the condition variable
>>>>   at the end of the "if" statement rather than at the end of the
>>>>   block containing the "if" statement.
>>> 
>>> Yay!
>>> 
>>>>  - Inside the "then" and "else" branches, so that we emit then- or
>>>>   else-local cleanups at the end of the corresponding block when the
>>>>   block is not a compound statement.
>>> 
>>> I can't convince myself these are necessary. Cleanups are run in FIFO
>>> order so how is this different than putting them on the cleanup for
>>> the containing statement, since no code is run after the then/else
>>> branches terminate.
>> 
>> 
>> It's for disgusting cases like:
>> 
>>        if (rand() % 2 == 1)
>>          std::string s = "foo";
>>        std::string t = "bar";
>> 
>> so that we destroy "s" after the if statement but before "t", but only if we
>> took the "then" branch.
> 
> Right, I follow that, but there is a cleanup scope around the if
> statement itself, so the cleanups for s can still go there and still
> be run before t, no?


But then we'd call the destructor of "s" unconditionally following the "if" statement, even though "s" won't have been constructed if !(rand() % 2 == 0).

	- Doug



More information about the cfe-commits mailing list