cp-tree.h (maybe_version_functions): Declare.
authorNathan Sidwell <nathan@acm.org>
Wed, 23 Aug 2017 19:37:53 +0000 (19:37 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 23 Aug 2017 19:37:53 +0000 (19:37 +0000)
* cp-tree.h (maybe_version_functions): Declare.
* decl.c (decls_match): Break function versioning check to
separate function.  Call it.
(maybe_version_functions): Broken out of decls_match.
* class.c (add_method): Use maybe_version_functions.

From-SVN: r251316

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/cp-tree.h
gcc/cp/decl.c

index 7b82a61b13cf93047b1b86a0fcfde4d4947887ab..3bc7de0e7ebd012fc8ed53e0bc23ce58d94ac306 100644 (file)
@@ -1,5 +1,11 @@
 2017-08-23  Nathan Sidwell  <nathan@acm.org>
 
+       * cp-tree.h (maybe_version_functions): Declare.
+       * decl.c (decls_match): Break function versioning check to
+       separate function.  Call it.
+       (maybe_version_functions): Broken out of decls_match.
+       * class.c (add_method): Use maybe_version_functions.
+
        * cp-tree.h (print_search_statistics,
        reinit_search_statistics): Don't declare.
        * search.c (n_fields_searched, n_calls_lookup_field,
index 94738bd8f78aa578d857c062c70b917a3ed99b32..78a9b5f393f337c96270718191d32375c60f9822 100644 (file)
@@ -1154,33 +1154,11 @@ add_method (tree type, tree method, bool via_using)
                              TREE_TYPE (method_type)))
           && equivalently_constrained (fn, method))
        {
-         /* For function versions, their parms and types match
-            but they are not duplicates.  Record function versions
-            as and when they are found.  extern "C" functions are
-            not treated as versions.  */
+         /* If these are versions of the same function, process and
+            move on.  */
          if (TREE_CODE (fn) == FUNCTION_DECL
-             && TREE_CODE (method) == FUNCTION_DECL
-             && !DECL_EXTERN_C_P (fn)
-             && !DECL_EXTERN_C_P (method)
-             && targetm.target_option.function_versions (fn, method))
-           {
-             /* Mark functions as versions if necessary.  Modify the mangled
-                decl name if necessary.  */
-             if (!DECL_FUNCTION_VERSIONED (fn))
-               {
-                 DECL_FUNCTION_VERSIONED (fn) = 1;
-                 if (DECL_ASSEMBLER_NAME_SET_P (fn))
-                   mangle_decl (fn);
-               }
-             if (!DECL_FUNCTION_VERSIONED (method))
-               {
-                 DECL_FUNCTION_VERSIONED (method) = 1;
-                 if (DECL_ASSEMBLER_NAME_SET_P (method))
-                   mangle_decl (method);
-               }
-             cgraph_node::record_function_versions (fn, method);
-             continue;
-           }
+             && maybe_version_functions (method, fn))
+           continue;
 
          if (DECL_INHERITED_CTOR (method))
            {
index fb9dadef34b6c90781bccc25d0cb54dc964bafd1..d80cd2985358d7b8c9919da922eec469108aabba 100644 (file)
@@ -6071,6 +6071,7 @@ extern void push_switch                           (tree);
 extern void pop_switch                         (void);
 extern tree make_lambda_name                   (void);
 extern int decls_match                         (tree, tree);
+extern bool maybe_version_functions            (tree, tree);
 extern tree duplicate_decls                    (tree, tree, bool);
 extern tree declare_local_label                        (tree);
 extern tree define_label                       (location_t, tree);
index 5307e11cb94608513feb18b8598fe0652403bae2..a9d72c0f30d168f147c177a235d3a2f1f508e032 100644 (file)
@@ -1088,28 +1088,8 @@ decls_match (tree newdecl, tree olddecl)
       if (types_match
          && !DECL_EXTERN_C_P (newdecl)
          && !DECL_EXTERN_C_P (olddecl)
-         && targetm.target_option.function_versions (newdecl, olddecl))
-       {
-         /* Mark functions as versions if necessary.  Modify the mangled decl
-            name if necessary.  */
-         if (DECL_FUNCTION_VERSIONED (newdecl)
-             && DECL_FUNCTION_VERSIONED (olddecl))
-           return 0;
-         if (!DECL_FUNCTION_VERSIONED (newdecl))
-           {
-             DECL_FUNCTION_VERSIONED (newdecl) = 1;
-             if (DECL_ASSEMBLER_NAME_SET_P (newdecl))
-               mangle_decl (newdecl);
-           }
-         if (!DECL_FUNCTION_VERSIONED (olddecl))
-           {
-             DECL_FUNCTION_VERSIONED (olddecl) = 1;
-             if (DECL_ASSEMBLER_NAME_SET_P (olddecl))
-              mangle_decl (olddecl);
-           }
-         cgraph_node::record_function_versions (olddecl, newdecl);
-         return 0;
-       }
+         && maybe_version_functions (newdecl, olddecl))
+       return 0;
     }
   else if (TREE_CODE (newdecl) == TEMPLATE_DECL)
     {
@@ -1165,6 +1145,40 @@ decls_match (tree newdecl, tree olddecl)
   return types_match;
 }
 
+/* NEWDECL and OLDDECL have identical signatures.  If they are
+   different versions adjust them and return true.  */
+
+bool
+maybe_version_functions (tree newdecl, tree olddecl)
+{
+  if (!targetm.target_option.function_versions (newdecl, olddecl))
+    return false;
+
+  bool record = false;
+
+  if (!DECL_FUNCTION_VERSIONED (olddecl))
+    {
+      record = true;
+      DECL_FUNCTION_VERSIONED (olddecl) = 1;
+      if (DECL_ASSEMBLER_NAME_SET_P (olddecl))
+       mangle_decl (olddecl);
+    }
+
+  if (!DECL_FUNCTION_VERSIONED (newdecl))
+    {
+      record = true;
+      DECL_FUNCTION_VERSIONED (newdecl) = 1;
+      if (DECL_ASSEMBLER_NAME_SET_P (newdecl))
+       mangle_decl (newdecl);
+    }
+
+  /* Only record if at least one was not already versions.  */
+  if (record)
+    cgraph_node::record_function_versions (olddecl, newdecl);
+
+  return true;
+}
+
 /* If NEWDECL is `static' and an `extern' was seen previously,
    warn about it.  OLDDECL is the previous declaration.