c++: debug location of variable cleanups [PR88742]
authorJason Merrill <jason@redhat.com>
Tue, 13 Apr 2021 20:18:54 +0000 (16:18 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 14 Apr 2021 00:17:58 +0000 (20:17 -0400)
commit006783f4b165dff25aae3697920fcf54754dddd4
tree0d473b30518596d5f997103a4f1c01786aee9d3c
parent6d0d35d518a12ee43c1fbd77df73a66d02305a69
c++: debug location of variable cleanups [PR88742]

PR49951 complained about the debugger jumping back to the declaration of a
local variable when we run its destructor.  That was fixed in 4.7, but broke
again in 4.8.  PR58123 fixed an inconsistency in the behavior, but not the
jumping around.  This patch addresses the issue by setting EXPR_LOCATION on
a cleanup destructor call to the location of the closing brace of the
compound-statement, or whatever token ends the scope of the variable.

The change to cp_parser_compound_statement is so input_location is the }
rather than the ; of the last substatement.

gcc/cp/ChangeLog:

PR c++/88742
PR c++/49951
PR c++/58123
* semantics.c (set_cleanup_locs): New.
(do_poplevel): Call it.
* parser.c (cp_parser_compound_statement): Consume the }
before finish_compound_stmt.

gcc/testsuite/ChangeLog:

PR c++/88742
* g++.dg/debug/cleanup1.C: New test.
* c-c++-common/Wimplicit-fallthrough-6.c: Adjust diagnostic line.
* c-c++-common/Wimplicit-fallthrough-7.c: Likewise.
* g++.dg/cpp2a/constexpr-dtor3.C: Likewise.
* g++.dg/ext/constexpr-attr-cleanup1.C: Likewise.
* g++.dg/tm/inherit2.C: Likewise.
* g++.dg/tm/unsafe1.C: Likewise.
* g++.dg/warn/Wimplicit-fallthrough-1.C: Likewise.
* g++.dg/gcov/gcov-2.C: Adjust coverage counts.
gcc/cp/parser.c
gcc/cp/semantics.c
gcc/testsuite/c-c++-common/Wimplicit-fallthrough-6.c
gcc/testsuite/c-c++-common/Wimplicit-fallthrough-7.c
gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C
gcc/testsuite/g++.dg/debug/cleanup1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C
gcc/testsuite/g++.dg/gcov/gcov-2.C
gcc/testsuite/g++.dg/tm/inherit2.C
gcc/testsuite/g++.dg/tm/unsafe1.C
gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C