public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6169] c++: don't wrap cleanups that can't throw Date: Sun, 2 Jan 2022 17:56:09 +0000 (GMT) [thread overview] Message-ID: <20220102175609.D7E3E3858427@sourceware.org> (raw) https://gcc.gnu.org/g:092e60f57adeccf98e876af6b7b5734337904812 commit r12-6169-g092e60f57adeccf98e876af6b7b5734337904812 Author: Jason Merrill <jason@redhat.com> Date: Thu Dec 30 00:10:57 2021 -0500 c++: don't wrap cleanups that can't throw Since C++11, the vast majority of destructors are noexcept, so wrap_temporary_cleanups adds a bunch of useless TRY_CATCH_EXPR to be removed later in the optimizers. It's simple to avoid adding them in the first place. gcc/cp/ChangeLog: * decl.c (wrap_cleanups_r): Don't wrap if noexcept. gcc/testsuite/ChangeLog: * g++.dg/eh/cleanup6.C: New test. Diff: --- gcc/cp/decl.c | 14 ++++++++------ gcc/testsuite/g++.dg/eh/cleanup6.C | 13 +++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 982fca8983d..51c69957635 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7428,12 +7428,14 @@ wrap_cleanups_r (tree *stmt_p, int *walk_subtrees, void *data) tree guard = (tree)data; tree tcleanup = TARGET_EXPR_CLEANUP (*stmt_p); - tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard); - /* Tell honor_protect_cleanup_actions to handle this as a separate - cleanup. */ - TRY_CATCH_IS_CLEANUP (tcleanup) = 1; - - TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup; + if (tcleanup && !expr_noexcept_p (tcleanup, tf_none)) + { + tcleanup = build2 (TRY_CATCH_EXPR, void_type_node, tcleanup, guard); + /* Tell honor_protect_cleanup_actions to handle this as a separate + cleanup. */ + TRY_CATCH_IS_CLEANUP (tcleanup) = 1; + TARGET_EXPR_CLEANUP (*stmt_p) = tcleanup; + } } return NULL_TREE; diff --git a/gcc/testsuite/g++.dg/eh/cleanup6.C b/gcc/testsuite/g++.dg/eh/cleanup6.C new file mode 100644 index 00000000000..e27563f4569 --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/cleanup6.C @@ -0,0 +1,13 @@ +// Test that we don't wrap the non-throwing A cleanup with a B cleanup. + +// { dg-do compile { target c++11 } } +// { dg-additional-options -fdump-tree-gimple } +// { dg-final { scan-tree-dump-times "B::~B" 1 "gimple" } } + +struct A { A(); ~A(); }; +struct B { B(const A& = A()); ~B(); }; + +int main() +{ + B b; +}
reply other threads:[~2022-01-02 17:56 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220102175609.D7E3E3858427@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).