public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-contracts] c++: adjust violation call handling
@ 2021-07-06 20:43 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-07-06 20:43 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:58aa1b5f573f5509ce420cfa89bf58ff668cfa49

commit 58aa1b5f573f5509ce420cfa89bf58ff668cfa49
Author: Jason Merrill <jason@redhat.com>
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)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-06 20:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-06 20:43 [gcc/devel/c++-contracts] c++: adjust violation call handling Jason Merrill

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).