From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 177503857033 for ; Wed, 14 Apr 2021 00:20:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 177503857033 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-205-pphLtt9oNwuc2ZvpSoBXAg-1; Tue, 13 Apr 2021 20:20:03 -0400 X-MC-Unique: pphLtt9oNwuc2ZvpSoBXAg-1 Received: by mail-qt1-f197.google.com with SMTP id j10-20020a05622a038ab029019f472c0820so780545qtx.10 for ; Tue, 13 Apr 2021 17:20:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=VhuO+40L4cs1Y7ryM5AyRsYfhKL32thX0ZLLZ0BhHJo=; b=rszaHNS0lvxeFxRRwhrOjate0gAJpONjbNTZsN0cJC8/KgJSIK6PzopJV2hnzTULOB 55cy5oifXzeyIEXLS3PnEGGPL6i2/0zal2UweL9LoGh4VF4mkFaDboXGQ4F386Ym5nQ6 d7dtAiTE1tf/3PHczw2RaVkx3BIfYdhUpt4TYjzVQuJLaXrslccFX8RNu310X4cmCLAF J5qClnOtnMAESqZq9clsWa7Z2d2L9I65hV+yyjrMUP9ow7A+u2V7EuGEJ3etgINCfBa3 JAGVxIoG4vB3GuXogyKjWKHljkaC1BCr6QiLRV4B+RC1yDCfUMNBrw9GnRH/40G4o0DN Qe0Q== X-Gm-Message-State: AOAM532g7cX+PKwFMBgJiRcwE9qHTtixr/YJ5nY1Vjlydtdr2KRMCinc fBvKpInNXuz/DpICJe3JAKRjRPoDDVRcXtqrGBD1l1tEsxRznxq3we6QbrDJ+efPYbMFrxz42Qb uQz3rVvSQYrcNVwSJdaxkW1gexdGKx5ZqW3k+uVe3IH2HWxEdMDrqHf+imp94LKdYRw== X-Received: by 2002:ac8:d87:: with SMTP id s7mr33305400qti.32.1618359602042; Tue, 13 Apr 2021 17:20:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD8hsYo62huxpURlLzl1qMA1GR1XJIhfhKDSPAyn70VCDEgcLZHPOADdQPhCwDSSwvEEV8Ew== X-Received: by 2002:ac8:d87:: with SMTP id s7mr33305368qti.32.1618359601544; Tue, 13 Apr 2021 17:20:01 -0700 (PDT) Received: from barrymore.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id b1sm5539211qto.36.2021.04.13.17.20.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 17:20:00 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: debug location of variable cleanups [PR88742] Date: Tue, 13 Apr 2021 20:19:58 -0400 Message-Id: <20210414001958.344809-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-15.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Apr 2021 00:20:07 -0000 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. Tested x86_64-pc-linux-gnu, applying to trunk. 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 | 5 ++- gcc/cp/semantics.c | 19 +++++++++ .../c-c++-common/Wimplicit-fallthrough-6.c | 16 ++++---- .../c-c++-common/Wimplicit-fallthrough-7.c | 4 +- gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C | 4 +- gcc/testsuite/g++.dg/debug/cleanup1.C | 41 +++++++++++++++++++ .../g++.dg/ext/constexpr-attr-cleanup1.C | 4 +- gcc/testsuite/g++.dg/gcov/gcov-2.C | 4 +- gcc/testsuite/g++.dg/tm/inherit2.C | 4 +- gcc/testsuite/g++.dg/tm/unsafe1.C | 4 +- .../g++.dg/warn/Wimplicit-fallthrough-1.C | 4 +- 11 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/g++.dg/debug/cleanup1.C diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 8b7801b2be7..aec3aa3587f 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -12126,11 +12126,12 @@ cp_parser_compound_statement (cp_parser *parser, tree in_statement_expr, if (function_body) maybe_splice_retval_cleanup (compound_stmt); - /* Finish the compound-statement. */ - finish_compound_stmt (compound_stmt); /* Consume the `}'. */ braces.require_close (parser); + /* Finish the compound-statement. */ + finish_compound_stmt (compound_stmt); + return compound_stmt; } diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 8eaaaefe2d6..125772238d3 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -602,6 +602,22 @@ add_decl_expr (tree decl) add_stmt (r); } +/* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */ + +static void +set_cleanup_locs (tree stmts, location_t loc) +{ + if (TREE_CODE (stmts) == CLEANUP_STMT) + { + protected_set_expr_location (CLEANUP_EXPR (stmts), loc); + set_cleanup_locs (CLEANUP_BODY (stmts), loc); + } + else if (TREE_CODE (stmts) == STATEMENT_LIST) + for (tree_stmt_iterator i = tsi_start (stmts); + !tsi_end_p (i); tsi_next (&i)) + set_cleanup_locs (tsi_stmt (i), loc); +} + /* Finish a scope. */ tree @@ -614,6 +630,9 @@ do_poplevel (tree stmt_list) stmt_list = pop_stmt_list (stmt_list); + /* input_location is the last token of the scope, usually a }. */ + set_cleanup_locs (stmt_list, input_location); + if (!processing_template_decl) { stmt_list = c_build_bind_expr (input_location, block, stmt_list); diff --git a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-6.c b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-6.c index 32d5febda83..9593f670709 100644 --- a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-6.c +++ b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-6.c @@ -121,8 +121,8 @@ L1: int j = 0; bar (j); if (j == 8) - return; /* { dg-warning "statement may fall through" "" { target c++ } } */ - } + return; + } /* { dg-warning "statement may fall through" "" { target c++ } } */ case 2: bar (99); } @@ -151,8 +151,8 @@ L1: if (j == 8) bar (1); else - return; /* { dg-warning "statement may fall through" "" { target c++ } } */ - } + return; + } /* { dg-warning "statement may fall through" "" { target c++ } } */ case 2: bar (99); } @@ -181,8 +181,8 @@ L1: if (j == 8) bar (1); else - bar (2); /* { dg-warning "statement may fall through" "" { target c++ } } */ - } + bar (2); + } /* { dg-warning "statement may fall through" "" { target c++ } } */ case 2: bar (99); } @@ -281,8 +281,8 @@ L1: case 1: { /* { dg-warning "statement may fall through" "" { target c } } */ int j = 9; - switch (j); /* { dg-warning "statement may fall through" "" { target c++ } } */ - } + switch (j); + } /* { dg-warning "statement may fall through" "" { target c++ } } */ case 2: bar (99); } diff --git a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-7.c b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-7.c index a602216fa73..343b6250807 100644 --- a/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-7.c +++ b/gcc/testsuite/c-c++-common/Wimplicit-fallthrough-7.c @@ -22,8 +22,8 @@ f (int i) { case 1: { /* { dg-warning "statement may fall through" "" { target c } } */ - int a[i]; /* { dg-warning "statement may fall through" "" { target c++ } } */ - } + int a[i]; + } /* { dg-warning "statement may fall through" "" { target c++ } } */ case 2: bar (99); } diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C index 193ae93933d..7700bb7b036 100644 --- a/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-dtor3.C @@ -149,9 +149,9 @@ constexpr int x3 = f3 (); constexpr int f4 () { - W7 w13 = 5; // { dg-message "in 'constexpr' expansion of" } + W7 w13 = 5; return 0; -} +} // { dg-message "in 'constexpr' expansion of" } constexpr int x4 = f4 (); // { dg-message "in 'constexpr' expansion of" } diff --git a/gcc/testsuite/g++.dg/debug/cleanup1.C b/gcc/testsuite/g++.dg/debug/cleanup1.C new file mode 100644 index 00000000000..ae0515aef7b --- /dev/null +++ b/gcc/testsuite/g++.dg/debug/cleanup1.C @@ -0,0 +1,41 @@ +// PR c++/88742 +// { dg-additional-options -fdump-tree-gimple-lineno } + + +class C { +public: + C() {} + ~C() {} + operator int() { return 1; } +}; + +int main() { + C a; + C b; + C c; + + if (C e = C()) + { + if (C d = C()) + { + } + else + { + return 42; + } // { dg-final { scan-tree-dump-times ":25:9. C::~C" 1 "gimple" } } + } // { dg-final { scan-tree-dump-times ":26:5. C::~C" 1 "gimple" } } + + while (C f = C()) + { + break; + } // { dg-final { scan-tree-dump-times ":31:5. C::~C" 1 "gimple" } } + + for (C h = C(); C i = C(); ) + break; // { dg-final { scan-tree-dump-times ":34:10. C::~C" 2 "gimple" } } + + switch (C g = C()) + { + default: + break; + } // { dg-final { scan-tree-dump-times ":40:5. C::~C" 1 "gimple" } } +} // { dg-final { scan-tree-dump-times ":41:1. C::~C" 3 "gimple" } } diff --git a/gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C b/gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C index b6e7c691367..ab5fd17e815 100644 --- a/gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C +++ b/gcc/testsuite/g++.dg/ext/constexpr-attr-cleanup1.C @@ -15,9 +15,9 @@ cleanup2 (int *x) constexpr bool foo () { - int a __attribute__((cleanup (cleanup))) = 1; // { dg-message "in 'constexpr' expansion of" } + int a __attribute__((cleanup (cleanup))) = 1; return true; -} +} // { dg-message "in 'constexpr' expansion of" } constexpr bool bar () diff --git a/gcc/testsuite/g++.dg/gcov/gcov-2.C b/gcc/testsuite/g++.dg/gcov/gcov-2.C index 6d002f5d2cd..2b4cdd844e9 100644 --- a/gcc/testsuite/g++.dg/gcov/gcov-2.C +++ b/gcc/testsuite/g++.dg/gcov/gcov-2.C @@ -20,9 +20,9 @@ private: void foo() { - C c; /* count(2) */ + C c; /* count(1) */ c.seti (1); /* count(1) */ -} +} /* count(1) */ int main() { diff --git a/gcc/testsuite/g++.dg/tm/inherit2.C b/gcc/testsuite/g++.dg/tm/inherit2.C index 3b696a9ffb6..366f9b30e90 100644 --- a/gcc/testsuite/g++.dg/tm/inherit2.C +++ b/gcc/testsuite/g++.dg/tm/inherit2.C @@ -26,8 +26,8 @@ int main() B b; // ok D1 d1; // ok B& b1 = d1; - D2 x; // { dg-error "" "destructor of D2 is not transaction-safe" } + D2 x; b1.f(); // ok, calls D1::f() delete b2; // undefined behavior: calls unsafe destructor of D2 - } + } // { dg-error "" "destructor of D2 is not transaction-safe" } } diff --git a/gcc/testsuite/g++.dg/tm/unsafe1.C b/gcc/testsuite/g++.dg/tm/unsafe1.C index 49dd564894a..710fb1a3031 100644 --- a/gcc/testsuite/g++.dg/tm/unsafe1.C +++ b/gcc/testsuite/g++.dg/tm/unsafe1.C @@ -5,8 +5,8 @@ struct S { virtual ~S(); }; void f() transaction_safe { - S s; // { dg-error "unsafe" "invocation of unsafe destructor" } -} + S s; +} // { dg-error "unsafe" "invocation of unsafe destructor" } int g(int x) { // is transaction-safe if (x <= 0) diff --git a/gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C b/gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C index 053ed6885c5..b5ebd3daaad 100644 --- a/gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C +++ b/gcc/testsuite/g++.dg/warn/Wimplicit-fallthrough-1.C @@ -25,8 +25,8 @@ fn2 () switch (0) { case 0: { - A b; // { dg-warning "statement may fall through" } - } + A b; + } // { dg-warning "statement may fall through" } default: a = 0; } base-commit: 6d0d35d518a12ee43c1fbd77df73a66d02305a69 -- 2.27.0