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