https://gcc.gnu.org/g:416290b10bb9cb45361630b61af09200962bd5a5
commit r17-4628-g416290b10bb9cb45361630b61af09200962bd5a5 Author: Josef Melcr <[email protected]> Date: Thu Sep 24 11:16:00 2026 +0200 Clean up old code in callback_only attribute handler This patch cleans up two useless loops from the callback_only attribute handler. The first loop used to check for void_list_node, now it does literally nothing. Seems like I forgot to remove it when I changed the validation logic a few weeks ago. The second loop also checks for void_list_node and decrements type_nargs if it finds it, but since we ensure !stdarg_p for both the carrying and the callback function, looking for void_list_node again is pointless. In this case, we can just initialize type_nargs differently. gcc/c-family/ChangeLog: * c-attribs.cc (handle_callback_only_attribute): Clean up old code. Signed-off-by: Josef Melcr <[email protected]> Diff: --- gcc/c-family/c-attribs.cc | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 3c0e780669b4..0e2e17cc0bec 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -4709,10 +4709,6 @@ handle_callback_only_attribute (tree *node, tree name, tree args, DECL_ARGUMENTS returns NULL at this point. */ int callback_fn_idx = TREE_INT_CST_LOW (val); tree decl_type_args = TYPE_ARG_TYPES (decl_type); - tree it; - for (it = decl_type_args; it != NULL_TREE; it = TREE_CHAIN (it)) - if (it == void_list_node) - break; if (callback_fn_idx == CB_UNKNOWN_POS) { @@ -4754,13 +4750,7 @@ handle_callback_only_attribute (tree *node, tree name, tree args, /* Compare the length of the list of argument indices and the real number of parameters the callback takes. */ unsigned cfn_nargs = list_length (TREE_CHAIN (args)); - unsigned type_nargs = list_length (type_args); - for (it = type_args; it != NULL_TREE; it = TREE_CHAIN (it)) - if (it == void_list_node) - { - --type_nargs; - break; - } + unsigned type_nargs = list_length (type_args) - 1; if (cfn_nargs != type_nargs) { warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, @@ -4771,7 +4761,7 @@ handle_callback_only_attribute (tree *node, tree name, tree args, } unsigned curr = 0; - tree cfn_it; + tree it, cfn_it; /* Validate type compatibility of the arguments passed from caller function to callback. "it" is used to step through the parameters of the caller, "cfn_it" is
