1 /* Demonstrates how to add custom attributes */
3 #include "gcc-plugin.h"
12 int plugin_is_GPL_compatible;
14 /* Attribute handler callback */
17 handle_user_attribute (tree *node, tree name, tree args,
18 int flags, bool *no_add_attrs)
23 /* Attribute definition */
25 static struct attribute_spec user_attr =
26 { "user", 1, 1, false, false, false, handle_user_attribute };
28 /* Plugin callback called during attribute registration */
31 register_attributes (void *event_data, void *data)
33 warning (0, G_("Callback to register attributes"));
34 register_attribute (&user_attr);
37 /* Callback function to invoke before the function body is genericized. */
40 handle_pre_generic (void *event_data, void *data)
42 tree fndecl = (tree) event_data;
44 for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN (arg)) {
46 for (attr = DECL_ATTRIBUTES (arg); attr; attr = TREE_CHAIN (attr)) {
47 tree attrname = TREE_PURPOSE (attr);
48 tree attrargs = TREE_VALUE (attr);
49 warning (0, G_("attribute '%s' on param '%s' of function %s"),
50 IDENTIFIER_POINTER (attrname),
51 IDENTIFIER_POINTER (DECL_NAME (arg)),
52 IDENTIFIER_POINTER (DECL_NAME (fndecl))
59 plugin_init (struct plugin_name_args *plugin_info,
60 struct plugin_gcc_version *version)
62 const char *plugin_name = plugin_info->base_name;
63 register_callback (plugin_name, PLUGIN_CXX_CP_PRE_GENERICIZE,
64 handle_pre_generic, NULL);
66 register_callback (plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);