]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree: add to clobber_kind
authorJason Merrill <jason@redhat.com>
Mon, 11 Dec 2023 16:35:31 +0000 (11:35 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 12 Dec 2023 17:47:21 +0000 (12:47 -0500)
In discussion of PR71093 it came up that more clobber_kind options would be
useful within the C++ front-end.

gcc/ChangeLog:

* tree-core.h (enum clobber_kind): Rename CLOBBER_EOL to
CLOBBER_STORAGE_END.  Add CLOBBER_STORAGE_BEGIN,
CLOBBER_OBJECT_BEGIN, CLOBBER_OBJECT_END.
* gimple-lower-bitint.cc
* gimple-ssa-warn-access.cc
* gimplify.cc
* tree-inline.cc
* tree-ssa-ccp.cc: Adjust for rename.
* tree-pretty-print.cc: And handle new values.

gcc/cp/ChangeLog:

* call.cc (build_trivial_dtor_call): Use CLOBBER_OBJECT_END.
* decl.cc (build_clobber_this): Take clobber_kind argument.
(start_preparsed_function): Pass CLOBBER_OBJECT_BEGIN.
(begin_destructor_body): Pass CLOBBER_OBJECT_END.

gcc/testsuite/ChangeLog:

* gcc.dg/pr87052.c: Adjust expected CLOBBER output.

Co-authored-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/call.cc
gcc/cp/decl.cc
gcc/gimple-lower-bitint.cc
gcc/gimple-ssa-warn-access.cc
gcc/gimplify.cc
gcc/testsuite/gcc.dg/pr87052.c
gcc/tree-core.h
gcc/tree-inline.cc
gcc/tree-pretty-print.cc
gcc/tree-ssa-ccp.cc

index 4f0abf8e93fa997d639549dee15f5a652d809ec5..aaee34f35b04798522febbf85161b3e2b9107867 100644 (file)
@@ -9716,7 +9716,7 @@ build_trivial_dtor_call (tree instance, bool no_ptr_deref)
     }
 
   /* A trivial destructor should still clobber the object.  */
-  tree clobber = build_clobber (TREE_TYPE (instance));
+  tree clobber = build_clobber (TREE_TYPE (instance), CLOBBER_OBJECT_END);
   return build2 (MODIFY_EXPR, void_type_node,
                 instance, clobber);
 }
index b1ada1d521521fa0d3b595332d4c18ae0b548ea0..4d17ead123ac84bbfef5160d137bc74a025cc5bf 100644 (file)
@@ -17401,7 +17401,7 @@ implicit_default_ctor_p (tree fn)
    storage is dead when we enter the constructor or leave the destructor.  */
 
 static tree
-build_clobber_this ()
+build_clobber_this (clobber_kind kind)
 {
   /* Clobbering an empty base is pointless, and harmful if its one byte
      TYPE_SIZE overlays real data.  */
@@ -17417,7 +17417,7 @@ build_clobber_this ()
   if (!vbases)
     ctype = CLASSTYPE_AS_BASE (ctype);
 
-  tree clobber = build_clobber (ctype);
+  tree clobber = build_clobber (ctype, kind);
 
   tree thisref = current_class_ref;
   if (ctype != current_class_type)
@@ -17836,7 +17836,7 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
         because part of the initialization might happen before we enter the
         constructor, via AGGR_INIT_ZERO_FIRST (c++/68006).  */
       && !implicit_default_ctor_p (decl1))
-    finish_expr_stmt (build_clobber_this ());
+    finish_expr_stmt (build_clobber_this (CLOBBER_OBJECT_BEGIN));
 
   if (!processing_template_decl
       && DECL_CONSTRUCTOR_P (decl1)
@@ -18074,7 +18074,8 @@ begin_destructor_body (void)
            finish_decl_cleanup (NULL_TREE, stmt);
          }
        else
-         finish_decl_cleanup (NULL_TREE, build_clobber_this ());
+         finish_decl_cleanup (NULL_TREE,
+                              build_clobber_this (CLOBBER_OBJECT_END));
       }
 
       /* And insert cleanups for our bases and members so that they
index c55c32fb40d644dce091ff3608af9a1b8d6be416..65a7bbe3fa9aef99d494b618ad851175610cabc2 100644 (file)
@@ -806,7 +806,8 @@ bitint_large_huge::handle_operand (tree op, tree idx)
          && m_after_stmt
          && bitmap_bit_p (m_single_use_names, SSA_NAME_VERSION (op)))
        {
-         tree clobber = build_clobber (TREE_TYPE (m_vars[p]), CLOBBER_EOL);
+         tree clobber = build_clobber (TREE_TYPE (m_vars[p]),
+                                       CLOBBER_STORAGE_END);
          g = gimple_build_assign (m_vars[p], clobber);
          gimple_stmt_iterator gsi = gsi_for_stmt (m_after_stmt);
          gsi_insert_after (&gsi, g, GSI_SAME_STMT);
@@ -2063,7 +2064,7 @@ bitint_large_huge::handle_operand_addr (tree op, gimple *stmt,
       tree ret = build_fold_addr_expr (var);
       if (!stmt_ends_bb_p (gsi_stmt (m_gsi)))
        {
-         tree clobber = build_clobber (atype, CLOBBER_EOL);
+         tree clobber = build_clobber (atype, CLOBBER_STORAGE_END);
          g = gimple_build_assign (var, clobber);
          gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
        }
@@ -2100,7 +2101,8 @@ bitint_large_huge::handle_operand_addr (tree op, gimple *stmt,
              ret = build_fold_addr_expr (var);
              if (!stmt_ends_bb_p (gsi_stmt (m_gsi)))
                {
-                 tree clobber = build_clobber (m_limb_type, CLOBBER_EOL);
+                 tree clobber = build_clobber (m_limb_type,
+                                               CLOBBER_STORAGE_END);
                  g = gimple_build_assign (var, clobber);
                  gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
                }
@@ -3707,7 +3709,7 @@ bitint_large_huge::finish_arith_overflow (tree var, tree obj, tree type,
     }
   if (var)
     {
-      tree clobber = build_clobber (TREE_TYPE (var), CLOBBER_EOL);
+      tree clobber = build_clobber (TREE_TYPE (var), CLOBBER_STORAGE_END);
       g = gimple_build_assign (var, clobber);
       gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
     }
index 1646bd1be14c140c33c7ed53f09f5f1bb29dc9f4..f04c2530869311886b0c4502fc0db13a37284641 100644 (file)
@@ -4364,7 +4364,7 @@ void
 pass_waccess::check_stmt (gimple *stmt)
 {
   if (m_check_dangling_p
-      && gimple_clobber_p (stmt, CLOBBER_EOL))
+      && gimple_clobber_p (stmt, CLOBBER_STORAGE_END))
     {
       /* Ignore clobber statements in blocks with exceptional edges.  */
       basic_block bb = gimple_bb (stmt);
index 342e43a7f2558e62da5623374da3db005280461c..afeaea873c08828d7b587963b853038aa169e270 100644 (file)
@@ -1518,7 +1518,7 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
                      tmp = build_call_expr_loc (EXPR_LOCATION (*e), tmp, 2, v,
                                                 build_zero_cst (ptr_type_node));
                      tsi_link_after (&e, tmp, TSI_SAME_STMT);
-                     tmp = build_clobber (TREE_TYPE (v), CLOBBER_EOL);
+                     tmp = build_clobber (TREE_TYPE (v), CLOBBER_STORAGE_END);
                      tmp = fold_build2_loc (loc, MODIFY_EXPR, TREE_TYPE (v), v,
                                             fold_convert (TREE_TYPE (v), tmp));
                      ++e;
@@ -1651,7 +1651,7 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
                                         build_zero_cst (ptr_type_node));
              gimplify_and_add (tmp, &cleanup);
              gimple *clobber_stmt;
-             tmp = build_clobber (TREE_TYPE (v), CLOBBER_EOL);
+             tmp = build_clobber (TREE_TYPE (v), CLOBBER_STORAGE_END);
              clobber_stmt = gimple_build_assign (v, tmp);
              gimple_set_location (clobber_stmt, end_locus);
              gimplify_seq_add_stmt (&cleanup, clobber_stmt);
@@ -1665,7 +1665,7 @@ gimplify_bind_expr (tree *expr_p, gimple_seq *pre_p)
              && !is_gimple_reg (t)
              && flag_stack_reuse != SR_NONE)
            {
-             tree clobber = build_clobber (TREE_TYPE (t), CLOBBER_EOL);
+             tree clobber = build_clobber (TREE_TYPE (t), CLOBBER_STORAGE_END);
              gimple *clobber_stmt;
              clobber_stmt = gimple_build_assign (t, clobber);
              gimple_set_location (clobber_stmt, end_locus);
@@ -7417,7 +7417,8 @@ gimplify_target_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
        {
          if (flag_stack_reuse == SR_ALL)
            {
-             tree clobber = build_clobber (TREE_TYPE (temp), CLOBBER_EOL);
+             tree clobber = build_clobber (TREE_TYPE (temp),
+                                           CLOBBER_STORAGE_END);
              clobber = build2 (MODIFY_EXPR, TREE_TYPE (temp), temp, clobber);
              gimple_push_cleanup (temp, clobber, false, pre_p, true);
            }
index 796fe6440c174a9816678e6ca4181c48f0ea6032..90f3c3b14a805e14235d899acc9c788fe1322361 100644 (file)
@@ -36,6 +36,6 @@ void test (void)
    { dg-final { scan-tree-dump-times "b = \"a\\\\x00bc\";"  1 "gimple" } }
    { dg-final { scan-tree-dump-times "c = \"\";"  1 "gimple" } }
    { dg-final { scan-tree-dump-times "d = "  1 "gimple" } }
-   { dg-final { scan-tree-dump-times "d = {CLOBBER\\(eol\\)}"  1 "gimple" } }
+   { dg-final { scan-tree-dump-times "d = {CLOBBER\\(eos\\)}"  1 "gimple" } }
    { dg-final { scan-tree-dump-times "e = "  1 "gimple" } }
-   { dg-final { scan-tree-dump-times "e = {CLOBBER\\(eol\\)}"  1 "gimple" } }  */
+   { dg-final { scan-tree-dump-times "e = {CLOBBER\\(eos\\)}"  1 "gimple" } }  */
index 04c04cf2f37530ca7bbee11c6584519d363a4e5f..58aa598f3bba6e4f497017ec3e7b3b17089262d0 100644 (file)
@@ -986,12 +986,19 @@ enum annot_expr_kind {
   annot_expr_kind_last
 };
 
-/* The kind of a TREE_CLOBBER_P CONSTRUCTOR node.  */
+/* The kind of a TREE_CLOBBER_P CONSTRUCTOR node.  Other than _UNDEF, these are
+   in roughly sequential order.  */
 enum clobber_kind {
   /* Unspecified, this clobber acts as a store of an undefined value.  */
   CLOBBER_UNDEF,
-  /* This clobber ends the lifetime of the storage.  */
-  CLOBBER_EOL,
+  /* Beginning of storage duration, e.g. malloc.  */
+  CLOBBER_STORAGE_BEGIN,
+  /* Beginning of object lifetime, e.g. C++ constructor.  */
+  CLOBBER_OBJECT_BEGIN,
+  /* End of object lifetime, e.g. C++ destructor.  */
+  CLOBBER_OBJECT_END,
+  /* End of storage duration, e.g. free.  */
+  CLOBBER_STORAGE_END,
   CLOBBER_LAST
 };
 
index a4fc839a22d5c7b98fd0a7e6923e270de1e5a893..137b83b7c83affe7b8b4405078be3964f52a5f78 100644 (file)
@@ -5136,7 +5136,8 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id,
              && !is_gimple_reg (*varp)
              && !(id->debug_map && id->debug_map->get (p)))
            {
-             tree clobber = build_clobber (TREE_TYPE (*varp), CLOBBER_EOL);
+             tree clobber = build_clobber (TREE_TYPE (*varp),
+                                           CLOBBER_STORAGE_END);
              gimple *clobber_stmt;
              clobber_stmt = gimple_build_assign (*varp, clobber);
              gimple_set_location (clobber_stmt, gimple_location (stmt));
@@ -5208,7 +5209,8 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id,
          && !is_gimple_reg (id->retvar)
          && !stmt_ends_bb_p (stmt))
        {
-         tree clobber = build_clobber (TREE_TYPE (id->retvar), CLOBBER_EOL);
+         tree clobber = build_clobber (TREE_TYPE (id->retvar),
+                                       CLOBBER_STORAGE_END);
          gimple *clobber_stmt;
          clobber_stmt = gimple_build_assign (id->retvar, clobber);
          gimple_set_location (clobber_stmt, gimple_location (old_stmt));
index 0dabb6d1580d632c4abd4e8f69c2d67cad3f50a8..cab99f9dfb6db3856dd9cf524ec785fda55d25e9 100644 (file)
@@ -2624,8 +2624,23 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags,
        if (TREE_CLOBBER_P (node))
          {
            pp_string (pp, "CLOBBER");
-           if (CLOBBER_KIND (node) == CLOBBER_EOL)
-             pp_string (pp, "(eol)");
+           switch (CLOBBER_KIND (node))
+             {
+             case CLOBBER_STORAGE_BEGIN:
+               pp_string (pp, "(bos)");
+               break;
+             case CLOBBER_STORAGE_END:
+               pp_string (pp, "(eos)");
+               break;
+             case CLOBBER_OBJECT_BEGIN:
+               pp_string (pp, "(bob)");
+               break;
+             case CLOBBER_OBJECT_END:
+               pp_string (pp, "(eob)");
+               break;
+             default:
+               break;
+             }
          }
        else if (TREE_CODE (TREE_TYPE (node)) == RECORD_TYPE
                 || TREE_CODE (TREE_TYPE (node)) == UNION_TYPE)
index ddcbaaaa417de6ca9b2d5279da990c3b600b07a4..fab2a9b248a6edc14b4a79cd0d93bcf8e4456a96 100644 (file)
@@ -2525,7 +2525,7 @@ insert_clobber_before_stack_restore (tree saved_val, tree var,
   FOR_EACH_IMM_USE_STMT (stmt, iter, saved_val)
     if (gimple_call_builtin_p (stmt, BUILT_IN_STACK_RESTORE))
       {
-       clobber = build_clobber (TREE_TYPE (var), CLOBBER_EOL);
+       clobber = build_clobber (TREE_TYPE (var), CLOBBER_STORAGE_END);
        clobber_stmt = gimple_build_assign (var, clobber);
 
        i = gsi_for_stmt (stmt);