]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Whitelity type attributes for function signature change
authorJan Hubicka <jh@suse.cz>
Sat, 13 Nov 2021 14:46:57 +0000 (15:46 +0100)
committerJan Hubicka <jh@suse.cz>
Sat, 13 Nov 2021 14:46:57 +0000 (15:46 +0100)
gcc/ChangeLog:

* ipa-fnsummary.c (compute_fn_summary): Use type_attribut_allowed_p
* ipa-param-manipulation.c
(ipa_param_adjustments::type_attribute_allowed_p):
New member function.
(drop_type_attribute_if_params_changed_p): New function.
(build_adjusted_function_type): Use it.
* ipa-param-manipulation.h: Add type_attribute_allowed_p.

gcc/ipa-fnsummary.c
gcc/ipa-param-manipulation.c
gcc/ipa-param-manipulation.h

index 94a80d3ec90d0bc6e0fa8700081b69f13f56e808..7e9201a554a8b8084d9ddd56dd777c7df3935cab 100644 (file)
@@ -3141,8 +3141,8 @@ compute_fn_summary (struct cgraph_node *node, bool early)
          modref summaries.  */
        for (tree list = TYPE_ATTRIBUTES (TREE_TYPE (node->decl));
            list && !no_signature; list = TREE_CHAIN (list))
-        if (!flag_ipa_modref
-            || !is_attribute_p ("fn spec", get_attribute_name (list)))
+       if (!ipa_param_adjustments::type_attribute_allowed_p
+                       (get_attribute_name (list)))
           {
             if (dump_file)
                {
index 991db0d9b1bf176f64b73f1cfd4a84249c1ad3fa..0a5ed858a28bf248d71933b6cdabfe92ae069298 100644 (file)
@@ -279,6 +279,32 @@ fill_vector_of_new_param_types (vec<tree> *new_types, vec<tree> *otypes,
     }
 }
 
+/* Return false if given attribute should prevent type adjustments.  */
+
+bool
+ipa_param_adjustments::type_attribute_allowed_p (tree name)
+{
+  if ((is_attribute_p ("fn spec", name) && flag_ipa_modref)
+      || is_attribute_p ("access", name)
+      || is_attribute_p ("returns_nonnull", name)
+      || is_attribute_p ("assume_aligned", name)
+      || is_attribute_p ("nocf_check", name)
+      || is_attribute_p ("warn_unused_result", name))
+    return true;
+  return false;
+}
+
+/* Return true if attribute should be dropped if parameter changed.  */
+
+static bool
+drop_type_attribute_if_params_changed_p (tree name)
+{
+  if (is_attribute_p ("fn spec", name)
+      || is_attribute_p ("access", name))
+    return true;
+  return false;
+}
+
 /* Build and return a function type just like ORIG_TYPE but with parameter
    types given in NEW_PARAM_TYPES - which can be NULL if, but only if,
    ORIG_TYPE itself has NULL TREE_ARG_TYPEs.  If METHOD2FUNC is true, also make
@@ -337,16 +363,19 @@ build_adjusted_function_type (tree orig_type, vec<tree> *new_param_types,
       if (skip_return)
        TREE_TYPE (new_type) = void_type_node;
     }
-  /* We only support one fn spec attribute on type.  Be sure to remove it.
-     Once we support multiple attributes we will need to be able to unshare
-     the list.  */
   if (args_modified && TYPE_ATTRIBUTES (new_type))
     {
-      gcc_checking_assert
-             (!TREE_CHAIN (TYPE_ATTRIBUTES (new_type))
-              && (is_attribute_p ("fn spec",
-                         get_attribute_name (TYPE_ATTRIBUTES (new_type)))));
+      tree t = TYPE_ATTRIBUTES (new_type);
+      tree *last = &TYPE_ATTRIBUTES (new_type);
       TYPE_ATTRIBUTES (new_type) = NULL;
+      for (;t; t = TREE_CHAIN (t))
+       if (!drop_type_attribute_if_params_changed_p
+               (get_attribute_name (t)))
+         {
+           *last = copy_node (t);
+           TREE_CHAIN (*last) = NULL;
+           last = &TREE_CHAIN (*last);
+         }
     }
 
   return new_type;
index 9440cbfc56ced02161432f973120bed5a2125966..5adf8a223561c76dcde3998f77f7988073c2dc2e 100644 (file)
@@ -254,6 +254,7 @@ public:
   /* If true, make the function not return any value.  */
   bool m_skip_return;
 
+  static bool type_attribute_allowed_p (tree);
 private:
   ipa_param_adjustments () {}