https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118125

--- Comment #12 from Martin Jambor <jamborm at gcc dot gnu.org> ---
The cold attribute is simply and silently dropped on the floor by
decl_attributes (in attribs.cc) in the process of building decls for
builtins because it cannot look it up in the gnu attribute name space
by lookup_scoped_attribute_spec.  This is because attributes cold and
hot are missing from lto_gnu_attributes in lto/lto-lang.cc.

So the correct fix is probably going to look like the following.  I'll
get something ready for submission early next week.

(We should also probably have a self-test that all attributes used by
built-in functions are known to LTO.)

diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index 33f19365ec3..4c062fe8a0e 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -255,6 +255,9 @@ redirect_to_unreachable (struct cgraph_edge *e)
   struct cgraph_node *target
     = cgraph_node::get_create (builtin_decl_unreachable ());

+  gcc_checking_assert (lookup_attribute ("cold",
+                                        DECL_ATTRIBUTES (target->decl)));
+
   if (e->speculative)
     e = cgraph_edge::resolve_speculation (e, target->decl);
   else if (!e->callee)
diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc
index 652d7fc5e30..b8dddf89c49 100644
--- a/gcc/lto/lto-lang.cc
+++ b/gcc/lto/lto-lang.cc
@@ -60,6 +60,7 @@ static tree ignore_attribute (tree *, tree, tree, int, bool
*);
 static tree handle_format_attribute (tree *, tree, tree, int, bool *);
 static tree handle_fnspec_attribute (tree *, tree, tree, int, bool *);
 static tree handle_format_arg_attribute (tree *, tree, tree, int, bool *);
+static tree handle_cold_attribute (tree *, tree, tree, int, bool *);

 /* Helper to define attribute exclusions.  */
 #define ATTR_EXCL(name, function, type, variable)      \
@@ -128,6 +129,8 @@ static const attribute_spec lto_gnu_attributes[] =
                              handle_sentinel_attribute, NULL },
   { "type generic",           0, 0, false, true, true, false,
                              handle_type_generic_attribute, NULL },
+  { "cold",                  0, 0, false,  false, false, false,
+                             handle_cold_attribute, NULL },
   { "fn spec",               1, 1, false, true, true, false,
                              handle_fnspec_attribute, NULL },
   { "transaction_pure",              0, 0, false, true, true, false,
@@ -598,6 +601,13 @@ handle_fnspec_attribute (tree *node ATTRIBUTE_UNUSED, tree
ARG_UNUSED (name),
   return NULL_TREE;
 }

+static tree
+handle_cold_attribute (tree *, tree, tree, int, bool *)
+{
+  /* Is there anything to be done here?  */
+  return NULL_TREE;
+}
+
 /* Cribbed from c-common.cc.  */

 static void

Reply via email to