diff options
author | Jakub Jelinek <jakub@redhat.com> | 2012-03-06 16:39:52 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2012-03-06 16:39:52 +0000 |
commit | cf38adcec31776cb118f90bffbbc55f4924cfc16 (patch) | |
tree | 11a1e10242dd9339ff26cf73a1718106f3a27911 | |
parent | 9e0d1304ec7979253fc31b39a87c90511eae4aba (diff) |
svn merge -r177855:177856 svn+ssh://gcc.gnu.org/svn/gcc/trunk
svn merge -r177673:177674 svn+ssh://gcc.gnu.org/svn/gcc/trunk
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/redhat/gcc-4_6-branch@185002 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/c-decl.c | 2 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/decl.c | 2 | ||||
-rw-r--r-- | gcc/doc/plugins.texi | 1 | ||||
-rw-r--r-- | gcc/plugin.c | 2 | ||||
-rw-r--r-- | gcc/plugin.def | 3 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/plugin/decl-plugin-test.C | 30 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/plugin/decl_plugin.c | 52 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/plugin/plugin.exp | 3 |
11 files changed, 118 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4cabc79b8f9..a96d14fbee9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2011-08-11 Romain Geissler <romain.geissler@gmail.com> + Brian Hackett <bhackett1024@gmail.com> + + * plugin.def: Add event for finish_decl. + * plugin.c (register_callback, invoke_plugin_callbacks): Same. + * c-decl.c (finish_decl): Invoke callbacks on above event. + * doc/plugins.texi: Document above event. + 2012-02-11 Jakub Jelinek <jakub@redhat.com> PR debug/52132 diff --git a/gcc/c-decl.c b/gcc/c-decl.c index 44c0ec7728e..52a10cdcb4f 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -4477,6 +4477,8 @@ finish_decl (tree decl, location_t init_loc, tree init, && C_TYPE_FIELDS_READONLY (type)) diagnose_uninitialized_cst_member (decl, type); } + + invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl); } /* Given a parsed parameter declaration, decode it into a PARM_DECL. */ diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 46297ad92a2..bc78d0bb1df 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2011-08-11 Romain Geissler <romain.geissler@gmail.com> + Brian Hackett <bhackett1024@gmail.com> + + * decl.c (cp_finish_decl): Invoke callbacks on finish_decl event. + 2012-03-01 Release Manager * GCC 4.6.3 released. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 6b6f158491e..833e442f2ea 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6162,6 +6162,8 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (was_readonly) TREE_READONLY (decl) = 1; + + invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl); } /* Returns a declaration for a VAR_DECL as if: diff --git a/gcc/doc/plugins.texi b/gcc/doc/plugins.texi index 767cee8800c..0be44ad9ddf 100644 --- a/gcc/doc/plugins.texi +++ b/gcc/doc/plugins.texi @@ -151,6 +151,7 @@ enum plugin_event @{ PLUGIN_PASS_MANAGER_SETUP, /* To hook into pass manager. */ PLUGIN_FINISH_TYPE, /* After finishing parsing a type. */ + PLUGIN_FINISH_DECL, /* After finishing parsing a declaration. */ PLUGIN_FINISH_UNIT, /* Useful for summary processing. */ PLUGIN_PRE_GENERICIZE, /* Allows to see low level AST in C and C++ frontends. */ PLUGIN_FINISH, /* Called before GCC exits. */ diff --git a/gcc/plugin.c b/gcc/plugin.c index c93daed055d..3906bffc68b 100644 --- a/gcc/plugin.c +++ b/gcc/plugin.c @@ -420,6 +420,7 @@ register_callback (const char *plugin_name, } /* Fall through. */ case PLUGIN_FINISH_TYPE: + case PLUGIN_FINISH_DECL: case PLUGIN_START_UNIT: case PLUGIN_FINISH_UNIT: case PLUGIN_PRE_GENERICIZE: @@ -496,6 +497,7 @@ invoke_plugin_callbacks_full (int event, void *gcc_data) gcc_assert (event < event_last); /* Fall through. */ case PLUGIN_FINISH_TYPE: + case PLUGIN_FINISH_DECL: case PLUGIN_START_UNIT: case PLUGIN_FINISH_UNIT: case PLUGIN_PRE_GENERICIZE: diff --git a/gcc/plugin.def b/gcc/plugin.def index 4a40c2cf79e..0c9c8bc76f5 100644 --- a/gcc/plugin.def +++ b/gcc/plugin.def @@ -24,6 +24,9 @@ DEFEVENT (PLUGIN_PASS_MANAGER_SETUP) /* After finishing parsing a type. */ DEFEVENT (PLUGIN_FINISH_TYPE) +/* After finishing parsing a declaration. */ +DEFEVENT (PLUGIN_FINISH_DECL) + /* Useful for summary processing. */ DEFEVENT (PLUGIN_FINISH_UNIT) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6a7ae2caf6c..575dae2a7c1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2011-08-18 Jakub Jelinek <jakub@redhat.com> + + * g++.dg/plugin/decl_plugin.c: Include diagnostic.h. + +2011-08-11 Romain Geissler <romain.geissler@gmail.com> + Brian Hackett <bhackett1024@gmail.com> + + * g++.dg/plugin/decl_plugin.c: New. + * g++.dg/plugin/decl-plugin-test.C: New. + * g++.dg/plugin/plugin.exp: Add above testcase. + 2012-02-11 Jakub Jelinek <jakub@redhat.com> PR debug/52132 diff --git a/gcc/testsuite/g++.dg/plugin/decl-plugin-test.C b/gcc/testsuite/g++.dg/plugin/decl-plugin-test.C new file mode 100644 index 00000000000..08a2ff2aa5d --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/decl-plugin-test.C @@ -0,0 +1,30 @@ +extern int global; // { dg-warning "Decl Global global" } +int global_array[] = { 1, 2, 3 }; // { dg-warning "Decl Global global_array" } + +int takes_args(int arg1, int arg2) +{ + int local = arg1 + arg2 + global; // { dg-warning "Decl Local local" } + return local + 1; +} + +int global = 12; // { dg-warning "Decl Global global" } + +struct test_str { + int field; // { dg-warning "Decl Field field" } +}; + +class test_class { + int class_field1; // { dg-warning "Decl Field class_field1" } + int class_field2; // { dg-warning "Decl Field class_field2" } + + test_class() // { dg-warning "Decl Function test_class" } + : class_field1(0), class_field2(0) + {} + + void swap_fields(int bias) // { dg-warning "Decl Function swap_fields" } + { + int temp = class_field1 + bias; // { dg-warning "Decl Local temp" } + class_field1 = class_field2 - bias; + class_field2 = temp; + } +}; diff --git a/gcc/testsuite/g++.dg/plugin/decl_plugin.c b/gcc/testsuite/g++.dg/plugin/decl_plugin.c new file mode 100644 index 00000000000..d44c8f9d469 --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/decl_plugin.c @@ -0,0 +1,52 @@ +/* A plugin example that shows which declarations are caught by FINISH_DECL */ + +#include "gcc-plugin.h" +#include <stdlib.h> +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tree.h" +#include "tree-pass.h" +#include "intl.h" +#include "diagnostic.h" + +int plugin_is_GPL_compatible; + +/* Callback function to invoke after GCC finishes a declaration. */ + +void plugin_finish_decl (void *event_data, void *data) +{ + tree decl = (tree) event_data; + + const char *kind = NULL; + switch (TREE_CODE(decl)) { + case FUNCTION_DECL: + kind = "Function"; break; + case PARM_DECL: + kind = "Parameter"; break; + case VAR_DECL: + if (DECL_FILE_SCOPE_P(decl)) + kind = "Global"; + else + kind = "Local"; + break; + case FIELD_DECL: + kind = "Field"; break; + default: + kind = "Unknown"; + } + + warning (0, G_("Decl %s %s"), + kind, IDENTIFIER_POINTER (DECL_NAME (decl))); +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + const char *plugin_name = plugin_info->base_name; + + register_callback (plugin_name, PLUGIN_FINISH_DECL, + plugin_finish_decl, NULL); + return 0; +} diff --git a/gcc/testsuite/g++.dg/plugin/plugin.exp b/gcc/testsuite/g++.dg/plugin/plugin.exp index 72de92dfd42..fb962dfdead 100644 --- a/gcc/testsuite/g++.dg/plugin/plugin.exp +++ b/gcc/testsuite/g++.dg/plugin/plugin.exp @@ -51,7 +51,8 @@ set plugin_test_list [list \ { pragma_plugin.c pragma_plugin-test-1.C } \ { selfassign.c self-assign-test-1.C self-assign-test-2.C self-assign-test-3.C } \ { dumb_plugin.c dumb-plugin-test-1.C } \ - { header_plugin.c header-plugin-test.C } ] + { header_plugin.c header-plugin-test.C } \ + { decl_plugin.c decl-plugin-test.C } ] foreach plugin_test $plugin_test_list { # Replace each source file with its full-path name |