1 /* This plugin tests the correct operation of a PLUGIN_START_UNIT callback.
2 * By the time a PLUGIN_START_UNIT callback is invoked, the frontend
3 * initialization should have completed. At least the different *_type_nodes
4 * should have been created. This plugin creates an artifical global
8 #include "gcc-plugin.h"
11 #include "coretypes.h"
14 #include "basic-block.h"
17 #include "tree-pass.h"
20 int plugin_is_GPL_compatible;
21 static tree fake_var = NULL;
24 gate_start_unit (void)
29 static void start_unit_callback (void *gcc_data, void *user_data)
31 if (integer_type_node) {
32 fake_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
33 get_identifier ("_fake_var_"),
35 TREE_PUBLIC (fake_var) = 1;
36 DECL_ARTIFICIAL (fake_var) = 1;
40 static void finish_unit_callback (void *gcc_data, void *user_data)
42 if (fake_var == NULL) {
43 printf ("fake_var not created \n");
46 if (TREE_CODE (fake_var) != VAR_DECL) {
47 printf ("fake_var not a VAR_DECL \n");
50 if (TREE_CODE (TREE_TYPE (fake_var)) != INTEGER_TYPE) {
51 printf ("fake_var not INTEGER_TYPE \n");
54 if (DECL_ARTIFICIAL (fake_var) == 0) {
55 printf ("fake_var not ARTIFICIAL \n");
60 int plugin_init (struct plugin_name_args *plugin_info,
61 struct plugin_gcc_version *version)
63 register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
64 register_callback ("finish_unit", PLUGIN_FINISH_UNIT, &finish_unit_callback, NULL);