[Bug c++/58487] Missed return value optimization

2023-12-19 Thread jason at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

Jason Merrill  changed:

   What|Removed |Added

 CC||jason at gcc dot gnu.org
   Target Milestone|--- |14.0
 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #9 from Jason Merrill  ---
Fixed for GCC 14.

[Bug c++/58487] Missed return value optimization

2023-06-09 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

--- Comment #8 from CVS Commits  ---
The trunk branch has been updated by Jason Merrill :

https://gcc.gnu.org/g:953bbeaeff050f4d0b670568a587aa1ce82ed711

commit r14-1660-g953bbeaeff050f4d0b670568a587aa1ce82ed711
Author: Jason Merrill 
Date:   Fri Jun 9 10:37:35 2023 -0400

c++: fix 32-bit spaceship failures [PR110185]

Various spaceship tests failed after r14-1624.  This turned out to be
because the comparison category classes return in memory on 32-bit targets,
and the synthesized operator<=> looks something like

if (auto v = a.x <=> b.x, v == 0); else return v;
if (auto v = a.y <=> b.y, v == 0); else return v;
etc.

so check_return_expr was trying to do NRVO for all the 'v' variables, and
now on subsequent returns we check to see if the previous NRV is still in
scope.  But the NRVs didn't have names, so looking up name bindings
crashed.
Fixed both by giving 'v' a name so we can NRVO the first one, and fixing
the
test to give up if the old NRV has no name.

PR c++/110185
PR c++/58487

gcc/cp/ChangeLog:

* method.cc (build_comparison_op): Give retval a name.
* typeck.cc (check_return_expr): Fix for nameless variables.

[Bug c++/58487] Missed return value optimization

2023-06-07 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

--- Comment #7 from CVS Commits  ---
The trunk branch has been updated by Jason Merrill :

https://gcc.gnu.org/g:28db36e2cfca1b7106adc8d371600fa3a325c4e2

commit r14-1624-g28db36e2cfca1b7106adc8d371600fa3a325c4e2
Author: Jason Merrill 
Date:   Wed Jun 7 05:15:02 2023 -0400

c++: allow NRV and non-NRV returns [PR58487]

Now that we support NRV from an inner block, we can also support non-NRV
returns from other blocks, since once the NRV is out of scope a later
return
expression can't possibly alias it.

This fixes 58487 and half-fixes 53637: now one of the returns is elided,
but
not the other.

Fixing the remaining xfails in these testcases will require a very
different
approach, probably involving a full tree/block walk from finalize_nrv, and
check_return_expr only adding to a list of potential return variables.

PR c++/58487
PR c++/53637

gcc/cp/ChangeLog:

* cp-tree.h (INIT_EXPR_NRV_P): New.
* semantics.cc (finalize_nrv_r): Check it.
* name-lookup.h (decl_in_scope_p): Declare.
* name-lookup.cc (decl_in_scope_p): New.
* typeck.cc (check_return_expr): Allow non-NRV
returns if the NRV is no longer in scope.

gcc/testsuite/ChangeLog:

* g++.dg/opt/nrv26.C: New test.
* g++.dg/opt/nrv26a.C: New test.
* g++.dg/opt/nrv27.C: New test.

[Bug c++/58487] Missed return value optimization

2023-06-06 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

--- Comment #6 from CVS Commits  ---
The trunk branch has been updated by Jason Merrill :

https://gcc.gnu.org/g:2ae5384d457b9c67586de012816dfc71a6943164

commit r14-1594-g2ae5384d457b9c67586de012816dfc71a6943164
Author: Jason Merrill 
Date:   Tue Jun 6 12:46:26 2023 -0400

c++: Add -Wnrvo

While looking at PRs about cases where we don't perform the named return
value optimization, it occurred to me that it might be useful to have a
warning for that.

This does not fix PR58487, but might be interesting to people watching it.

PR c++/58487

gcc/c-family/ChangeLog:

* c.opt: Add -Wnrvo.

gcc/ChangeLog:

* doc/invoke.texi: Document it.

gcc/cp/ChangeLog:

* typeck.cc (want_nrvo_p): New.
(check_return_expr): Handle -Wnrvo.

gcc/testsuite/ChangeLog:

* g++.dg/opt/nrv25.C: New test.

[Bug c++/58487] Missed return value optimization

2023-06-06 Thread jason at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

--- Comment #5 from Jason Merrill  ---
*** Bug 96004 has been marked as a duplicate of this bug. ***

[Bug c++/58487] Missed return value optimization

2021-11-19 Thread gcc_bugzilla at axeitado dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

Óscar Fuentes  changed:

   What|Removed |Added

 CC||gcc_bugzilla at axeitado dot 
com

--- Comment #4 from Óscar Fuentes  ---
Isn't this PR a trivial variation of PR53637 ?

[Bug c++/58487] Missed return value optimization

2021-06-28 Thread antoshkka at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

Antony Polukhin  changed:

   What|Removed |Added

 CC||antoshkka at gmail dot com

--- Comment #3 from Antony Polukhin  ---
Minimized example, move constructor should not be called:

struct A {
  A() = default;
  A(A&&);
};

A test() {
  if (true) {
A a;
return a;
  } else {
return A{};
  }
}


Godbolt playground: https://godbolt.org/z/4Pzq83WWY

[Bug c++/58487] Missed return value optimization

2016-08-13 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2016-08-14
 Ever confirmed|0   |1

--- Comment #2 from Andrew Pinski  ---
Confirmed.

[Bug c++/58487] Missed return value optimization

2016-07-26 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement

[Bug c++/58487] Missed return value optimization

2016-07-26 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement

[Bug c++/58487] Missed return value optimization

2013-09-20 Thread glisse at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58487

Marc Glisse glisse at gcc dot gnu.org changed:

   What|Removed |Added

   Keywords||missed-optimization

--- Comment #1 from Marc Glisse glisse at gcc dot gnu.org ---
PR53637 or one of the other RVO PRs (see the meta PR 58055).