aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-12-30 00:10:57 -0500
committerJason Merrill <jason@redhat.com>2022-01-02 12:56:02 -0500
commit092e60f57adeccf98e876af6b7b5734337904812 (patch)
treed1fccee44b5ddfa5581b21987d1cba47133d2463 /gcc/cp
parent4620531ea988d6d2ede7c8f168074586ba64f482 (diff)
downloadgcc-092e60f57adeccf98e876af6b7b5734337904812.zip
gcc-092e60f57adeccf98e876af6b7b5734337904812.tar.gz
gcc-092e60f57adeccf98e876af6b7b5734337904812.tar.bz2
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.
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/decl.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 982fca8..51c6995 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;