From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7824) id 2A4213857BA6; Fri, 7 Oct 2022 18:34:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A4213857BA6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665167671; bh=kqzDSAeSY5+ooWb3rZrRpr4BnnKJAcl7IXH09As8NJE=; h=From:To:Subject:Date:From; b=cHM6vppsu/uYDWIfphFmqtI3qMKoj0Z04rbZKuG2iiRvvqY+W8TZJ0rCx48PS4RR6 B0Lxk15PP+p8D0SmKDKxjfiRFeZmEqU1Tr6y1Gve1Q8k0XuXPaIcmswTWWftIn3Coi szrBhtSvg8ft7Z2Z3ZMBhmOW1bH6zSL0y2R6Ntj8= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: David Faust To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/dfaust/heads/btf-type-tag-new-rebase)] c-family: Add BTF tag attribute handlers X-Act-Checkin: gcc X-Git-Author: David Faust X-Git-Refname: refs/users/dfaust/heads/btf-type-tag-new-rebase X-Git-Oldrev: b6e7be91ec799f465f90c678bf4e1e8c4242a6b5 X-Git-Newrev: 4587fe84d9fed5eb7f0ea58784ec04f878ea5312 Message-Id: <20221007183431.2A4213857BA6@sourceware.org> Date: Fri, 7 Oct 2022 18:34:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4587fe84d9fed5eb7f0ea58784ec04f878ea5312 commit 4587fe84d9fed5eb7f0ea58784ec04f878ea5312 Author: David Faust Date: Wed Mar 2 15:01:58 2022 -0800 c-family: Add BTF tag attribute handlers This patch adds attribute handlers in GCC for two attributes already supported in LLVM: "btf_decl_tag" and "btf_type_tag". Both attributes accept a single string constant argument, and are used to add arbitrary annotations to debug information generated for the types/decls to which they apply. gcc/c-family/ * c-attribs.cc (c_common_attribute_table): Add new attributes btf_decl_tag and btf_type_tag. (handle_btf_decl_tag_attribute): New. (handle_btf_type_tag_attribute): Likewise. Diff: --- gcc/c-family/c-attribs.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 671ea38fd1b..346d8dc8a81 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -176,6 +176,9 @@ static tree handle_signed_bool_precision_attribute (tree *, tree, tree, int, static tree handle_retain_attribute (tree *, tree, tree, int, bool *); static tree handle_fd_arg_attribute (tree *, tree, tree, int, bool *); +static tree handle_btf_decl_tag_attribute (tree *, tree, tree, int, bool *); +static tree handle_btf_type_tag_attribute (tree *, tree, tree, int, bool *); + /* Helper to define attribute exclusions. */ #define ATTR_EXCL(name, function, type, variable) \ { name, function, type, variable } @@ -565,6 +568,12 @@ const struct attribute_spec c_common_attribute_table[] = handle_fd_arg_attribute, NULL}, { "fd_arg_write", 1, 1, false, true, true, false, handle_fd_arg_attribute, NULL}, + + { "btf_type_tag", 1, 1, false, true, false, false, + handle_btf_type_tag_attribute, NULL }, + { "btf_decl_tag", 1, 1, false, false, false, false, + handle_btf_decl_tag_attribute, NULL }, + { NULL, 0, 0, false, false, false, false, NULL, NULL } }; @@ -5921,6 +5930,42 @@ handle_tainted_args_attribute (tree *node, tree name, tree, int, return NULL_TREE; } +/* Handle a "btf_decl_tag" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_btf_decl_tag_attribute (tree *, tree name, tree args, int, + bool *no_add_attrs) +{ + if (!args) + *no_add_attrs = true; + else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST) + { + error ("%qE attribute requires a string", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + +/* Handle a "btf_type_tag" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_btf_type_tag_attribute (tree *, tree name, tree args, int, + bool *no_add_attrs) +{ + if (!args) + *no_add_attrs = true; + else if (TREE_CODE (TREE_VALUE (args)) != STRING_CST) + { + error ("%qE attribute requires a string", name); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Attempt to partially validate a single attribute ATTR as if it were to be applied to an entity OPER. */