This patch adds attribute handlers for two new attributes: "debug_annotate_decl" and "debug_annotate_type". Both attributes accept a single string argument, and are used to add arbitrary annotations to debug information generated for the decls or types to which they apply.
gcc/c-family/ * c-attribs.cc (c_common_attribute_table): Add new attributes debug_annotate_decl and debug_annotate_type. (handle_debug_annotate_decl_attribute): New. (handle_debug_annotate_type_attribute): Likewise. --- gcc/c-family/c-attribs.cc | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index c8d96723f4c..50e8fc1b695 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -174,6 +174,9 @@ static tree handle_signed_bool_precision_attribute (tree *, tree, tree, int, bool *); static tree handle_retain_attribute (tree *, tree, tree, int, bool *); +static tree handle_debug_annotate_decl_attribute (tree *, tree, tree, int, bool *); +static tree handle_debug_annotate_type_attribute (tree *, tree, tree, int, bool *); + /* Helper to define attribute exclusions. */ #define ATTR_EXCL(name, function, type, variable) \ { name, function, type, variable } @@ -555,6 +558,10 @@ const struct attribute_spec c_common_attribute_table[] = handle_dealloc_attribute, NULL }, { "tainted_args", 0, 0, true, false, false, false, handle_tainted_args_attribute, NULL }, + { "debug_annotate_decl", 1, 1, false, false, false, false, + handle_debug_annotate_decl_attribute, NULL }, + { "debug_annotate_type", 1, 1, false, true, false, false, + handle_debug_annotate_type_attribute, NULL }, { NULL, 0, 0, false, false, false, false, NULL, NULL } }; @@ -5868,6 +5875,42 @@ handle_tainted_args_attribute (tree *node, tree name, tree, int, return NULL_TREE; } +/* Handle a "debug_annotate_decl" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_debug_annotate_decl_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 "debug_annotate_type" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_debug_annotate_type_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. */ -- 2.36.1