1
Index: gcc/doc/plugins.texi
2
===================================================================
3
--- gcc/doc/plugins.texi (revision 162126)
4
+++ gcc/doc/plugins.texi (working copy)
7
PLUGIN_PASS_MANAGER_SETUP, /* To hook into pass manager. */
8
PLUGIN_FINISH_TYPE, /* After finishing parsing a type. */
9
+ PLUGIN_FINISH_DECL, /* After finishing parsing a declaration. */
10
PLUGIN_FINISH_UNIT, /* Useful for summary processing. */
11
PLUGIN_PRE_GENERICIZE, /* Allows to see low level AST in C and C++ frontends. */
12
PLUGIN_FINISH, /* Called before GCC exits. */
14
===================================================================
15
--- gcc/plugin.def (revision 162126)
16
+++ gcc/plugin.def (working copy)
18
/* After finishing parsing a type. */
19
DEFEVENT (PLUGIN_FINISH_TYPE)
21
+/* After finishing parsing a declaration. */
22
+DEFEVENT (PLUGIN_FINISH_DECL)
24
/* Useful for summary processing. */
25
DEFEVENT (PLUGIN_FINISH_UNIT)
27
Index: gcc/testsuite/g++.dg/plugin/plugin.exp
28
===================================================================
29
--- gcc/testsuite/g++.dg/plugin/plugin.exp (revision 162126)
30
+++ gcc/testsuite/g++.dg/plugin/plugin.exp (working copy)
32
{ pragma_plugin.c pragma_plugin-test-1.C } \
33
{ selfassign.c self-assign-test-1.C self-assign-test-2.C self-assign-test-3.C } \
34
{ dumb_plugin.c dumb-plugin-test-1.C } \
35
- { header_plugin.c header-plugin-test.C } ]
36
+ { header_plugin.c header-plugin-test.C } \
37
+ { decl_plugin.c decl-plugin-test.C } ]
39
foreach plugin_test $plugin_test_list {
40
# Replace each source file with its full-path name
41
Index: gcc/testsuite/g++.dg/plugin/decl-plugin-test.C
42
===================================================================
43
--- gcc/testsuite/g++.dg/plugin/decl-plugin-test.C (revision 0)
44
+++ gcc/testsuite/g++.dg/plugin/decl-plugin-test.C (revision 0)
48
+extern int global; // { dg-warning "Decl Global global" }
49
+int global_array[] = { 1, 2, 3 }; // { dg-warning "Decl Global global_array" }
51
+int takes_args(int arg1, int arg2)
53
+ int local = arg1 + arg2 + global; // { dg-warning "Decl Local local" }
57
+int global = 12; // { dg-warning "Decl Global global" }
60
+ int field; // { dg-warning "Decl Field field" }
64
+ int class_field1; // { dg-warning "Decl Field class_field1" }
65
+ int class_field2; // { dg-warning "Decl Field class_field2" }
67
+ test_class() // { dg-warning "Decl Function test_class" }
68
+ : class_field1(0), class_field2(0)
71
+ void swap_fields(int bias) // { dg-warning "Decl Function swap_fields" }
73
+ int temp = class_field1 + bias; // { dg-warning "Decl Local temp" }
74
+ class_field1 = class_field2 - bias;
75
+ class_field2 = temp;
78
Index: gcc/testsuite/g++.dg/plugin/decl_plugin.c
79
===================================================================
80
--- gcc/testsuite/g++.dg/plugin/decl_plugin.c (revision 0)
81
+++ gcc/testsuite/g++.dg/plugin/decl_plugin.c (revision 0)
83
+/* A plugin example that shows which declarations are caught by FINISH_DECL */
85
+#include "gcc-plugin.h"
89
+#include "coretypes.h"
91
+#include "tree-pass.h"
94
+int plugin_is_GPL_compatible;
96
+/* Callback function to invoke after GCC finishes a declaration. */
98
+void plugin_finish_decl (void *event_data, void *data)
100
+ tree decl = (tree) event_data;
102
+ const char *kind = NULL;
103
+ switch (TREE_CODE(decl)) {
104
+ case FUNCTION_DECL:
105
+ kind = "Function"; break;
107
+ kind = "Parameter"; break;
109
+ if (DECL_CONTEXT(decl) != NULL)
115
+ kind = "Field"; break;
120
+ warning (0, G_("Decl %s %s"),
121
+ kind, IDENTIFIER_POINTER (DECL_NAME (decl)));
125
+plugin_init (struct plugin_name_args *plugin_info,
126
+ struct plugin_gcc_version *version)
128
+ const char *plugin_name = plugin_info->base_name;
130
+ register_callback (plugin_name, PLUGIN_FINISH_DECL,
131
+ plugin_finish_decl, NULL);
135
===================================================================
136
--- gcc/cp/decl.c (revision 162126)
137
+++ gcc/cp/decl.c (working copy)
138
@@ -5967,6 +5967,8 @@
139
/* If this was marked 'used', be sure it will be output. */
140
if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
141
mark_decl_referenced (decl);
143
+ invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
146
/* Returns a declaration for a VAR_DECL as if:
148
===================================================================
149
--- gcc/c-decl.c (revision 162126)
150
+++ gcc/c-decl.c (working copy)
151
@@ -4392,6 +4392,8 @@
152
&& DECL_INITIAL (decl) == NULL_TREE)
153
warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
154
"uninitialized const %qD is invalid in C++", decl);
156
+ invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
159
/* Given a parsed parameter declaration, decode it into a PARM_DECL. */
161
===================================================================
162
--- gcc/plugin.c (revision 162126)
163
+++ gcc/plugin.c (working copy)
167
case PLUGIN_FINISH_TYPE:
168
+ case PLUGIN_FINISH_DECL:
169
case PLUGIN_START_UNIT:
170
case PLUGIN_FINISH_UNIT:
171
case PLUGIN_PRE_GENERICIZE:
173
gcc_assert (event < event_last);
175
case PLUGIN_FINISH_TYPE:
176
+ case PLUGIN_FINISH_DECL:
177
case PLUGIN_START_UNIT:
178
case PLUGIN_FINISH_UNIT:
179
case PLUGIN_PRE_GENERICIZE: