1 /* Demonstrates how to add custom attributes */
3 #include "gcc-plugin.h"
13 #include "diagnostic.h"
15 int plugin_is_GPL_compatible
;
17 /* Attribute handler callback */
20 handle_user_attribute (tree
*node
, tree name
, tree args
,
21 int flags
, bool *no_add_attrs
)
26 /* Attribute definition */
28 static struct attribute_spec user_attr
=
29 { "user", 1, 1, false, false, false, handle_user_attribute
, false };
31 /* Plugin callback called during attribute registration */
34 register_attributes (void *event_data
, void *data
)
36 warning (0, G_("Callback to register attributes"));
37 register_attribute (&user_attr
);
40 /* Callback function to invoke before the function body is genericized. */
43 handle_pre_generic (void *event_data
, void *data
)
45 tree fndecl
= (tree
) event_data
;
47 for (arg
= DECL_ARGUMENTS(fndecl
); arg
; arg
= DECL_CHAIN (arg
)) {
49 for (attr
= DECL_ATTRIBUTES (arg
); attr
; attr
= TREE_CHAIN (attr
)) {
50 tree attrname
= TREE_PURPOSE (attr
);
51 tree attrargs
= TREE_VALUE (attr
);
52 warning (0, G_("attribute '%s' on param '%s' of function %s"),
53 IDENTIFIER_POINTER (attrname
),
54 IDENTIFIER_POINTER (DECL_NAME (arg
)),
55 IDENTIFIER_POINTER (DECL_NAME (fndecl
))
62 plugin_init (struct plugin_name_args
*plugin_info
,
63 struct plugin_gcc_version
*version
)
65 const char *plugin_name
= plugin_info
->base_name
;
66 register_callback (plugin_name
, PLUGIN_PRE_GENERICIZE
,
67 handle_pre_generic
, NULL
);
69 register_callback (plugin_name
, PLUGIN_ATTRIBUTES
, register_attributes
, NULL
);