[{"id":3685591,"web_url":"http://patchwork.ozlabs.org/comment/3685591/","msgid":"<afhdd8trem7X17uI@tucnak>","list_archive_url":null,"date":"2026-05-04T08:48:55","subject":"Re: [PATCH v2] Add callback_only attribute","submitter":{"id":671,"url":"http://patchwork.ozlabs.org/api/people/671/","name":"Jakub Jelinek","email":"jakub@redhat.com"},"content":"On Mon, May 04, 2026 at 10:40:23AM +0200, Josef Melcr wrote:\n>    gcc_checking_assert (cb_attr);\n>    tree res = NULL_TREE;\n>    for (; cb_attr;\n> -       cb_attr = lookup_attribute (CALLBACK_ATTR_IDENT, TREE_CHAIN (cb_attr)))\n> +       cb_attr = lookup_attribute (\"gnu\", CALLBACK_ATTR_IDENT, TREE_CHAIN (cb_attr)))\n\nPlease watch formatting, the above line is now definitely too long.\n>      {\n>        unsigned id = callback_get_fn_index (cb_attr);\n>        if (id == e->callback_id)\n> @@ -229,10 +229,10 @@ handle_callback_attribute (tree *node, tree name, tree args,\n>        return NULL_TREE;\n>      }\n>    --callback_fn_idx;\n> -  if (callback_fn_idx >= decl_nargs)\n> +  if (callback_fn_idx < 0 || callback_fn_idx >= decl_nargs)\n>      {\n>        error_at (DECL_SOURCE_LOCATION (decl),\n> -\t\t\"callback function position out of range\");\n> +\t\t\"callback function index %d is out of range\", callback_fn_idx + 1);\n\nThis one too.\n> @@ -331,8 +331,8 @@ handle_callback_attribute (tree *node, tree name, tree args,\n>  \n>    /* Check that the decl does not already have a callback attribute describing\n>       the same argument.  */\n> -  it = lookup_attribute (CALLBACK_ATTR_IDENT, DECL_ATTRIBUTES (decl));\n> -  for (; it; it = lookup_attribute (CALLBACK_ATTR_IDENT, TREE_CHAIN (it)))\n> +  it = lookup_attribute (\"gnu\", CALLBACK_ATTR_IDENT, DECL_ATTRIBUTES (decl));\n> +  for (; it; it = lookup_attribute (\"gnu\", CALLBACK_ATTR_IDENT, TREE_CHAIN (it)))\n\nAnd this one too.\n>      if (callback_get_fn_index (it) == callback_fn_idx)\n>        {\n>  \terror_at (DECL_SOURCE_LOCATION (decl),\n> diff --git a/gcc/attr-callback.h b/gcc/attr-callback.h\n> index b2c1c3c09c5..e51c4c6c571 100644\n> --- a/gcc/attr-callback.h\n> +++ b/gcc/attr-callback.h\n> @@ -28,7 +28,7 @@ enum callback_position\n>    CB_UNKNOWN_POS = 0\n>  };\n>  \n> -#define CALLBACK_ATTR_IDENT \" callback\"\n> +#define CALLBACK_ATTR_IDENT \"callback_only\"\n>  \n>  /* Returns a callback attribute with callback index FN_IDX, and ARG_COUNT\n>     arguments specified by VA_ARGS.  */\n> diff --git a/gcc/builtin-attrs.def b/gcc/builtin-attrs.def\n> index be80184b1a1..a395f454be1 100644\n> --- a/gcc/builtin-attrs.def\n> +++ b/gcc/builtin-attrs.def\n> @@ -130,7 +130,7 @@ DEF_ATTR_IDENT (ATTR_TM_TMPURE, \"transaction_pure\")\n>  DEF_ATTR_IDENT (ATTR_RETURNS_TWICE, \"returns_twice\")\n>  DEF_ATTR_IDENT (ATTR_RETURNS_NONNULL, \"returns_nonnull\")\n>  DEF_ATTR_IDENT (ATTR_WARN_UNUSED_RESULT, \"warn_unused_result\")\n> -DEF_ATTR_IDENT (ATTR_CALLBACK, \" callback\")\n> +DEF_ATTR_IDENT (ATTR_CALLBACK, \"callback_only\")\n>  \n>  DEF_ATTR_TREE_LIST (ATTR_NOVOPS_LIST, ATTR_NOVOPS, ATTR_NULL, ATTR_NULL)\n>  \n> diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc\n> index d437c55285e..2d04b4c1ad2 100644\n> --- a/gcc/c-family/c-attribs.cc\n> +++ b/gcc/c-family/c-attribs.cc\n> @@ -485,8 +485,6 @@ const struct attribute_spec c_common_gnu_attributes[] =\n>  \t\t\t      handle_tm_attribute, NULL },\n>    { \"transaction_may_cancel_outer\", 0, 0, false, true, false, false,\n>  \t\t\t      handle_tm_attribute, NULL },\n> -  { CALLBACK_ATTR_IDENT,      1, -1, true, false, false, false,\n> -\t\t\t      handle_callback_attribute, NULL },\n>    /* ??? These two attributes didn't make the transition from the\n>       Intel language document to the multi-vendor language document.  */\n>    { \"transaction_pure\",       0, 0, false, true,  false, false,\n> @@ -707,6 +705,20 @@ const struct scoped_attribute_specs c_common_format_attribute_table =\n>    \"gnu\", { c_common_format_attributes }\n>  };\n>  \n> +/* Attribute table for the callback attribute to be used by the C frontends.  We\n> +   don't want to expose the attribute outside of the GNU namespace, so it has to\n\nThese two too.\n\n> @@ -4419,9 +4419,9 @@ cgraph_node::verify_node (void)\n>  \t    {\n>  \t      int ncallbacks = 0;\n>  \t      int nfound_edges = 0;\n> -\t      for (tree cb = lookup_attribute (CALLBACK_ATTR_IDENT, DECL_ATTRIBUTES (\n> +\t      for (tree cb = lookup_attribute (\"gnu\", CALLBACK_ATTR_IDENT, DECL_ATTRIBUTES (\n>  \t\t\t\t\t\t\t     e->callee->decl));\n> -\t\t   cb; cb = lookup_attribute (CALLBACK_ATTR_IDENT, TREE_CHAIN (cb)),\n> +\t\t   cb; cb = lookup_attribute (\"gnu\", CALLBACK_ATTR_IDENT, TREE_CHAIN (cb)),\n\nAnd here as well.  Note, DECL_ATTRIBUTES ( one one line and argument on\nanother one is ugly, better\n\t      for (tree cb\n\t\t   = lookup_attribute (\"gnu\", CALLBACK_ATTR_IDENT,\n\t\t\t\t       DECL_ATTRIBUTES (e->callee->decl));\n\t\t   cb; cb = lookup_attribute (\"gnu\", CALLBACK_ATTR_IDENT,\n\t\t\t\t\t      TREE_CHAIN (cb)), ncallbacks++)\n\n> +@cindex @code{callback_only} function attribute\n> +@item callback_only\n> +The @code{callback_only} attribute specifies that the annotated\n> +function may call the specified callback function. The first parameter\n> +identifies the index of the callback function, the rest of the arguments specify the\n> +indices of the arguments of the indirect call. All indices start from 1. If the function\n> +takes the implicit @code{this} pointer, it is referred to by the index 1, with\n> +the rest of the arguments starting at index 2. The index 0 marks an argument not\n> +present in the arguments of the annotated function, an argument which is\n> +modified before calling the callback function. The annotated function must pass the\n> +specified arguments in the specified order to the callback function, which must be\n> +callable with the number, order and type of the arguments. The specified pointer\n> +to the callback may not escape the translation unit of the annotated function and it\n> +may not be captured. The annotated function is required to pass the arguments\n> +through, it may not change or dereference them. The arguments also may not escape.\n> +The attribute may be used multiple times per function, though only one @code{callback_only}\n> +attribute may be used per function parameter.\n> +\n> +The attribute exposes the potentially hidden callsite in the annotated function,\n> +enabling interprocedural optimizations which may not be possible without the\n> +attribute. It is most useful for annotating functions from dynamically linked libraries,\n> +as their bodies are not available during compilation.\n> +\n> +This attribute is similar to the clang @code{callback} attribute but it is not compatible\n> +with it. The clang implementation allows identifiers as arguments, marks an unknown\n> +argument with -1 and the @code{this} pointer with the index 0.\n\nHere too, many lines.\n\nTestsuite is fine vs. line length I think, especially if it is dg- directive\ncomments that are overlong.\n\n\tJakub","headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=ZdsYHehM;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=ZdsYHehM","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.133.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g8Fly1V5Kz1yJ9\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 04 May 2026 18:53:02 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id AD43E4BAE7E1\n\tfor <incoming@patchwork.ozlabs.org>; Mon,  4 May 2026 08:52:59 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id E90E64BABF33\n for <gcc-patches@gcc.gnu.org>; Mon,  4 May 2026 08:49:03 +0000 (GMT)","from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-624-FG9cc2CyPDms4IXzD9WYcg-1; Mon,\n 04 May 2026 04:49:00 -0400","from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id DFB5E1956094; Mon,  4 May 2026 08:48:59 +0000 (UTC)","from tucnak.zalov.cz (unknown [10.44.32.15])\n by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 41FC01953952; Mon,  4 May 2026 08:48:59 +0000 (UTC)","from tucnak.zalov.cz (localhost [127.0.0.1])\n by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 6448muFs2247720\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Mon, 4 May 2026 10:48:56 +0200","(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 6448muJv2247719;\n Mon, 4 May 2026 10:48:56 +0200"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org AD43E4BAE7E1","OpenDKIM Filter v2.11.0 sourceware.org E90E64BABF33"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org E90E64BABF33","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org E90E64BABF33","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777884544; cv=none;\n b=IZKFUGCP4fxHof6dni+/6U5m6gE0F5IgvLQAXEz5JBmrojNGnDX2NbwV48Le6g1r/vlChRhf/dYZV8UgODs7ThOyyHL7wigQ6WVeAqBClUubyM3oGIvSV55hV/afVOw5P4UPMkHIRolAV2LWJGFoW6hcDa5zvTqqIGH3E3JcWas=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777884544; c=relaxed/simple;\n bh=WR4QskLDzrMcdoOPXNY+MG5s9e+QUuX4E20tfNlfgHI=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=aH19W9H8kHJ9goEOjmM9kcqy722FPOd2Om8h8T09d1lSi6oKu6LZveGlxNfkoydmeXaBb7mkDBhaBzFWBxbpZHaTE6AoOuQIWVxfsN0rkXRcalPVlWAT0MylqrN9cxIqtbUejJ/TEAi1KDKX1ok+yevgwXVpr9XWnMZowtOEqaM=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1777884542;\n h=from:from:reply-to:reply-to:subject:subject:date:date:\n message-id:message-id:to:to:cc:cc:mime-version:mime-version:\n content-type:content-type:in-reply-to:in-reply-to:  references:references;\n bh=r2LlxBX26y2PC2E5Ahs7K6UJePWh3329KDkhGI6pjcI=;\n b=ZdsYHehM4oUB3jRTjIckyaJzOgmDo6cEd6rg0SRR6NJq4fsHRw0i4qcNP0674VwSFqKera\n CnNT+uleACiDs5jhcJHae/cAPaLX0ykIpqQuMI+5WdjJYEBGIwZIIlq8lYbZ2AUZbKUwAN\n UOjkRmcePJ0wEoB/ECHhvbspz3OA/0M=","X-MC-Unique":"FG9cc2CyPDms4IXzD9WYcg-1","X-Mimecast-MFC-AGG-ID":"FG9cc2CyPDms4IXzD9WYcg_1777884540","Date":"Mon, 4 May 2026 10:48:55 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"Josef Melcr <josef.melcr@suse.com>","Cc":"gcc-patches@gcc.gnu.org, andrew.pinski@oss.qualcomm.com","Subject":"Re: [PATCH v2] Add callback_only attribute","Message-ID":"<afhdd8trem7X17uI@tucnak>","References":"<20260504084022.29508-2-josef.melcr@suse.com>","MIME-Version":"1.0","In-Reply-To":"<20260504084022.29508-2-josef.melcr@suse.com>","X-Scanned-By":"MIMEDefang 3.0 on 10.30.177.17","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"09mFwreUaztj66J11LfwRiNl6xmaHmt01OZ39HemdNc_1777884540","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"Jakub Jelinek <jakub@redhat.com>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"}}]