public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
@ 2020-11-16 16:13 ` sichert at in dot tum.de
  2023-06-06  1:51 ` jason at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: sichert at in dot tum.de @ 2020-11-16 16:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

Moritz Sichert <sichert at in dot tum.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sichert at in dot tum.de

--- Comment #6 from Moritz Sichert <sichert at in dot tum.de> ---
We are also running into this bug when using RAII lock guards and goto to
"retry" the section guarded by the lock.

I think the standard is very clear that the destructor should be called:

"Transfer out of a loop, out of a block, or back past an initialized variable
with automatic storage duration involves the destruction of objects with
automatic storage duration that are in scope at the point transferred from but
not at the point transferred to."

N4861: Section 8.7 (2)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
  2020-11-16 16:13 ` [Bug c++/92407] Destruction of objects returned from functions skipped by goto sichert at in dot tum.de
@ 2023-06-06  1:51 ` jason at gcc dot gnu.org
  2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2023-06-06  1:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
  2020-11-16 16:13 ` [Bug c++/92407] Destruction of objects returned from functions skipped by goto sichert at in dot tum.de
  2023-06-06  1:51 ` jason at gcc dot gnu.org
@ 2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
  2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-07  1:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:b192e2007e1c98b548f4aa878523b485968d24a4

commit r14-1592-gb192e2007e1c98b548f4aa878523b485968d24a4
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jun 4 12:00:55 2023 -0400

    c++: NRV and goto [PR92407]

    Here our named return value optimization was breaking the required
    destructor when the goto takes 'a' out of scope.  The simplest fix is to
    disable the optimization in the presence of user labels.

    We could do better by disabling the optimization only if there is a
backward
    goto across the variable declaration, but we don't currently track that.

            PR c++/92407

    gcc/cp/ChangeLog:

            * typeck.cc (check_return_expr): Prevent NRV in the presence of
            named labels.

    gcc/testsuite/ChangeLog:

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
@ 2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
  2023-06-07  1:35 ` jason at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-07  1:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Jason Merrill <jason@gcc.gnu.org>:

https://gcc.gnu.org/g:7e0b65b239c3a0d68ce94896b236b03de666ffd6

commit r14-1593-g7e0b65b239c3a0d68ce94896b236b03de666ffd6
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jun 4 12:09:11 2023 -0400

    c++: enable NRVO from inner block [PR51571]

    Our implementation of the named return value optimization has been limited
    to variables declared in the outermost block of the function, to avoid
    needing to handle the case where the variable needs to be destroyed due to
    going out of scope.  PR92407 pointed out a case we were missing, where the
    variable goes out of scope due to a goto and we were failing to destroy it.

    It occurred to me that this problem is the flip side of PR33799, where we
    need to be sure to destroy the return value if a cleanup throws on return;
    here we want to avoid destroying the return value when exiting the
    variable's scope on return.  We can use the same flag to indicate to both
    cleanups that we're returning.

    This implements the guaranteed copy elision specified by P2025 (which is
not
    yet part of the draft standard).

            PR c++/51571
            PR c++/92407

    gcc/cp/ChangeLog:

            * decl.cc (finish_function): Simplify NRV handling.
            * except.cc (maybe_set_retval_sentinel): Also set if NRV.
            (maybe_splice_retval_cleanup): Don't add the cleanup region
            if we don't need it.
            * semantics.cc (nrv_data): Add simple field.
            (finalize_nrv): Set it.
            (finalize_nrv_r): Check it and retval sentinel.
            * cp-tree.h (finalize_nrv): Adjust declaration.
            * typeck.cc (check_return_expr): Remove named_labels check.

    gcc/testsuite/ChangeLog:

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
@ 2023-06-07  1:35 ` jason at gcc dot gnu.org
  2023-08-31 22:40 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2023-06-07  1:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

--- Comment #9 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 14 so far.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2023-06-07  1:35 ` jason at gcc dot gnu.org
@ 2023-08-31 22:40 ` cvs-commit at gcc dot gnu.org
  2023-12-20 17:41 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-08-31 22:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:a645347c19b07cc7abd7bf276c6769fc41afc932

commit r13-7770-ga645347c19b07cc7abd7bf276c6769fc41afc932
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jun 4 12:00:55 2023 -0400

    c++: NRV and goto [PR92407]

    Here our named return value optimization was breaking the required
    destructor when the goto takes 'a' out of scope.  A simple fix for the
    release branches is to disable the optimization in the presence of backward
    goto.

    We could do better by disabling the optimization only if there is a
backward
    goto across the variable declaration, but we don't track that, and in GCC
14
    we instead make the goto work with NRV.

            PR c++/92407

    gcc/cp/ChangeLog:

            * cp-tree.h (struct language_function): Add backward_goto.
            * decl.cc (check_goto): Set it.
            * typeck.cc (check_return_expr): Prevent NRV if set.

    gcc/testsuite/ChangeLog:

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2023-08-31 22:40 ` cvs-commit at gcc dot gnu.org
@ 2023-12-20 17:41 ` cvs-commit at gcc dot gnu.org
  2023-12-20 17:46 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-20 17:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

--- Comment #11 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:32bd8a1053d25cbb15172294e59a81bc134658aa

commit r11-11162-g32bd8a1053d25cbb15172294e59a81bc134658aa
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jun 4 12:00:55 2023 -0400

    c++: NRV and goto [PR92407]

    Here our named return value optimization was breaking the required
    destructor when the goto takes 'a' out of scope.  A simple fix for the
    release branches is to disable the optimization in the presence of backward
    goto.

    We could do better by disabling the optimization only if there is a
backward
    goto across the variable declaration, but we don't track that, and in GCC
14
    we instead make the goto work with NRV.

            PR c++/92407

    gcc/cp/ChangeLog:

            * cp-tree.h (struct language_function): Add backward_goto.
            * decl.c (check_goto): Set it.
            * typeck.c (check_return_expr): Prevent NRV if set.

    gcc/testsuite/ChangeLog:

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

    (cherry picked from commit a645347c19b07cc7abd7bf276c6769fc41afc932)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2023-12-20 17:41 ` cvs-commit at gcc dot gnu.org
@ 2023-12-20 17:46 ` jason at gcc dot gnu.org
  2024-01-24 19:40 ` cvs-commit at gcc dot gnu.org
  2024-02-05 18:20 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2023-12-20 17:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|---                         |11.5

--- Comment #12 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 11.5/12.4/13.3/14.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2023-12-20 17:46 ` jason at gcc dot gnu.org
@ 2024-01-24 19:40 ` cvs-commit at gcc dot gnu.org
  2024-02-05 18:20 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-24 19:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:

https://gcc.gnu.org/g:193321d2649a818c3b322c8db79a2805cfdd7095

commit r12-10109-g193321d2649a818c3b322c8db79a2805cfdd7095
Author: Jason Merrill <jason@redhat.com>
Date:   Sun Jun 4 12:00:55 2023 -0400

    c++: NRV and goto [PR92407]

    Here our named return value optimization was breaking the required
    destructor when the goto takes 'a' out of scope.  A simple fix for the
    release branches is to disable the optimization in the presence of backward
    goto.

    We could do better by disabling the optimization only if there is a
backward
    goto across the variable declaration, but we don't track that, and in GCC
14
    we instead make the goto work with NRV.

            PR c++/92407

    gcc/cp/ChangeLog:

            * cp-tree.h (struct language_function): Add backward_goto.
            * decl.cc (check_goto): Set it.
            * typeck.cc (check_return_expr): Prevent NRV if set.

    gcc/testsuite/ChangeLog:

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

    (cherry picked from commit a645347c19b07cc7abd7bf276c6769fc41afc932)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug c++/92407] Destruction of objects returned from functions skipped by goto
       [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2024-01-24 19:40 ` cvs-commit at gcc dot gnu.org
@ 2024-02-05 18:20 ` jason at gcc dot gnu.org
  9 siblings, 0 replies; 10+ messages in thread
From: jason at gcc dot gnu.org @ 2024-02-05 18:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92407

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |joerg.richter@pdv-fs.de

--- Comment #14 from Jason Merrill <jason at gcc dot gnu.org> ---
*** Bug 113767 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-02-05 18:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-92407-4@http.gcc.gnu.org/bugzilla/>
2020-11-16 16:13 ` [Bug c++/92407] Destruction of objects returned from functions skipped by goto sichert at in dot tum.de
2023-06-06  1:51 ` jason at gcc dot gnu.org
2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
2023-06-07  1:33 ` cvs-commit at gcc dot gnu.org
2023-06-07  1:35 ` jason at gcc dot gnu.org
2023-08-31 22:40 ` cvs-commit at gcc dot gnu.org
2023-12-20 17:41 ` cvs-commit at gcc dot gnu.org
2023-12-20 17:46 ` jason at gcc dot gnu.org
2024-01-24 19:40 ` cvs-commit at gcc dot gnu.org
2024-02-05 18:20 ` jason at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).