Fix warning with -Wsign-compare -Wsystem-headers
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / ggcplug.c
blobc186d119371db98322d6f5934e17cbf064daf9d8
1 /* This plugin tests the GGC related plugin events. */
2 /* { dg-options "-O" } */
4 #include "config.h"
5 #include "system.h"
6 #include "coretypes.h"
7 #include "gcc-plugin.h"
8 #include "tm.h"
9 #include "tree.h"
10 #include "toplev.h"
11 #include "basic-block.h"
12 #include "hash-table.h"
13 #include "vec.h"
14 #include "ggc.h"
15 #include "tree-ssa-alias.h"
16 #include "internal-fn.h"
17 #include "gimple-fold.h"
18 #include "tree-eh.h"
19 #include "gimple-expr.h"
20 #include "is-a.h"
21 #include "gimple.h"
22 #include "tree.h"
23 #include "tree-pass.h"
24 #include "intl.h"
25 #include "plugin-version.h"
26 #include "diagnostic.h"
28 int plugin_is_GPL_compatible;
30 /* our callback is the same for all PLUGIN_GGC_START,
31 PLUGIN_GGC_MARKING, PLUGIN_GGC_END events; it just increments the
32 user_data which is an int */
33 static void increment_callback (void *gcc_data, void *user_data);
35 /* our counters are user_data */
36 static int our_ggc_start_counter;
37 static int our_ggc_end_counter;
38 static int our_ggc_marking_counter;
40 /* our empty GGC extra root table */
41 static const struct ggc_root_tab our_xtratab[] = {
42 LAST_GGC_ROOT_TAB
46 /* The initialization routine exposed to and called by GCC. The spec of this
47 function is defined in gcc/gcc-plugin.h.
49 Note that this function needs to be named exactly "plugin_init". */
50 int
51 plugin_init (struct plugin_name_args *plugin_info,
52 struct plugin_gcc_version *version)
54 const char *plugin_name = plugin_info->base_name;
55 int argc = plugin_info->argc;
56 int i = 0;
57 struct plugin_argument *argv = plugin_info->argv;
58 if (!plugin_default_version_check (version, &gcc_version))
59 return 1;
60 /* Process the plugin arguments. This plugin takes the following arguments:
61 count-ggc-start count-ggc-end count-ggc-mark */
62 for (i = 0; i < argc; ++i)
64 if (!strcmp (argv[i].key, "count-ggc-start"))
66 if (argv[i].value)
67 warning (0, G_("option '-fplugin-arg-%s-count-ggc-start=%s'"
68 " ignored (superfluous '=%s')"),
69 plugin_name, argv[i].value, argv[i].value);
70 else
71 register_callback ("ggcplug",
72 PLUGIN_GGC_START,
73 increment_callback,
74 (void *) &our_ggc_start_counter);
76 else if (!strcmp (argv[i].key, "count-ggc-end"))
78 if (argv[i].value)
79 warning (0, G_("option '-fplugin-arg-%s-count-ggc-end=%s'"
80 " ignored (superfluous '=%s')"),
81 plugin_name, argv[i].value, argv[i].value);
82 else
83 register_callback ("ggcplug",
84 PLUGIN_GGC_END,
85 increment_callback,
86 (void *) &our_ggc_end_counter);
88 else if (!strcmp (argv[i].key, "count-ggc-mark"))
90 if (argv[i].value)
91 warning (0, G_("option '-fplugin-arg-%s-count-ggc-mark=%s'"
92 " ignored (superfluous '=%s')"),
93 plugin_name, argv[i].value, argv[i].value);
94 else
95 register_callback ("ggcplug",
96 PLUGIN_GGC_MARKING,
97 increment_callback,
98 (void *) &our_ggc_marking_counter);
100 else if (!strcmp (argv[i].key, "test-extra-root"))
102 if (argv[i].value)
103 warning (0, G_("option '-fplugin-arg-%s-test-extra-root=%s'"
104 " ignored (superfluous '=%s')"),
105 plugin_name, argv[i].value, argv[i].value);
106 else
107 register_callback ("ggcplug",
108 PLUGIN_REGISTER_GGC_ROOTS,
109 NULL,
110 (void *) our_xtratab);
113 /* plugin initialization succeeded */
114 return 0;
117 static void
118 increment_callback (void *gcc_data, void *user_data)
120 int *usercountptr = (int *) user_data;
121 gcc_assert (!gcc_data);
122 gcc_assert (user_data);
123 (*usercountptr)++;