Skip to content
Snippets Groups Projects
Commit 092e60f5 authored by Jason Merrill's avatar Jason Merrill
Browse files

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.
parent 4620531e
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
// 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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment