public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/84471] Instruction reordering happens in lambdas even with -O0
       [not found] <bug-84471-4@http.gcc.gnu.org/bugzilla/>
@ 2022-11-01 23:44 ` pinskia at gcc dot gnu.org
  2022-11-02 14:21 ` [Bug c++/84471] Debugger jumps back to lambda capture location every time a captured variable is odr-used redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-01 23:44 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=107504

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
  const char[19] & key [value-expr: [/app/example.cpp:9:34] __closure->__key];

very similar issue to PR 107504. The VALUE_EXPR has a line info on it which
gets copied when referencing key in other places.

Either we should remove the line info on the VALUE_EXPR on creation or when
doing the copy.

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

* [Bug c++/84471] Debugger jumps back to lambda capture location every time  a captured variable is odr-used
       [not found] <bug-84471-4@http.gcc.gnu.org/bugzilla/>
  2022-11-01 23:44 ` [Bug c++/84471] Instruction reordering happens in lambdas even with -O0 pinskia at gcc dot gnu.org
@ 2022-11-02 14:21 ` redi at gcc dot gnu.org
  2022-12-02  4:01 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-02 14:21 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Instruction reordering      |Debugger jumps back to
                   |happens in lambdas even     |lambda capture location
                   |with -O0                    |every time  a captured
                   |                            |variable is odr-used

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Every time a captured variable is odr-used in the lambda body, the debugger
jumps back to the location of the capture list:

$ cat lambda.cc 
int main(int argc, char**)
{
  int x = 1;
  auto f = [&x, &argc](const char* i) {
    i += x;
    i -= argc;
    i += argc - x;
    return i;
  };
  f("          ");
}
$ g++ -g lambda.cc -o lambda
$ gdb -q -ex start -ex 'py [gdb.execute("step") for n in range(14)]' ./lambda
Reading symbols from ./lambda...
Temporary breakpoint 1 at 0x40117a: file lambda.cc, line 3.
Starting program: /tmp/lambda 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main (argc=1) at lambda.cc:3
3         int x = 1;
9         };
10        f("          ");
operator() (__closure=0x7fffffffda60, i=0x402004 "          ") at lambda.cc:5
5           i += x;
4         auto f = [&x, &argc](const char* i) {
5           i += x;
6           i -= argc;
4         auto f = [&x, &argc](const char* i) {
6           i -= argc;
7           i += argc - x;
4         auto f = [&x, &argc](const char* i) {
7           i += argc - x;
4         auto f = [&x, &argc](const char* i) {
7           i += argc - x;
8           return i;

We keep returning to line 4 (the capture) every time the captured variiable is
odr-used.


I've updated the summary. There is no instruction reordering, the debuginfo
just contains line info that causes the debugger to jump around. That has
nothing to do with the actual instructions being executed.

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

* [Bug c++/84471] Debugger jumps back to lambda capture location every time  a captured variable is odr-used
       [not found] <bug-84471-4@http.gcc.gnu.org/bugzilla/>
  2022-11-01 23:44 ` [Bug c++/84471] Instruction reordering happens in lambdas even with -O0 pinskia at gcc dot gnu.org
  2022-11-02 14:21 ` [Bug c++/84471] Debugger jumps back to lambda capture location every time a captured variable is odr-used redi at gcc dot gnu.org
@ 2022-12-02  4:01 ` jason at gcc dot gnu.org
  2022-12-21  2:04 ` cvs-commit at gcc dot gnu.org
  2023-03-02 22:24 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2022-12-02  4:01 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

* [Bug c++/84471] Debugger jumps back to lambda capture location every time  a captured variable is odr-used
       [not found] <bug-84471-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2022-12-02  4:01 ` jason at gcc dot gnu.org
@ 2022-12-21  2:04 ` cvs-commit at gcc dot gnu.org
  2023-03-02 22:24 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-12-21  2:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:302485a70a33f3a86e85ad9051de2b51c5dc0bc0

commit r13-4812-g302485a70a33f3a86e85ad9051de2b51c5dc0bc0
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Dec 1 22:58:28 2022 -0500

    c++: source position of lambda captures [PR84471]

    If the DECL_VALUE_EXPR of a VAR_DECL has EXPR_LOCATION set, then any use of
    that variable looks like it has that location, which leads to the debugger
    jumping back and forth for both lambdas and structured bindings.

    Rather than fix all the uses, it seems simplest to remove any EXPR_LOCATION
    when setting DECL_VALUE_EXPR.  So the cp/ hunks aren't necessary, but they
    avoid the need to unshare to remove the location.

            PR c++/84471
            PR c++/107504

    gcc/cp/ChangeLog:

            * coroutines.cc (transform_local_var_uses): Don't
            specify a location for DECL_VALUE_EXPR.
            * decl.cc (cp_finish_decomp): Likewise.

    gcc/ChangeLog:

            * fold-const.cc (protected_set_expr_location_unshare): Not static.
            * tree.h: Declare it.
            * tree.cc (decl_value_expr_insert): Use it.

    include/ChangeLog:

            * ansidecl.h (ATTRIBUTE_WARN_UNUSED_RESULT): Add __.

    gcc/testsuite/ChangeLog:

            * g++.dg/tree-ssa/value-expr1.C: New test.
            * g++.dg/tree-ssa/value-expr2.C: New test.
            * g++.dg/analyzer/pr93212.C: Move warning.

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

* [Bug c++/84471] Debugger jumps back to lambda capture location every time  a captured variable is odr-used
       [not found] <bug-84471-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2022-12-21  2:04 ` cvs-commit at gcc dot gnu.org
@ 2023-03-02 22:24 ` jason at gcc dot gnu.org
  4 siblings, 0 replies; 5+ messages in thread
From: jason at gcc dot gnu.org @ 2023-03-02 22:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for GCC 13.

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

end of thread, other threads:[~2023-03-02 22:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-84471-4@http.gcc.gnu.org/bugzilla/>
2022-11-01 23:44 ` [Bug c++/84471] Instruction reordering happens in lambdas even with -O0 pinskia at gcc dot gnu.org
2022-11-02 14:21 ` [Bug c++/84471] Debugger jumps back to lambda capture location every time a captured variable is odr-used redi at gcc dot gnu.org
2022-12-02  4:01 ` jason at gcc dot gnu.org
2022-12-21  2:04 ` cvs-commit at gcc dot gnu.org
2023-03-02 22:24 ` 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).