http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58055

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebotcazou at gcc dot gnu.org

--- Comment #3 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
> We currently only apply the NRVO when there is a single variable at the
> topmost level of the function body such that all return statements are of
> this variable. It seems like a wider characterization of the valid cases
> would be when we have an automatic variable whose natural lifetime (from the
> declaration to the end of the scope) includes returns only of this variable.

You can go farther if the return operation overwrites entirely the anonymous
return object and for example allow returning literals, but I don't know if
this is a realistic case in C++; we allow that in Ada.

> That may be easiest to detect in the front-end. Later, the scope would be
> the try block in a try-finally right after a constructor call? In SSA it is
> even less obvious. For return statements, we need to look for a call to a
> copy constructor before a return statement, again more complicated than in
> the FE.

Yes, it's definitely easier to use scoping information in the FE.

> However, actually performing the optimization in the FE is not trivial.  We
> want to remove the calls to the destructor of the variable, but not all,
> only those associated to a return.

In Ada we have little choice but to perform it in the FE, at least for things
like unconstrained array types, because the semantics is lost in the ME.

Reply via email to