From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id F38AC3839808; Tue, 6 Jul 2021 20:43:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F38AC3839808 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/c++-contracts] c++: adjust violation call handling X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/devel/c++-contracts X-Git-Oldrev: 6e2be2d05164c927b04a384844d181d2114219ad X-Git-Newrev: 58aa1b5f573f5509ce420cfa89bf58ff668cfa49 Message-Id: <20210706204350.F38AC3839808@sourceware.org> Date: Tue, 6 Jul 2021 20:43:50 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jul 2021 20:43:51 -0000 https://gcc.gnu.org/g:58aa1b5f573f5509ce420cfa89bf58ff668cfa49 commit 58aa1b5f573f5509ce420cfa89bf58ff668cfa49 Author: Jason Merrill Date: Thu Jul 1 11:09:09 2021 -0400 c++: adjust violation call handling We shouldn't need to touch TREE_NOTHROW in cp_genericize_r; the call should go through set_flags_from_callee and then we'll see that the current function might throw. For this to work I needed to move the TREE_NOTHROW setting in finish_function to after cp_genericize. gcc/cp/ChangeLog: * contracts.cc (build_contract_handler_fn): Rename to... (build_contract_handler_call): ...this. Use build_call_n. (build_contract_check): Use void_node. * cp-gimplify.c (cp_genericize_r): Don't mess with TREE_NOTHROW or current_function_returns_abnormally. * decl.c (finish_function): Set TREE_NOTHROW after genericize. Diff: --- gcc/cp/contracts.cc | 20 ++++++++++---------- gcc/cp/cp-gimplify.c | 5 ----- gcc/cp/decl.c | 14 +++++++------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/gcc/cp/contracts.cc b/gcc/cp/contracts.cc index c343fcf3f3b..067248fc7df 100644 --- a/gcc/cp/contracts.cc +++ b/gcc/cp/contracts.cc @@ -1573,8 +1573,8 @@ get_contract_role_name (tree contract) } static void -build_contract_handler_fn (tree contract, - contract_continuation cmode) +build_contract_handler_call (tree contract, + contract_continuation cmode) { const char *level = get_contract_level_name (contract); const char *role = get_contract_role_name (contract); @@ -1604,10 +1604,10 @@ build_contract_handler_fn (tree contract, violation_fn = on_contract_violation_fn; else violation_fn = on_contract_violation_never_fn; - tree call = build_call_expr (violation_fn, 8, continue_mode, line_number, - file_name, function_name, comment, - level_str, role_str, - continuation); + tree call = build_call_n (violation_fn, 8, continue_mode, line_number, + file_name, function_name, comment, + level_str, role_str, + continuation); finish_expr_stmt (call); } @@ -1645,7 +1645,7 @@ build_contract_check (tree contract) /* Ignored contracts are never checked or assumed. */ if (semantic == CCS_IGNORE) - return build1 (NOP_EXPR, void_type_node, integer_zero_node); + return void_node; remap_dummy_this (current_function_decl, &CONTRACT_CONDITION (contract)); tree condition = CONTRACT_CONDITION (contract); @@ -1656,7 +1656,7 @@ build_contract_check (tree contract) of turning it into a compile time assumption fails and emits run time code. We don't want that, so just turn these into NOP. */ if (semantic == CCS_ASSUME && !cp_tree_defined_p (condition)) - return build1 (NOP_EXPR, void_type_node, integer_zero_node); + return void_node; tree if_stmt = begin_if_stmt (); tree cond = build_x_unary_op (EXPR_LOCATION (contract), @@ -1668,7 +1668,7 @@ build_contract_check (tree contract) if (semantic == CCS_ASSUME) { tree unreachable_fn = builtin_decl_implicit (BUILT_IN_UNREACHABLE); - tree call = build_call_expr (unreachable_fn, 0); + tree call = build_call_n (unreachable_fn, 0); finish_expr_stmt (call); } else @@ -1682,7 +1682,7 @@ build_contract_check (tree contract) default: gcc_unreachable (); } - build_contract_handler_fn (contract, cmode); + build_contract_handler_call (contract, cmode); } finish_then_clause (if_stmt); diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 59bb34d723a..1828c9d6ac4 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1200,11 +1200,6 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data) { if (tree check = build_contract_check (stmt)) { - /* Mark the current function as possibly throwing exceptions - (through invocation of the contract violation handler). */ - current_function_returns_abnormally = 1; - TREE_NOTHROW (current_function_decl) = 0; - *stmt_p = check; return cp_genericize_r (stmt_p, walk_subtrees, data); } diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index e4ef6b37ac0..56988acb012 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -17628,13 +17628,6 @@ finish_function (bool inline_p) finish_fname_decls (); - /* If this function can't throw any exceptions, remember that. */ - if (!processing_template_decl - && !cp_function_chain->can_throw - && !flag_non_call_exceptions - && !decl_replaceable_p (fndecl)) - TREE_NOTHROW (fndecl) = 1; - /* This must come after expand_function_end because cleanups might have declarations (from inline functions) that need to go into this function's blocks. */ @@ -17859,6 +17852,13 @@ finish_function (bool inline_p) && !DECL_OMP_DECLARE_REDUCTION_P (fndecl)) cp_genericize (fndecl); + /* If this function can't throw any exceptions, remember that. */ + if (!processing_template_decl + && !cp_function_chain->can_throw + && !flag_non_call_exceptions + && !decl_replaceable_p (fndecl)) + TREE_NOTHROW (fndecl) = 1; + /* Emit the resumer and destroyer functions now, providing that we have not encountered some fatal error. */ if (coro_emit_helpers)