diff mbox series

c++: Tweak function cloning names

Message ID fe5799da-3e7a-c46a-2cb2-c1d9bc249b6d@acm.org
State New
Headers show
Series c++: Tweak function cloning names | expand

Commit Message

Nathan Sidwell June 30, 2020, 5:53 p.m. UTC
On the modules branch I need to expose an intermediate step of the 
function cloning, but before that it'd be nice to rationalize the names 
somewhat, now that we also use that API for copying the equality 
operator.  Jason's recent patch caused me some pain by altering the same 
code.  I can only blame myself for not pushing some bits sooner. Anyway, 
this patch makes the newly renamed copy_fndecl_with_name static, and 
adds a wrapper copy_operator_fn, that takes an operator code.  The cdtor 
cloning functions are renamed to explicitly note they expect cdtors.  A 
followup patch will move some of the logic from copy_fndecl_with_name to 
build_cdtor_clones.

     gcc/cp/
             * cp-tree.h (copy_fndecl_with_name): Rename to ...
             (copy_operatorn_fn): ... this.  Change arg type.
             (clone_function_decl): Rename to ...
             (clone_cdtor): ... this.
             * class.c (copy_fndecl_with_name): Make static.
             (copy_operator_fn): New wrapper.
             (build_clones): Rename to ...
             (build_cdtor_clones): ... this.
             (clone_function_decl): Rename to ...
             (clone_cdtor): ... this.  Adjust build_clones calls.
             (clone_constructors_and_destructors): Adjust 
clone_function_decl
             calls.
             * method.c (implicitly_declare_fn): Adjust 
copy_fndecl_with_name
             call.
             (lazily_declare_fn): Adjust clone_function_decl call.
             * pt.c (tsubst_function_decl): Likewise.
             (instantiate_template_1): Likewise.

     libcc1/
             * libcp1plugin.cc (plugin_build_decl): Adjust 
clone_function_decl
             call.
diff mbox series

Patch

diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 94a95854e25..b0cc027e0de 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -4696,7 +4696,7 @@  check_methods (tree t)
     }
 }
 
-tree
+static tree
 copy_fndecl_with_name (tree fn, tree name)
 {
   /* Copy the function.  */
@@ -4804,6 +4804,14 @@  copy_fndecl_with_name (tree fn, tree name)
   return clone;
 }
 
+/* FN is an operator function, create a variant for CODE.  */
+
+tree
+copy_operator_fn (tree fn, tree_code code)
+{
+  return copy_fndecl_with_name (fn, ovl_op_identifier (code));
+}
+
 /* FN is a constructor or destructor.  Clone the declaration to create
    a specialized in-charge or not-in-charge version, as indicated by
    NAME.  */
@@ -4847,8 +4855,8 @@  build_clone (tree fn, tree name)
 /* Build the clones of FN, return the number of clones built.  These
    will be inserted onto DECL_CHAIN of FN.  */
 
-unsigned
-build_clones (tree fn)
+static unsigned
+build_cdtor_clones (tree fn)
 {
   unsigned count = 0;
 
@@ -4891,14 +4899,14 @@  build_clones (tree fn)
    CLASSTYPE_MEMBER_VEC.  */
 
 void
-clone_function_decl (tree fn, bool update_methods)
+clone_cdtor (tree fn, bool update_methods)
 {
   /* Avoid inappropriate cloning.  */
   if (DECL_CHAIN (fn)
       && DECL_CLONED_FUNCTION_P (DECL_CHAIN (fn)))
     return;
 
-  unsigned count = build_clones (fn);
+  unsigned count = build_cdtor_clones (fn);
 
   /* Note that this is an abstract function that is never emitted.  */
   DECL_ABSTRACT_P (fn) = true;
@@ -4998,10 +5006,10 @@  clone_constructors_and_destructors (tree t)
   /* While constructors can be via a using declaration, at this point
      we no longer need to know that.  */
   for (ovl_iterator iter (CLASSTYPE_CONSTRUCTORS (t)); iter; ++iter)
-    clone_function_decl (*iter, /*update_methods=*/true);
+    clone_cdtor (*iter, /*update_methods=*/true);
 
   if (tree dtor = CLASSTYPE_DESTRUCTOR (t))
-    clone_function_decl (dtor, /*update_methods=*/true);
+    clone_cdtor (dtor, /*update_methods=*/true);
 }
 
 /* Deduce noexcept for a destructor DTOR.  */
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 78e8ca4150a..9b31eaf4a07 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -6450,8 +6450,8 @@  extern void check_abi_tags			(tree);
 extern tree missing_abi_tags			(tree);
 extern void fixup_type_variants			(tree);
 extern void fixup_attribute_variants		(tree);
-extern tree copy_fndecl_with_name		(tree, tree);
-extern void clone_function_decl			(tree, bool);
+extern void clone_cdtor				(tree, bool);
+extern tree copy_operator_fn			(tree, tree_code code);
 extern void adjust_clone_args			(tree);
 extern void deduce_noexcept_on_destructor       (tree);
 extern bool uniquely_derived_from_p             (tree, tree);
diff --git a/gcc/cp/method.c b/gcc/cp/method.c
index 2a98907bfa1..8fd7052d205 100644
--- a/gcc/cp/method.c
+++ b/gcc/cp/method.c
@@ -2688,7 +2688,7 @@  implicitly_declare_fn (special_function_kind kind, tree type,
      comparison operator function. --end note]  */
   if (kind == sfk_comparison)
     {
-      fn = copy_fndecl_with_name (pattern_fn, ovl_op_identifier (EQ_EXPR));
+      fn = copy_operator_fn (pattern_fn, EQ_EXPR);
       DECL_ARTIFICIAL (fn) = 1;
       TREE_TYPE (fn) = change_return_type (boolean_type_node, TREE_TYPE (fn));
       return fn;
@@ -3152,7 +3152,7 @@  lazily_declare_fn (special_function_kind sfk, tree type)
   maybe_add_class_template_decl_list (type, fn, /*friend_p=*/0);
   if (DECL_MAYBE_IN_CHARGE_CDTOR_P (fn))
     /* Create appropriate clones.  */
-    clone_function_decl (fn, /*update_methods=*/true);
+    clone_cdtor (fn, /*update_methods=*/true);
 
   return fn;
 }
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 618bf68b2d6..b6423f7432b 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -13923,7 +13923,7 @@  tsubst_function_decl (tree t, tree args, tsubst_flags_t complain,
 	 If it isn't, that'll be handled by
 	 clone_constructors_and_destructors.  */
       if (PRIMARY_TEMPLATE_P (gen_tmpl))
-	clone_function_decl (r, /*update_methods=*/false);
+	clone_cdtor (r, /*update_methods=*/false);
     }
   else if ((complain & tf_error) != 0
 	   && IDENTIFIER_ANY_OP_P (DECL_NAME (r))
@@ -20769,7 +20769,7 @@  instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain)
      instantiating the template clones.  */
   if (tree chain = DECL_CHAIN (gen_tmpl))
     if (DECL_P (chain) && DECL_CLONED_FUNCTION_P (chain))
-      clone_function_decl (fndecl, /*update_methods=*/false);
+      clone_cdtor (fndecl, /*update_methods=*/false);
 
   if (!access_ok)
     {
diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index 00449f43b52..01aecf00735 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -1552,7 +1552,7 @@  plugin_build_decl (cc1_plugin::connection *self,
 	 reversal.  */
       tree save = DECL_CHAIN (decl);
       DECL_CHAIN (decl) = NULL_TREE;
-      clone_function_decl (decl, /*update_methods=*/true);
+      clone_cdtor (decl, /*update_methods=*/true);
       gcc_assert (TYPE_FIELDS (current_class_type) == decl);
       TYPE_FIELDS (current_class_type)
 	= nreverse (TYPE_FIELDS (current_class_type));