]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: init_priority and SUPPORTS_INIT_PRIORITY [PR107638]
authorPatrick Palka <ppalka@redhat.com>
Tue, 15 Nov 2022 02:28:58 +0000 (21:28 -0500)
committerPatrick Palka <ppalka@redhat.com>
Tue, 15 Nov 2022 02:28:58 +0000 (21:28 -0500)
The commit r13-3706-gd0a492faa6478c for fixing the result of
__has_attribute(init_priority) causes a bootstrap failure on hppa64-hpux
due to assuming the macro SUPPORTS_INIT_PRIORITY expands to a simple
constant, but on this target the macro is defined as

  #define SUPPORTS_INIT_PRIORITY (TARGET_GNU_LD ? 1 : 0)

(where TARGET_GNU_LD expands to something in terms of global_options)
which means we can't use the macro to conditionally exclude the entry
for init_priority when defining the cxx_attribute_table.

So instead of trying to exclude init_priority from the attribute table,
this patch just makes __has_attribute handle init_priority specially.

PR c++/107638

gcc/c-family/ChangeLog:

* c-lex.cc (c_common_has_attribute): Return 1 for init_priority
iff SUPPORTS_INIT_PRIORITY.

gcc/cp/ChangeLog:

* tree.cc (cxx_attribute_table): Don't conditionally exclude
the init_priority entry.
(handle_init_priority_attribute): Remove ATTRIBUTE_UNUSED.
Return error_mark_node if !SUPPORTS_INIT_PRIORITY.

gcc/c-family/c-lex.cc
gcc/cp/tree.cc

index 89c65aca28a8438d25588b22ec86c01f5769dce3..2fe562c7ccfbacbfebd1db13ead3c968b619e996 100644 (file)
@@ -380,6 +380,15 @@ c_common_has_attribute (cpp_reader *pfile, bool std_syntax)
                result = 201907;
              else if (is_attribute_p ("assume", attr_name))
                result = 202207;
+             else if (is_attribute_p ("init_priority", attr_name))
+               {
+                 /* The (non-standard) init_priority attribute is always
+                    included in the attribute table, but we don't want to
+                    advertise the attribute unless the target actually
+                    supports init priorities.  */
+                 result = SUPPORTS_INIT_PRIORITY ? 1 : 0;
+                 attr_name = NULL_TREE;
+               }
            }
          else
            {
index 954c6de2fcd396483b4d0f7160e04a3e0de79d10..e352cf8021374301df778e6e82e2cca69985815f 100644 (file)
@@ -5036,10 +5036,8 @@ const struct attribute_spec cxx_attribute_table[] =
 {
   /* { name, min_len, max_len, decl_req, type_req, fn_type_req,
        affects_type_identity, handler, exclude } */
-#if SUPPORTS_INIT_PRIORITY
   { "init_priority",  1, 1, true,  false, false, false,
     handle_init_priority_attribute, NULL },
-#endif
   { "abi_tag", 1, -1, false, false, false, true,
     handle_abi_tag_attribute, NULL },
   { NULL, 0, 0, false, false, false, false, NULL, NULL }
@@ -5069,13 +5067,18 @@ const struct attribute_spec std_attribute_table[] =
 
 /* Handle an "init_priority" attribute; arguments as in
    struct attribute_spec.handler.  */
-ATTRIBUTE_UNUSED static tree
+static tree
 handle_init_priority_attribute (tree* node,
                                tree name,
                                tree args,
                                int /*flags*/,
                                bool* no_add_attrs)
 {
+  if (!SUPPORTS_INIT_PRIORITY)
+    /* Treat init_priority as an unrecognized attribute (mirroring
+       __has_attribute) if the target doesn't support init priorities.  */
+    return error_mark_node;
+
   tree initp_expr = TREE_VALUE (args);
   tree decl = *node;
   tree type = TREE_TYPE (decl);
@@ -5133,7 +5136,6 @@ handle_init_priority_attribute (tree* node,
         pri);
     }
 
-  gcc_assert (SUPPORTS_INIT_PRIORITY);
   SET_DECL_INIT_PRIORITY (decl, pri);
   DECL_HAS_INIT_PRIORITY_P (decl) = 1;
   return NULL_TREE;