Hi,
thanks for the review. Please find the revised patch below. I didn't
run the entire testsuite on it, I just built it and tested the attached
testcase to make sure it still worked.
Best regards,
Josef
-- >8 --
Rejection of unprototyped functions from the callback_only attribute has
been mentioned on this mailing list. It has now also come up in the
form of PR127464. This patch implements the check for unprototyped
functions and adds a mention about them in the attribute's
documentation.
Best regards,
Josef
PR c/127464
gcc/c-family/ChangeLog:
* c-attribs.cc (handle_callback_only_attribute): Reject
unprototyped functions.
gcc/ChangeLog:
* doc/extend.texi (callback_only): Add a sentence about unprototyped
functions to callback_only docs.
gcc/testsuite/ChangeLog:
* gcc.dg/pr127464.c: New test.
Signed-off-by: Josef Melcr <[email protected]>
---
gcc/c-family/c-attribs.cc | 18 ++++++++++++++++--
gcc/doc/extend.texi | 2 +-
gcc/testsuite/gcc.dg/pr127464.c | 9 +++++++++
3 files changed, 26 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr127464.c
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 470054f044a..b41b9d1d72a 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -3951,7 +3951,14 @@ handle_callback_only_attribute (tree *node, tree name,
tree args,
}
tree decl_type = TREE_TYPE (decl);
- if (stdarg_p (decl_type))
+ if (!prototype_p (decl_type))
+ {
+ warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
+ "%qE attribute requires a prototype", name);
+ *no_add_attrs = true;
+ return NULL_TREE;
+ }
+ else if (stdarg_p (decl_type))
{
warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
"%qE attribute cannot be used on variadic functions", name);
@@ -4002,7 +4009,14 @@ handle_callback_only_attribute (tree *node, tree name,
tree args,
tree type_args = TYPE_ARG_TYPES (cfn_pointee_type);
- if (stdarg_p (cfn_pointee_type))
+ if (!prototype_p (cfn_pointee_type))
+ {
+ warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
+ "%qE callback function must have a prototype", name);
+ *no_add_attrs = true;
+ return NULL_TREE;
+ }
+ else if (stdarg_p (cfn_pointee_type))
{
warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes,
"%qE callback function cannot be variadic", name);
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index 9b616133468..a35b95cc74f 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2375,7 +2375,7 @@ may not change or dereference them. The arguments also
may not escape.
The attribute may be used multiple times per function, though only one
@code{callback_only} attribute may be used per function parameter.
Neither the dispatching function nor the callback function may be
-variadic.
+variadic. Both functions must have a prototype.
The attribute exposes the potentially hidden callsite in the annotated
function, enabling interprocedural optimizations which may not be
diff --git a/gcc/testsuite/gcc.dg/pr127464.c b/gcc/testsuite/gcc.dg/pr127464.c
new file mode 100644
index 00000000000..1c33769ca6f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr127464.c
@@ -0,0 +1,9 @@
+/* PR c/127464 */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -Wattributes" } */
+
+[[gnu::callback_only (1, 2, 3), gnu::callback_only (4, 5)]]
+void bar (); /* { dg-warning "requires a prototype" }*/
+
+[[gnu::callback_only (1, 2, 3)]]
+void foo (void (*) (), int *, double); /* { dg-warning "must have a prototype"
} */
--
2.56.0