There was a missing return statement in the attribute handler when
checking whether or not the attribute was used on a function.  Since
positional_argument was introduced into the handler, this uncaught error
would result in an ICE.  This patch fixes that.

gcc/c-family/ChangeLog:

        * c-attribs.cc (handle_callback_only_attribute): Add early
        return if the attribute is not used on a function.

gcc/testsuite/ChangeLog:

        * gcc.dg/attr-callback.c: Add testcases for the early return.

Signed-off-by: Josef Melcr <[email protected]>
---
 gcc/c-family/c-attribs.cc            |  1 +
 gcc/testsuite/gcc.dg/attr-callback.c | 13 +++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index e6ad795949d..4c90e1fe983 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -4685,6 +4685,7 @@ handle_callback_only_attribute (tree *node, tree name, 
tree args,
       warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
                  "%qE attribute can only be used on functions", name);
       *no_add_attrs = true;
+      return NULL_TREE;
     }
 
   tree decl_type = TREE_TYPE (decl);
diff --git a/gcc/testsuite/gcc.dg/attr-callback.c 
b/gcc/testsuite/gcc.dg/attr-callback.c
index 3837af1b118..7e95a00816e 100755
--- a/gcc/testsuite/gcc.dg/attr-callback.c
+++ b/gcc/testsuite/gcc.dg/attr-callback.c
@@ -75,6 +75,19 @@ vararg_1(void (*)(int*), int*, ...); /* { dg-warning "cannot 
be used on variadic
 void
 vararg_2(void (*)(int*, ...), int*); /* { dg-warning "callback function cannot 
be variadic" } */
 
+void
+not_used_on_fn_1 ()
+{
+  __attribute__ ((callback_only (1))) int a = 1; /* { dg-warning "attribute 
can only be used on functions" } */
+}
+
+/* This warning is not issued by the attribute handler, rather by
+   decl_attributes in attribs.cc.  Test it anyway.  */
+struct __attribute__ ((callback_only (1))) not_used_on_fn_2
+{
+  int x;
+}; /* { dg-warning "attribute does not apply to types" } */
+
 struct S
 {
   int x;
-- 
2.55.0

Reply via email to