public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107504] New: Debugger jumps back to structured binding declaration
@ 2022-11-01 23:16 redi at gcc dot gnu.org
  2022-11-01 23:22 ` [Bug c++/107504] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-01 23:16 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107504
           Summary: Debugger jumps back to structured binding declaration
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

struct S
{
  void* i;
  int j;
};

S f(char* p)
{
  return {p, 1};
}

int main()
{
  char buf[1];
  auto [x, y] = f(buf);
  if (x != buf)
    throw 1;
  if (y != 1)
    throw 2;
  return 0;
}

Compiled with -g the debugger shows control jumping backwards to the structured
binding declaration:

$ gdb --quiet -ex start -ex n -ex n -ex n -ex n a.out
Reading symbols from a.out...
Temporary breakpoint 1 at 0x40115f: file sb.C, line 15.
Starting program: /tmp/a.out 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at sb.C:15
15        auto [x, y] = f(buf);
16        if (x != buf)
15        auto [x, y] = f(buf);
18        if (y != 1)
20        return 0;


For a slightly larger piece of code I see it jump back to it three times:

$ gdb --quiet -ex start -ex step  -ex n -ex n -ex n -ex n -ex n -ex n -ex n
a.out
Reading symbols from a.out...
Temporary breakpoint 1 at 0x405aa3: file fton.C, line 43.
Starting program: /tmp/a.out 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Temporary breakpoint 1, main () at fton.C:43
43        test();
test () at fton.C:14
14        char buf[4] = { };
15        auto [out, len] = std::format_to_n(buf, 3, "123 + 456 = {}", 579);
16        VERIFY( out == buf+3 );
15        auto [out, len] = std::format_to_n(buf, 3, "123 + 456 = {}", 579);
16        VERIFY( out == buf+3 );
15        auto [out, len] = std::format_to_n(buf, 3, "123 + 456 = {}", 579);
17        VERIFY( len == 15 );
19        std::locale loc({}, new punct);

Notice line 15 occurs three times. I haven't been able to reproduce that in the
minimized test case.

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

* [Bug c++/107504] Debugger jumps back to structured binding declaration
  2022-11-01 23:16 [Bug c++/107504] New: Debugger jumps back to structured binding declaration redi at gcc dot gnu.org
@ 2022-11-01 23:22 ` pinskia at gcc dot gnu.org
  2022-11-01 23:26 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-01 23:22 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
          Component|debug                       |c++
           Keywords|                            |wrong-debug
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-11-01

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---

        [/app/example.cpp:15:22] _2 = [/app/example.cpp:15:22] D.2776.j;
        [/app/example.cpp:18:3] if (_2 != 1) goto <D.2822>; else goto <D.2823>;

Most likely because the COMPONENT_REF has a line # on it:

    void * x [value-expr: [/app/example.cpp:15:22] D.2776.i];
    int y [value-expr: [/app/example.cpp:15:22] D.2776.j];

Seems like if we remove that, this would work.

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

* [Bug c++/107504] Debugger jumps back to structured binding declaration
  2022-11-01 23:16 [Bug c++/107504] New: Debugger jumps back to structured binding declaration redi at gcc dot gnu.org
  2022-11-01 23:22 ` [Bug c++/107504] " pinskia at gcc dot gnu.org
@ 2022-11-01 23:26 ` pinskia at gcc dot gnu.org
  2022-11-02 11:58 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-01 23:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The code that creates the COMPONENT_REF is the call to
finish_non_static_data_member around decl.cc:9186 .

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

* [Bug c++/107504] Debugger jumps back to structured binding declaration
  2022-11-01 23:16 [Bug c++/107504] New: Debugger jumps back to structured binding declaration redi at gcc dot gnu.org
  2022-11-01 23:22 ` [Bug c++/107504] " pinskia at gcc dot gnu.org
  2022-11-01 23:26 ` pinskia at gcc dot gnu.org
@ 2022-11-02 11:58 ` redi at gcc dot gnu.org
  2022-11-02 14:08 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2022-11-02 11:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
I'm also seeing similar jumps back and forth in the debugger for the bodies of
lambda expressions, where the debugger keeps jumping back to the capture list
of the lambda:


$ 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.

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

* [Bug c++/107504] Debugger jumps back to structured binding declaration
  2022-11-01 23:16 [Bug c++/107504] New: Debugger jumps back to structured binding declaration redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-11-02 11:58 ` redi at gcc dot gnu.org
@ 2022-11-02 14:08 ` pinskia at gcc dot gnu.org
  2022-12-02  4:01 ` jason at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-02 14:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #3)
> I'm also seeing similar jumps back and forth in the debugger for the bodies
> of lambda expressions, where the debugger keeps jumping back to the capture
> list of the lambda:

Yes see PR 84471 for the lambda issue.

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

* [Bug c++/107504] Debugger jumps back to structured binding declaration
  2022-11-01 23:16 [Bug c++/107504] New: Debugger jumps back to structured binding declaration redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-11-02 14:08 ` pinskia 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
  6 siblings, 0 replies; 8+ 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=107504

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

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

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

* [Bug c++/107504] Debugger jumps back to structured binding declaration
  2022-11-01 23:16 [Bug c++/107504] New: Debugger jumps back to structured binding declaration redi at gcc dot gnu.org
                   ` (4 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
  6 siblings, 0 replies; 8+ 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=107504

--- 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] 8+ messages in thread

* [Bug c++/107504] Debugger jumps back to structured binding declaration
  2022-11-01 23:16 [Bug c++/107504] New: Debugger jumps back to structured binding declaration redi at gcc dot gnu.org
                   ` (5 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
  6 siblings, 0 replies; 8+ 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=107504

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

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

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

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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-01 23:16 [Bug c++/107504] New: Debugger jumps back to structured binding declaration redi at gcc dot gnu.org
2022-11-01 23:22 ` [Bug c++/107504] " pinskia at gcc dot gnu.org
2022-11-01 23:26 ` pinskia at gcc dot gnu.org
2022-11-02 11:58 ` redi at gcc dot gnu.org
2022-11-02 14:08 ` pinskia 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).