c-family: fix attribute constructor ICE [PR90658]
authorMarek Polacek <polacek@redhat.com>
Thu, 26 May 2022 22:59:44 +0000 (18:59 -0400)
committerMarek Polacek <polacek@redhat.com>
Fri, 27 May 2022 15:55:19 +0000 (11:55 -0400)
Here the C compiler crashes because a FUNCTION_DECL got into
get_priority -> default_conversion, and the C FE's version of d_c
specifically asserts that it doesn't get a FUNCTION_DECL.  All uses
of default_conversion in c-attribs.cc are guarded by != IDENTIFIER_NODE
&& != FUNCTION_DECL, but get_priority was only checking IDENTIFIER_NODE.

PR c/90658

gcc/c-family/ChangeLog:

* c-attribs.cc (get_priority): Check FUNCTION_DECL.

gcc/testsuite/ChangeLog:

* c-c++-common/attr-cdtor-1.c: New test.

gcc/c-family/c-attribs.cc
gcc/testsuite/c-c++-common/attr-cdtor-1.c [new file with mode: 0644]

index 4dc68db..c8d9672 100644 (file)
@@ -1895,7 +1895,7 @@ get_priority (tree args, bool is_destructor)
     }
 
   arg = TREE_VALUE (args);
-  if (TREE_CODE (arg) == IDENTIFIER_NODE)
+  if (TREE_CODE (arg) == IDENTIFIER_NODE || TREE_CODE (arg) == FUNCTION_DECL)
     goto invalid;
   if (arg == error_mark_node)
     return DEFAULT_INIT_PRIORITY;
diff --git a/gcc/testsuite/c-c++-common/attr-cdtor-1.c b/gcc/testsuite/c-c++-common/attr-cdtor-1.c
new file mode 100644 (file)
index 0000000..ea61336
--- /dev/null
@@ -0,0 +1,6 @@
+/* PR c/90658 */
+/* { dg-do compile } */
+
+void f ();
+void g1 () __attribute__ ((constructor(f))); /* { dg-error "priorities must be integers" } */
+void g2 () __attribute__ ((destructor(f))); /* { dg-error "priorities must be integers" } */