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

            Bug ID: 118746
           Summary: In go FE, __builtin_unreachable does not have the
                    attribute cold - or any attribute, for that matter
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: jamborm at gcc dot gnu.org
  Target Milestone: ---

As discovered in PR 118125 (where the issue was with lto "front-end"),
builtins only get their attributes if these attributes are listed in
attribute_spec reachable from LANG_HOOKS_ATTRIBUTE_TABLE.

As far as I can grep, go does not provide any
LANG_HOOKS_ATTRIBUTE_TABLE which probably means that no builtin gets
any attribute at all, certainly __builtin_unreachable does not:

  (gdb) pt target->decl
   <function_decl 0x7fffbf433a00 __builtin_unreachable
      type <function_type 0x7fffbf42d5e8
          type <void_type 0x7fffbf41cf18 asm_written VOID
              align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0x7fffbf41cf18
              pointer_to_this <pointer_type 0x7fffbf424000>>
          asm_written QI
          size <integer_cst 0x7fffbf402eb8 constant 8>
          unit-size <integer_cst 0x7fffbf402ed0 constant 1>
          align:8 warn_if_not_align:0 symtab:-1125496800 alias-set -1
   canonical-type 0x7fffbf4  2d5e8
          arg-types <tree_list 0x7fffbf41bde8 value <void_type 0x7fffbf41cf18>>
          pointer_to_this <pointer_type 0x7fffbf59cf18>>
      readonly volatile public external built-in QI <built-in>:0:0
      align:8 warn_if_not_align:0 built-in:
BUILT_IN_NORMAL:BUILT_IN_UNREACHABLE>
  (gdb) p target->decl->decl_common.attributes
  $1 = NULL_TREE

As discussed in the other bug, not having the cold attribute can have
big performance implications.  Needless to say, __builtin_unreachable
should really also be noreturn function to be mean what it is supposed
to mean.

The issue can be reproduced by applying the following patch and
building libgo.

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)

Reply via email to