aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/except.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/except.cc')
-rw-r--r--gcc/cp/except.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/cp/except.cc b/gcc/cp/except.cc
index a9d8e2f..a7f35e4 100644
--- a/gcc/cp/except.cc
+++ b/gcc/cp/except.cc
@@ -367,6 +367,8 @@ initialize_handler_parm (tree decl, tree exp)
MUST_NOT_THROW_EXPR. */
init = fold_build_cleanup_point_expr (TREE_TYPE (init), init);
init = build_must_not_throw_expr (init, NULL_TREE);
+ if (init && TREE_CODE (init) == MUST_NOT_THROW_EXPR)
+ MUST_NOT_THROW_CATCH_P (init) = 1;
}
decl = pushdecl (decl);
@@ -523,6 +525,7 @@ begin_eh_spec_block (void)
r = build_stmt (spec_location, MUST_NOT_THROW_EXPR,
NULL_TREE, NULL_TREE);
TREE_SIDE_EFFECTS (r) = 1;
+ MUST_NOT_THROW_NOEXCEPT_P (r) = 1;
}
else
r = build_stmt (spec_location, EH_SPEC_BLOCK, NULL_TREE, NULL_TREE);
@@ -614,6 +617,7 @@ wrap_cleanups_r (tree *tp, int *walk_subtrees, void * /*data*/)
{
cleanup = build2 (MUST_NOT_THROW_EXPR, void_type_node, cleanup,
NULL_TREE);
+ MUST_NOT_THROW_THROW_P (cleanup) = 1;
TARGET_EXPR_CLEANUP (exp) = cleanup;
}
@@ -712,6 +716,11 @@ build_throw (location_t loc, tree exp, tsubst_flags_t complain)
allocate_expr = do_allocate_exception (temp_type);
if (allocate_expr == error_mark_node)
return error_mark_node;
+ /* Copy ptr inside of the CLEANUP_POINT_EXPR
+ added below to a TARGET_EXPR slot added outside of it,
+ otherwise during constant evaluation of throw expression
+ we'd diagnose accessing ptr outside of its lifetime. */
+ tree ptr_copy = get_internal_target_expr (null_pointer_node);
allocate_expr = get_internal_target_expr (allocate_expr);
ptr = TARGET_EXPR_SLOT (allocate_expr);
TARGET_EXPR_CLEANUP (allocate_expr) = do_free_exception (ptr);
@@ -763,10 +772,17 @@ build_throw (location_t loc, tree exp, tsubst_flags_t complain)
/* Prepend the allocation. */
exp = build2 (COMPOUND_EXPR, TREE_TYPE (exp), allocate_expr, exp);
+ exp = build2 (COMPOUND_EXPR, void_type_node, exp,
+ build2 (MODIFY_EXPR, void_type_node,
+ TARGET_EXPR_SLOT (ptr_copy), ptr));
+ ptr = TARGET_EXPR_SLOT (ptr_copy);
+
/* Force all the cleanups to be evaluated here so that we don't have
to do them during unwinding. */
exp = build1 (CLEANUP_POINT_EXPR, void_type_node, exp);
+ exp = build2 (COMPOUND_EXPR, TREE_TYPE (exp), ptr_copy, exp);
+
throw_type = build_eh_type_type (prepare_eh_type (TREE_TYPE (object)));
cleanup = NULL_TREE;