]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/plugin/start_unit_plugin.c
Re-factor inclusion of tree.h.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / plugin / start_unit_plugin.c
CommitLineData
275b769b 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
69b39ef2 4 * should have been created. This plugin creates an artificial global
275b769b 5 * interger variable.
6 *
7*/
8#include "gcc-plugin.h"
9#include "config.h"
10#include "system.h"
11#include "coretypes.h"
12#include "tm.h"
41a8aa41 13#include "tree.h"
275b769b 14#include "toplev.h"
15#include "basic-block.h"
16#include "gimple.h"
17#include "tree.h"
18#include "tree-pass.h"
19#include "intl.h"
20
21int plugin_is_GPL_compatible;
22static tree fake_var = NULL;
23
24static bool
25gate_start_unit (void)
26{
27 return true;
28}
29
30static void start_unit_callback (void *gcc_data, void *user_data)
31{
32 if (integer_type_node) {
33 fake_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
34 get_identifier ("_fake_var_"),
35 integer_type_node);
36 TREE_PUBLIC (fake_var) = 1;
37 DECL_ARTIFICIAL (fake_var) = 1;
38 }
39}
40
41static void finish_unit_callback (void *gcc_data, void *user_data)
42{
43 if (fake_var == NULL) {
44 printf ("fake_var not created \n");
45 return;
46 }
47 if (TREE_CODE (fake_var) != VAR_DECL) {
48 printf ("fake_var not a VAR_DECL \n");
49 return;
50 }
51 if (TREE_CODE (TREE_TYPE (fake_var)) != INTEGER_TYPE) {
52 printf ("fake_var not INTEGER_TYPE \n");
53 return;
54 }
55 if (DECL_ARTIFICIAL (fake_var) == 0) {
56 printf ("fake_var not ARTIFICIAL \n");
57 return;
58 }
59}
60
61int plugin_init (struct plugin_name_args *plugin_info,
62 struct plugin_gcc_version *version)
63{
64 register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
65 register_callback ("finish_unit", PLUGIN_FINISH_UNIT, &finish_unit_callback, NULL);
66 return 0;
67}