public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: plugin event for C/C++ declarations
@ 2010-04-29 13:00 Dominique Dhumieres
  0 siblings, 0 replies; 42+ messages in thread
From: Dominique Dhumieres @ 2010-04-29 13:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: bhackett1024


This is likely the cause of pr43935.

Dominique

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2011-08-11 13:37             ` Romain Geissler
@ 2011-08-11 17:11               ` Diego Novillo
  0 siblings, 0 replies; 42+ messages in thread
From: Diego Novillo @ 2011-08-11 17:11 UTC (permalink / raw)
  To: Romain Geissler; +Cc: Romain Geissler, gcc-patches, bhackett1024

On Thu, Aug 11, 2011 at 08:59, Romain Geissler <romain.geissler@st.com> wrote:

> Find attached the updated patch. Retested for regression on x86_64.

Thanks.  Committed at rev 177674.


Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2011-08-10 15:59           ` Diego Novillo
@ 2011-08-11 13:37             ` Romain Geissler
  2011-08-11 17:11               ` Diego Novillo
  0 siblings, 1 reply; 42+ messages in thread
From: Romain Geissler @ 2011-08-11 13:37 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Romain Geissler, gcc-patches, bhackett1024

[-- Attachment #1: Type: text/plain, Size: 481 bytes --]

On 08/10/2011 05:20 PM, Diego Novillo wrote:
> On Mon, Aug 8, 2011 at 07:39, Romain Geissler<romain.geissler@gmail.com>  wrote:
>> 2011/7/20 Diego Novillo<dnovillo@google.com>:
>>> On Mon, Jul 18, 2011 at 03:06, Romain Geissler
>>> I will commit this patch shortly.
>>>
>>>
>>> Diego.
>>>
>>
>> Ping !
>
> Romain, please send me a current patch against today's trunk.
>
>
> Thanks.  Diego.

Hi

Find attached the updated patch. Retested for regression on x86_64.

Romain Geissler.

[-- Attachment #2: plugin_decl2.diff --]
[-- Type: text/plain, Size: 5977 bytes --]

Index: gcc/doc/plugins.texi
===================================================================
--- gcc/doc/plugins.texi	(revision 177557)
+++ gcc/doc/plugins.texi	(working copy)
@@ -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.  */
Index: gcc/plugin.def
===================================================================
--- gcc/plugin.def	(revision 177557)
+++ gcc/plugin.def	(working copy)
@@ -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)
 
Index: gcc/testsuite/g++.dg/plugin/plugin.exp
===================================================================
--- gcc/testsuite/g++.dg/plugin/plugin.exp	(revision 177557)
+++ gcc/testsuite/g++.dg/plugin/plugin.exp	(working copy)
@@ -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
Index: gcc/testsuite/g++.dg/plugin/decl-plugin-test.C
===================================================================
--- gcc/testsuite/g++.dg/plugin/decl-plugin-test.C	(revision 0)
+++ gcc/testsuite/g++.dg/plugin/decl-plugin-test.C	(revision 0)
@@ -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;
+  }
+};
Index: gcc/testsuite/g++.dg/plugin/decl_plugin.c
===================================================================
--- gcc/testsuite/g++.dg/plugin/decl_plugin.c	(revision 0)
+++ gcc/testsuite/g++.dg/plugin/decl_plugin.c	(revision 0)
@@ -0,0 +1,51 @@
+/* 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"
+
+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;
+}
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 177557)
+++ gcc/cp/decl.c	(working copy)
@@ -6311,6 +6311,8 @@ cp_finish_decl (tree decl, tree init, bo
 
   if (was_readonly)
     TREE_READONLY (decl) = 1;
+
+  invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
 }
 
 /* Returns a declaration for a VAR_DECL as if:
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revision 177557)
+++ gcc/c-decl.c	(working copy)
@@ -4466,6 +4466,8 @@ finish_decl (tree decl, location_t 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.
Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c	(revision 177557)
+++ gcc/plugin.c	(working copy)
@@ -420,6 +420,7 @@ register_callback (const char *plugin_na
 	  }
       /* 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,
 	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:

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2011-08-08 12:13         ` Romain Geissler
@ 2011-08-10 15:59           ` Diego Novillo
  2011-08-11 13:37             ` Romain Geissler
  0 siblings, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2011-08-10 15:59 UTC (permalink / raw)
  To: Romain Geissler; +Cc: gcc-patches, bhackett1024

On Mon, Aug 8, 2011 at 07:39, Romain Geissler <romain.geissler@gmail.com> wrote:
> 2011/7/20 Diego Novillo <dnovillo@google.com>:
>> On Mon, Jul 18, 2011 at 03:06, Romain Geissler
>> I will commit this patch shortly.
>>
>>
>> Diego.
>>
>
> Ping !

Romain, please send me a current patch against today's trunk.


Thanks.  Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2011-07-20 12:37       ` Diego Novillo
@ 2011-08-08 12:13         ` Romain Geissler
  2011-08-10 15:59           ` Diego Novillo
  0 siblings, 1 reply; 42+ messages in thread
From: Romain Geissler @ 2011-08-08 12:13 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches, bhackett1024

2011/7/20 Diego Novillo <dnovillo@google.com>:
> On Mon, Jul 18, 2011 at 03:06, Romain Geissler
> I will commit this patch shortly.
>
>
> Diego.
>

Ping !

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2011-07-18  9:28     ` Romain Geissler
@ 2011-07-20 12:37       ` Diego Novillo
  2011-08-08 12:13         ` Romain Geissler
  0 siblings, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2011-07-20 12:37 UTC (permalink / raw)
  To: Romain Geissler; +Cc: gcc-patches, bhackett1024

On Mon, Jul 18, 2011 at 03:06, Romain Geissler
<romain.geissler@gmail.com> wrote:
> 2011/7/11 Romain Geissler <romain.geissler@gmail.com>:
>> 2011/7/7 Diego Novillo <dnovillo@google.com>:
>>> OK.  This one fell through the cracks in my inbox.  Apologies.
>>>
>>>
>>> Diego.
>>
>> Hi,
>>
>> I don't have write access, can you please add the patch to the trunk ?
>>
>> Romain Geissler
>
> Ping !

I will commit this patch shortly.


Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2011-07-11  8:21   ` Romain Geissler
@ 2011-07-18  9:28     ` Romain Geissler
  2011-07-20 12:37       ` Diego Novillo
  0 siblings, 1 reply; 42+ messages in thread
From: Romain Geissler @ 2011-07-18  9:28 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches, bhackett1024

2011/7/11 Romain Geissler <romain.geissler@gmail.com>:
> 2011/7/7 Diego Novillo <dnovillo@google.com>:
>> OK.  This one fell through the cracks in my inbox.  Apologies.
>>
>>
>> Diego.
>
> Hi,
>
> I don't have write access, can you please add the patch to the trunk ?
>
> Romain Geissler

Ping !

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2011-07-07 12:19 ` Diego Novillo
@ 2011-07-11  8:21   ` Romain Geissler
  2011-07-18  9:28     ` Romain Geissler
  0 siblings, 1 reply; 42+ messages in thread
From: Romain Geissler @ 2011-07-11  8:21 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches, bhackett1024

2011/7/7 Diego Novillo <dnovillo@google.com>:
> OK.  This one fell through the cracks in my inbox.  Apologies.
>
>
> Diego.

Hi,

I don't have write access, can you please add the patch to the trunk ?

Romain Geissler

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2011-07-07  9:09 Romain Geissler
@ 2011-07-07 12:19 ` Diego Novillo
  2011-07-11  8:21   ` Romain Geissler
  0 siblings, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2011-07-07 12:19 UTC (permalink / raw)
  To: Romain Geissler; +Cc: gcc-patches, bhackett1024

On 11-07-07 05:06 , Romain Geissler wrote:

> gcc/ChangeLog:
>
>         * 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.
>
> gcc/cp/ChangeLog:
>
>         * decl.c (cp_finish_decl): Invoke callbacks on finish_decl event.
>
> gcc/testsuite/ChangeLog:
>
>         * g++.dg/plugin/decl_plugin.c: New test plugin.
>         * g++.dg/plugin/decl-plugin-test.C: Testcase for above plugin.
>         * g++.dg/plugin/plugin.exp: Add above testcase.

OK.  This one fell through the cracks in my inbox.  Apologies.


Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
@ 2011-07-07  9:09 Romain Geissler
  2011-07-07 12:19 ` Diego Novillo
  0 siblings, 1 reply; 42+ messages in thread
From: Romain Geissler @ 2011-07-07  9:09 UTC (permalink / raw)
  To: gcc-patches; +Cc: bhackett1024

> On Tue, Dec 22, 2009 at 11:45 AM, Diego Novillo <dnovillo@google.com> wrote:
>> On Tue, Dec 22, 2009 at 13:00, Brian Hackett <bhackett1024@gmail.com> wrote:
>>> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
>>> at every finish_decl in the C and C++ frontends. ?Previously there did
>>> not seem to be a way for a plugin to see the definition for a global
>>> that is never used in the input file, or the initializer for a global
>>> which is declared before a function but defined after. ?This event
>>> isn't restricted to just globals though, but also locals, fields, and
>>> parameters (C frontend only).
>>
>> Thanks for your patch. ?This will be great to fix
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41757 but we need to wait
>> for your copyright assignment to go through before we can accept it.
>
> Hi, this is a patch from a few months ago which I was not able to get
> an assignment for.  The FSF has a personal copyright assignment for
> me, but I could not get one from my employer at the time, Stanford
> (according to Stanford's policies they would not claim copyright on
> this patch).  I now work for Mozilla, which (I understand) has a
> company wide copyright assignment.  Are there issues if I from scratch
> rewrite and resubmit a new patch?
>
> Original patch (9 new lines of code, doc change and new regression):
>
> http://gcc.gnu.org/ml/gcc-patches/2009-12/msg01032.html
>
> Brian

Hi,

Once again, this is a ping for the long time proposed patch by Brian Hackett.
See last thread about this one here:
http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00315.html

Find below the fixed patch for recent revision (changed
gcc/testsuite/g++.dg/plugin/decl_plugin.c global and local var
decl detection)

Romain Geissler

2011-07-07  Romain Geissler  <romain.geissler@gmail.com>
2010-04-14  Brian Hackett  <bhackett1024@gmail.com>

gcc/ChangeLog:

       * 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.

gcc/cp/ChangeLog:

       * decl.c (cp_finish_decl): Invoke callbacks on finish_decl event.

gcc/testsuite/ChangeLog:

       * g++.dg/plugin/decl_plugin.c: New test plugin.
       * g++.dg/plugin/decl-plugin-test.C: Testcase for above plugin.
       * g++.dg/plugin/plugin.exp: Add above testcase.


Index: gcc/doc/plugins.texi
===================================================================
--- gcc/doc/plugins.texi        (revision 175907)
+++ gcc/doc/plugins.texi        (working copy)
@@ -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.  */
Index: gcc/plugin.def
===================================================================
--- gcc/plugin.def      (revision 175907)
+++ gcc/plugin.def      (working copy)
@@ -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)

Index: gcc/testsuite/g++.dg/plugin/plugin.exp
===================================================================
--- gcc/testsuite/g++.dg/plugin/plugin.exp      (revision 175907)
+++ gcc/testsuite/g++.dg/plugin/plugin.exp      (working copy)
@@ -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
Index: gcc/testsuite/g++.dg/plugin/decl-plugin-test.C
===================================================================
--- gcc/testsuite/g++.dg/plugin/decl-plugin-test.C      (revision 0)
+++ gcc/testsuite/g++.dg/plugin/decl-plugin-test.C      (revision 0)
@@ -0,0 +1,32 @@
+
+
+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;
+  }
+};
Index: gcc/testsuite/g++.dg/plugin/decl_plugin.c
===================================================================
--- gcc/testsuite/g++.dg/plugin/decl_plugin.c   (revision 0)
+++ gcc/testsuite/g++.dg/plugin/decl_plugin.c   (revision 0)
@@ -0,0 +1,51 @@
+/* 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"
+
+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;
+}
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c       (revision 175907)
+++ gcc/cp/decl.c       (working copy)
@@ -6298,6 +6298,8 @@ cp_finish_decl (tree decl, tree init, bo

   if (was_readonly)
     TREE_READONLY (decl) = 1;
+
+  invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
 }

 /* Returns a declaration for a VAR_DECL as if:
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c        (revision 175907)
+++ gcc/c-decl.c        (working copy)
@@ -4464,6 +4464,8 @@ finish_decl (tree decl, location_t 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.
Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c        (revision 175907)
+++ gcc/plugin.c        (working copy)
@@ -420,6 +420,7 @@ register_callback (const char *plugin_na
          }
       /* 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,
        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:

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-29 14:04                                         ` H.J. Lu
@ 2010-04-29 14:37                                           ` Brian Hackett
  0 siblings, 0 replies; 42+ messages in thread
From: Brian Hackett @ 2010-04-29 14:37 UTC (permalink / raw)
  To: H.J. Lu
  Cc: Diego Novillo, Richard Guenther, Richard Guenther, gcc-patches,
	Jakub Jelinek

On Thu, Apr 29, 2010 at 7:00 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, Apr 29, 2010 at 6:53 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>> I tested 'make bootstrap' on two different platforms and it worked.
>
> What are your configure options?
>

I didn't pass any options to './configure'.  Is there a file you need?

Brian

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-29 14:03                                       ` Brian Hackett
@ 2010-04-29 14:04                                         ` H.J. Lu
  2010-04-29 14:37                                           ` Brian Hackett
  0 siblings, 1 reply; 42+ messages in thread
From: H.J. Lu @ 2010-04-29 14:04 UTC (permalink / raw)
  To: Brian Hackett
  Cc: Diego Novillo, Richard Guenther, Richard Guenther, gcc-patches,
	Jakub Jelinek

On Thu, Apr 29, 2010 at 6:53 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
> I tested 'make bootstrap' on two different platforms and it worked.

What are your configure options?

> What can be causing the checksums to differ?

It is just warning:

warning: gcc/cc1obj-checksum.o differs
warning: gcc/cc1plus-checksum.o differs
warning: gcc/cc1-checksum.o differs

The error is

Bootstrap comparison failure!
gcc/ggc-common.o differs
gcc/tree-optimize.o differs
gcc/ggc-page.o differs
gcc/c-pragma.o differs
gcc/c-decl.o differs
gcc/cgraphunit.o differs


H.J.
--
> Brian
>
> On Thu, Apr 29, 2010 at 6:00 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>
>> This caused:
>>
>> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43936
>>
>> --
>> H.J.
>>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-29 13:22                                     ` H.J. Lu
@ 2010-04-29 14:03                                       ` Brian Hackett
  2010-04-29 14:04                                         ` H.J. Lu
  0 siblings, 1 reply; 42+ messages in thread
From: Brian Hackett @ 2010-04-29 14:03 UTC (permalink / raw)
  To: H.J. Lu
  Cc: Diego Novillo, Richard Guenther, Richard Guenther, gcc-patches,
	Jakub Jelinek

I tested 'make bootstrap' on two different platforms and it worked.
What can be causing the checksums to differ?

Brian

On Thu, Apr 29, 2010 at 6:00 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>
> This caused:
>
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43936
>
> --
> H.J.
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-29  2:24                                   ` Brian Hackett
  2010-04-29 10:02                                     ` Richard Guenther
@ 2010-04-29 13:22                                     ` H.J. Lu
  2010-04-29 14:03                                       ` Brian Hackett
  1 sibling, 1 reply; 42+ messages in thread
From: H.J. Lu @ 2010-04-29 13:22 UTC (permalink / raw)
  To: Brian Hackett
  Cc: Diego Novillo, Richard Guenther, Richard Guenther, gcc-patches,
	Jakub Jelinek

On Wed, Apr 28, 2010 at 5:48 PM, Brian Hackett <bhackett1024@gmail.com> wrote:
> On Wed, Apr 28, 2010 at 5:46 AM, Diego Novillo <dnovillo@google.com> wrote:
>> On 4/27/10 15:43 , Brian Hackett wrote:
>>
>>> Hmm, I don't see a way for this to avoid using a global variable,
>>
>> I wanted to avoid introducing a *new* one actually.  But I had forgotten
>> that we don't already have one for -fplugin.
>>
>>> there's no state saved for whether a plugin has been added that is not
>>> internal to plugin.c.  The patch below (seems to build, need to test
>>> regr) adds a flag_plugin_added; alternatively plugin_name_args_tab
>>> could be extern'ed in plugin.h but there's no reason for anything
>>> outside plugin.c to access this structure's internals.
>>
>> OK with the changes Richard suggested for the ChangeLog entry and:
>>
>>
>>> +/* True iff at least one plugin has been added. */
>>> +extern bool flag_plugin_added;
>>
>> Move the declaration inside invoke_plugin_callbacks?  This will at least
>> prevent other functions outside plugin.c from trying to access it.
>>
>>
>> Diego.
>>
>
> Hi, here is an updated patch incorporating this change.  For this
> patch 'make bootstrap' works for me on x86_64 linux (plugin support)
> and x86_64 darwin (no plugin support), and the plugin regressions
> pass.
>
> Brian
>
> gcc/ChangeLog:   Brian Hackett   <bhackett1024@gmail.com>
>
>        * plugin.h (invoke_plugin_callbacks): New inline function.
>        * plugin.c (flag_plugin_added): New global flag.
>        (add_new_plugin): Initialize above flag.
>        (invoke_plugin_callbacks): Rename to ...
>        (invoke_plugin_callbacks_full): ... this.
>

This caused:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43936

-- 
H.J.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-29  2:24                                   ` Brian Hackett
@ 2010-04-29 10:02                                     ` Richard Guenther
  2010-04-29 13:22                                     ` H.J. Lu
  1 sibling, 0 replies; 42+ messages in thread
From: Richard Guenther @ 2010-04-29 10:02 UTC (permalink / raw)
  To: Brian Hackett; +Cc: Diego Novillo, Richard Guenther, gcc-patches, Jakub Jelinek

[-- Attachment #1: Type: TEXT/PLAIN, Size: 5130 bytes --]

On Wed, 28 Apr 2010, Brian Hackett wrote:

> On Wed, Apr 28, 2010 at 5:46 AM, Diego Novillo <dnovillo@google.com> wrote:
> > On 4/27/10 15:43 , Brian Hackett wrote:
> >
> >> Hmm, I don't see a way for this to avoid using a global variable,
> >
> > I wanted to avoid introducing a *new* one actually.  But I had forgotten
> > that we don't already have one for -fplugin.
> >
> >> there's no state saved for whether a plugin has been added that is not
> >> internal to plugin.c.  The patch below (seems to build, need to test
> >> regr) adds a flag_plugin_added; alternatively plugin_name_args_tab
> >> could be extern'ed in plugin.h but there's no reason for anything
> >> outside plugin.c to access this structure's internals.
> >
> > OK with the changes Richard suggested for the ChangeLog entry and:
> >
> >
> >> +/* True iff at least one plugin has been added. */
> >> +extern bool flag_plugin_added;
> >
> > Move the declaration inside invoke_plugin_callbacks?  This will at least
> > prevent other functions outside plugin.c from trying to access it.
> >
> >
> > Diego.
> >
> 
> Hi, here is an updated patch incorporating this change.  For this
> patch 'make bootstrap' works for me on x86_64 linux (plugin support)
> and x86_64 darwin (no plugin support), and the plugin regressions
> pass.

Thanks.

I fixed minor formatting issues (two spaces after a '.' in a comment)
and committed it to trunk as rev. 158896.

Do you have a copyright assignment on file with the FSF?  If you
want to continue to contribute you should get one.

Thanks,
Richard.

> Brian
> 
> gcc/ChangeLog:   Brian Hackett   <bhackett1024@gmail.com>
> 
> 	* plugin.h (invoke_plugin_callbacks): New inline function.
> 	* plugin.c (flag_plugin_added): New global flag.
> 	(add_new_plugin): Initialize above flag.
> 	(invoke_plugin_callbacks): Rename to ...
> 	(invoke_plugin_callbacks_full): ... this.
> 
> Index: gcc/plugin.c
> ===================================================================
> --- gcc/plugin.c	(revision 158822)
> +++ gcc/plugin.c	(working copy)
> @@ -86,6 +86,8 @@ struct callback_info
>  static struct callback_info *plugin_callbacks_init[PLUGIN_EVENT_FIRST_DYNAMIC];
>  static struct callback_info **plugin_callbacks = plugin_callbacks_init;
> 
> +/* For invoke_plugin_callbacks(), see plugin.h */
> +bool flag_plugin_added = false;
> 
>  #ifdef ENABLE_PLUGIN
>  /* Each plugin should define an initialization function with exactly
> @@ -137,6 +139,8 @@ add_new_plugin (const char* plugin_name)
>    bool name_is_short;
>    const char *pc;
> 
> +  flag_plugin_added = true;
> +
>    /* Replace short names by their full path when relevant.  */
>    name_is_short  = !IS_ABSOLUTE_PATH (plugin_name);
>    for (pc = plugin_name; name_is_short && *pc; pc++)
> @@ -483,16 +487,11 @@ unregister_callback (const char *plugin_
>    return PLUGEVT_NO_CALLBACK;
>  }
> 
> -/* Called from inside GCC.  Invoke all plug-in callbacks registered with
> -   the specified event.
> -   Return PLUGEVT_SUCCESS if at least one callback was called,
> -   PLUGEVT_NO_CALLBACK if there was no callback.
> -
> -   EVENT    - the event identifier
> -   GCC_DATA - event-specific data provided by the compiler  */
> +/* Invoke all plugin callbacks registered with the specified event,
> +   called from invoke_plugin_callbacks(). */
> 
>  int
> -invoke_plugin_callbacks (int event, void *gcc_data)
> +invoke_plugin_callbacks_full (int event, void *gcc_data)
>  {
>    int retval = PLUGEVT_SUCCESS;
> 
> Index: gcc/plugin.h
> ===================================================================
> --- gcc/plugin.h	(revision 158822)
> +++ gcc/plugin.h	(working copy)
> @@ -26,7 +26,7 @@ struct attribute_spec;
> 
>  extern void add_new_plugin (const char *);
>  extern void parse_plugin_arg_opt (const char *);
> -extern int invoke_plugin_callbacks (int, void *);
> +extern int invoke_plugin_callbacks_full (int, void *);
>  extern void initialize_plugins (void);
>  extern bool plugins_active_p (void);
>  extern void dump_active_plugins (FILE *);
> @@ -35,6 +35,30 @@ extern void print_plugins_versions (FILE
>  extern void print_plugins_help (FILE *file, const char *indent);
>  extern void finalize_plugins (void);
> 
> +/* Called from inside GCC.  Invoke all plugin callbacks registered with
> +   the specified event.
> +   Return PLUGEVT_SUCCESS if at least one callback was called,
> +   PLUGEVT_NO_CALLBACK if there was no callback.
> +
> +   EVENT    - the event identifier
> +   GCC_DATA - event-specific data provided by the compiler  */
> +
> +static inline int
> +invoke_plugin_callbacks (int event, void *gcc_data)
> +{
> +#ifdef ENABLE_PLUGIN
> +
> +  /* True iff at least one plugin has been added. */
> +  extern bool flag_plugin_added;
> +
> +  if (flag_plugin_added)
> +    return invoke_plugin_callbacks_full (event, gcc_data);
> +
> +#endif
> +
> +  return PLUGEVT_NO_CALLBACK;
> +}
> +
>  /* In attribs.c.  */
> 
>  extern void register_attribute (const struct attribute_spec *attr);
> 
> 

-- 
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-28 14:34                                 ` Diego Novillo
@ 2010-04-29  2:24                                   ` Brian Hackett
  2010-04-29 10:02                                     ` Richard Guenther
  2010-04-29 13:22                                     ` H.J. Lu
  0 siblings, 2 replies; 42+ messages in thread
From: Brian Hackett @ 2010-04-29  2:24 UTC (permalink / raw)
  To: Diego Novillo
  Cc: Richard Guenther, Richard Guenther, gcc-patches, Jakub Jelinek

On Wed, Apr 28, 2010 at 5:46 AM, Diego Novillo <dnovillo@google.com> wrote:
> On 4/27/10 15:43 , Brian Hackett wrote:
>
>> Hmm, I don't see a way for this to avoid using a global variable,
>
> I wanted to avoid introducing a *new* one actually.  But I had forgotten
> that we don't already have one for -fplugin.
>
>> there's no state saved for whether a plugin has been added that is not
>> internal to plugin.c.  The patch below (seems to build, need to test
>> regr) adds a flag_plugin_added; alternatively plugin_name_args_tab
>> could be extern'ed in plugin.h but there's no reason for anything
>> outside plugin.c to access this structure's internals.
>
> OK with the changes Richard suggested for the ChangeLog entry and:
>
>
>> +/* True iff at least one plugin has been added. */
>> +extern bool flag_plugin_added;
>
> Move the declaration inside invoke_plugin_callbacks?  This will at least
> prevent other functions outside plugin.c from trying to access it.
>
>
> Diego.
>

Hi, here is an updated patch incorporating this change.  For this
patch 'make bootstrap' works for me on x86_64 linux (plugin support)
and x86_64 darwin (no plugin support), and the plugin regressions
pass.

Brian

gcc/ChangeLog:   Brian Hackett   <bhackett1024@gmail.com>

	* plugin.h (invoke_plugin_callbacks): New inline function.
	* plugin.c (flag_plugin_added): New global flag.
	(add_new_plugin): Initialize above flag.
	(invoke_plugin_callbacks): Rename to ...
	(invoke_plugin_callbacks_full): ... this.

Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c	(revision 158822)
+++ gcc/plugin.c	(working copy)
@@ -86,6 +86,8 @@ struct callback_info
 static struct callback_info *plugin_callbacks_init[PLUGIN_EVENT_FIRST_DYNAMIC];
 static struct callback_info **plugin_callbacks = plugin_callbacks_init;

+/* For invoke_plugin_callbacks(), see plugin.h */
+bool flag_plugin_added = false;

 #ifdef ENABLE_PLUGIN
 /* Each plugin should define an initialization function with exactly
@@ -137,6 +139,8 @@ add_new_plugin (const char* plugin_name)
   bool name_is_short;
   const char *pc;

+  flag_plugin_added = true;
+
   /* Replace short names by their full path when relevant.  */
   name_is_short  = !IS_ABSOLUTE_PATH (plugin_name);
   for (pc = plugin_name; name_is_short && *pc; pc++)
@@ -483,16 +487,11 @@ unregister_callback (const char *plugin_
   return PLUGEVT_NO_CALLBACK;
 }

-/* Called from inside GCC.  Invoke all plug-in callbacks registered with
-   the specified event.
-   Return PLUGEVT_SUCCESS if at least one callback was called,
-   PLUGEVT_NO_CALLBACK if there was no callback.
-
-   EVENT    - the event identifier
-   GCC_DATA - event-specific data provided by the compiler  */
+/* Invoke all plugin callbacks registered with the specified event,
+   called from invoke_plugin_callbacks(). */

 int
-invoke_plugin_callbacks (int event, void *gcc_data)
+invoke_plugin_callbacks_full (int event, void *gcc_data)
 {
   int retval = PLUGEVT_SUCCESS;

Index: gcc/plugin.h
===================================================================
--- gcc/plugin.h	(revision 158822)
+++ gcc/plugin.h	(working copy)
@@ -26,7 +26,7 @@ struct attribute_spec;

 extern void add_new_plugin (const char *);
 extern void parse_plugin_arg_opt (const char *);
-extern int invoke_plugin_callbacks (int, void *);
+extern int invoke_plugin_callbacks_full (int, void *);
 extern void initialize_plugins (void);
 extern bool plugins_active_p (void);
 extern void dump_active_plugins (FILE *);
@@ -35,6 +35,30 @@ extern void print_plugins_versions (FILE
 extern void print_plugins_help (FILE *file, const char *indent);
 extern void finalize_plugins (void);

+/* Called from inside GCC.  Invoke all plugin callbacks registered with
+   the specified event.
+   Return PLUGEVT_SUCCESS if at least one callback was called,
+   PLUGEVT_NO_CALLBACK if there was no callback.
+
+   EVENT    - the event identifier
+   GCC_DATA - event-specific data provided by the compiler  */
+
+static inline int
+invoke_plugin_callbacks (int event, void *gcc_data)
+{
+#ifdef ENABLE_PLUGIN
+
+  /* True iff at least one plugin has been added. */
+  extern bool flag_plugin_added;
+
+  if (flag_plugin_added)
+    return invoke_plugin_callbacks_full (event, gcc_data);
+
+#endif
+
+  return PLUGEVT_NO_CALLBACK;
+}
+
 /* In attribs.c.  */

 extern void register_attribute (const struct attribute_spec *attr);

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 20:15                               ` Brian Hackett
  2010-04-28 10:01                                 ` Richard Guenther
@ 2010-04-28 14:34                                 ` Diego Novillo
  2010-04-29  2:24                                   ` Brian Hackett
  1 sibling, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2010-04-28 14:34 UTC (permalink / raw)
  To: Brian Hackett
  Cc: Richard Guenther, Richard Guenther, gcc-patches, Jakub Jelinek

On 4/27/10 15:43 , Brian Hackett wrote:

> Hmm, I don't see a way for this to avoid using a global variable,

I wanted to avoid introducing a *new* one actually.  But I had forgotten
that we don't already have one for -fplugin.

> there's no state saved for whether a plugin has been added that is not
> internal to plugin.c.  The patch below (seems to build, need to test
> regr) adds a flag_plugin_added; alternatively plugin_name_args_tab
> could be extern'ed in plugin.h but there's no reason for anything
> outside plugin.c to access this structure's internals.

OK with the changes Richard suggested for the ChangeLog entry and:


> +/* True iff at least one plugin has been added. */
> +extern bool flag_plugin_added;

Move the declaration inside invoke_plugin_callbacks?  This will at least
prevent other functions outside plugin.c from trying to access it.


Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 20:15                               ` Brian Hackett
@ 2010-04-28 10:01                                 ` Richard Guenther
  2010-04-28 14:34                                 ` Diego Novillo
  1 sibling, 0 replies; 42+ messages in thread
From: Richard Guenther @ 2010-04-28 10:01 UTC (permalink / raw)
  To: Brian Hackett; +Cc: Diego Novillo, gcc-patches, Jakub Jelinek

[-- Attachment #1: Type: TEXT/PLAIN, Size: 4818 bytes --]

On Tue, 27 Apr 2010, Brian Hackett wrote:

> On Tue, Apr 27, 2010 at 9:03 AM, Richard Guenther <rguenther@suse.de> wrote:
> > On Tue, 27 Apr 2010, Diego Novillo wrote:
> >
> >> On 4/27/10 11:54 , Richard Guenther wrote:
> >>
> >> > Yes, preferably not as a function but a global variable directly.
> >>
> >> Ugh, please no more global variables.
> >
> > ;)  Works for me as well (it's slightly uncomfortable at -O0 ...)
> >
> > Richard.
> >
> 
> Hmm, I don't see a way for this to avoid using a global variable,
> there's no state saved for whether a plugin has been added that is not
> internal to plugin.c.  The patch below (seems to build, need to test
> regr) adds a flag_plugin_added; alternatively plugin_name_args_tab
> could be extern'ed in plugin.h but there's no reason for anything
> outside plugin.c to access this structure's internals.

The patch looks ok to me if it passes bootstrap & the plugin tests.
There are minor errors in the changelog entry,

> Brian
> 
> gcc/ChangeLog:   Brian Hackett   <bhackett1024@gmail.com>
> 
> 	* plugin.h: Change invoke_plugin_callbacks to be an inline wrapper.

        * plugin.h (invoke_plugin_callbacks): New inline function.
	(flag_plugin_added): Declare.

> Add flag_plugin_added for use by wrapper.
> 	* plugin.c: Define above flag.

	* plugin.c (flag_plugin_added): New global flag.

> 	* (add_new_plugin): Initialize above flag.

No '*' before '('

> 	* (invoke_plugin_callbacks): Rename to invoke_plugin_callbacks_full.

	(invoke_plugin_callbacks): Rename to ...
	(invoke_plugin_callbacks_full): ... this.

Thanks,
Richard.

> Index: gcc/plugin.c
> ===================================================================
> --- gcc/plugin.c	(revision 158789)
> +++ gcc/plugin.c	(working copy)
> @@ -86,6 +86,8 @@ struct callback_info
>  static struct callback_info *plugin_callbacks_init[PLUGIN_EVENT_FIRST_DYNAMIC];
>  static struct callback_info **plugin_callbacks = plugin_callbacks_init;
> 
> +/* For invoke_plugin_callbacks(), see plugin.h */
> +bool flag_plugin_added = false;
> 
>  #ifdef ENABLE_PLUGIN
>  /* Each plugin should define an initialization function with exactly
> @@ -137,6 +139,8 @@ add_new_plugin (const char* plugin_name)
>    bool name_is_short;
>    const char *pc;
> 
> +  flag_plugin_added = true;
> +
>    /* Replace short names by their full path when relevant.  */
>    name_is_short  = !IS_ABSOLUTE_PATH (plugin_name);
>    for (pc = plugin_name; name_is_short && *pc; pc++)
> @@ -483,16 +487,11 @@ unregister_callback (const char *plugin_
>    return PLUGEVT_NO_CALLBACK;
>  }
> 
> -/* Called from inside GCC.  Invoke all plug-in callbacks registered with
> -   the specified event.
> -   Return PLUGEVT_SUCCESS if at least one callback was called,
> -   PLUGEVT_NO_CALLBACK if there was no callback.
> -
> -   EVENT    - the event identifier
> -   GCC_DATA - event-specific data provided by the compiler  */
> +/* Invoke all plugin callbacks registered with the specified event,
> +   called from invoke_plugin_callbacks(). */
> 
>  int
> -invoke_plugin_callbacks (int event, void *gcc_data)
> +invoke_plugin_callbacks_full (int event, void *gcc_data)
>  {
>    int retval = PLUGEVT_SUCCESS;
> 
> Index: gcc/plugin.h
> ===================================================================
> --- gcc/plugin.h	(revision 158789)
> +++ gcc/plugin.h	(working copy)
> @@ -26,7 +26,7 @@ struct attribute_spec;
> 
>  extern void add_new_plugin (const char *);
>  extern void parse_plugin_arg_opt (const char *);
> -extern int invoke_plugin_callbacks (int, void *);
> +extern int invoke_plugin_callbacks_full (int, void *);
>  extern void initialize_plugins (void);
>  extern bool plugins_active_p (void);
>  extern void dump_active_plugins (FILE *);
> @@ -35,6 +35,27 @@ extern void print_plugins_versions (FILE
>  extern void print_plugins_help (FILE *file, const char *indent);
>  extern void finalize_plugins (void);
> 
> +/* True iff at least one plugin has been added. */
> +extern bool flag_plugin_added;
> +
> +/* Called from inside GCC.  Invoke all plugin callbacks registered with
> +   the specified event.
> +   Return PLUGEVT_SUCCESS if at least one callback was called,
> +   PLUGEVT_NO_CALLBACK if there was no callback.
> +
> +   EVENT    - the event identifier
> +   GCC_DATA - event-specific data provided by the compiler  */
> +
> +static inline int
> +invoke_plugin_callbacks (int event, void *gcc_data)
> +{
> +#ifdef ENABLE_PLUGIN
> +  if (flag_plugin_added)
> +    return invoke_plugin_callbacks_full (event, gcc_data);
> +#endif
> +  return PLUGEVT_NO_CALLBACK;
> +}
> +
>  /* In attribs.c.  */
> 
>  extern void register_attribute (const struct attribute_spec *attr);
> 
> 

-- 
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 17:16                             ` Richard Guenther
@ 2010-04-27 20:15                               ` Brian Hackett
  2010-04-28 10:01                                 ` Richard Guenther
  2010-04-28 14:34                                 ` Diego Novillo
  0 siblings, 2 replies; 42+ messages in thread
From: Brian Hackett @ 2010-04-27 20:15 UTC (permalink / raw)
  To: Richard Guenther
  Cc: Diego Novillo, Richard Guenther, gcc-patches, Jakub Jelinek

On Tue, Apr 27, 2010 at 9:03 AM, Richard Guenther <rguenther@suse.de> wrote:
> On Tue, 27 Apr 2010, Diego Novillo wrote:
>
>> On 4/27/10 11:54 , Richard Guenther wrote:
>>
>> > Yes, preferably not as a function but a global variable directly.
>>
>> Ugh, please no more global variables.
>
> ;)  Works for me as well (it's slightly uncomfortable at -O0 ...)
>
> Richard.
>

Hmm, I don't see a way for this to avoid using a global variable,
there's no state saved for whether a plugin has been added that is not
internal to plugin.c.  The patch below (seems to build, need to test
regr) adds a flag_plugin_added; alternatively plugin_name_args_tab
could be extern'ed in plugin.h but there's no reason for anything
outside plugin.c to access this structure's internals.

Brian

gcc/ChangeLog:   Brian Hackett   <bhackett1024@gmail.com>

	* plugin.h: Change invoke_plugin_callbacks to be an inline wrapper.
Add flag_plugin_added for use by wrapper.
	* plugin.c: Define above flag.
	* (add_new_plugin): Initialize above flag.
	* (invoke_plugin_callbacks): Rename to invoke_plugin_callbacks_full.

Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c	(revision 158789)
+++ gcc/plugin.c	(working copy)
@@ -86,6 +86,8 @@ struct callback_info
 static struct callback_info *plugin_callbacks_init[PLUGIN_EVENT_FIRST_DYNAMIC];
 static struct callback_info **plugin_callbacks = plugin_callbacks_init;

+/* For invoke_plugin_callbacks(), see plugin.h */
+bool flag_plugin_added = false;

 #ifdef ENABLE_PLUGIN
 /* Each plugin should define an initialization function with exactly
@@ -137,6 +139,8 @@ add_new_plugin (const char* plugin_name)
   bool name_is_short;
   const char *pc;

+  flag_plugin_added = true;
+
   /* Replace short names by their full path when relevant.  */
   name_is_short  = !IS_ABSOLUTE_PATH (plugin_name);
   for (pc = plugin_name; name_is_short && *pc; pc++)
@@ -483,16 +487,11 @@ unregister_callback (const char *plugin_
   return PLUGEVT_NO_CALLBACK;
 }

-/* Called from inside GCC.  Invoke all plug-in callbacks registered with
-   the specified event.
-   Return PLUGEVT_SUCCESS if at least one callback was called,
-   PLUGEVT_NO_CALLBACK if there was no callback.
-
-   EVENT    - the event identifier
-   GCC_DATA - event-specific data provided by the compiler  */
+/* Invoke all plugin callbacks registered with the specified event,
+   called from invoke_plugin_callbacks(). */

 int
-invoke_plugin_callbacks (int event, void *gcc_data)
+invoke_plugin_callbacks_full (int event, void *gcc_data)
 {
   int retval = PLUGEVT_SUCCESS;

Index: gcc/plugin.h
===================================================================
--- gcc/plugin.h	(revision 158789)
+++ gcc/plugin.h	(working copy)
@@ -26,7 +26,7 @@ struct attribute_spec;

 extern void add_new_plugin (const char *);
 extern void parse_plugin_arg_opt (const char *);
-extern int invoke_plugin_callbacks (int, void *);
+extern int invoke_plugin_callbacks_full (int, void *);
 extern void initialize_plugins (void);
 extern bool plugins_active_p (void);
 extern void dump_active_plugins (FILE *);
@@ -35,6 +35,27 @@ extern void print_plugins_versions (FILE
 extern void print_plugins_help (FILE *file, const char *indent);
 extern void finalize_plugins (void);

+/* True iff at least one plugin has been added. */
+extern bool flag_plugin_added;
+
+/* Called from inside GCC.  Invoke all plugin callbacks registered with
+   the specified event.
+   Return PLUGEVT_SUCCESS if at least one callback was called,
+   PLUGEVT_NO_CALLBACK if there was no callback.
+
+   EVENT    - the event identifier
+   GCC_DATA - event-specific data provided by the compiler  */
+
+static inline int
+invoke_plugin_callbacks (int event, void *gcc_data)
+{
+#ifdef ENABLE_PLUGIN
+  if (flag_plugin_added)
+    return invoke_plugin_callbacks_full (event, gcc_data);
+#endif
+  return PLUGEVT_NO_CALLBACK;
+}
+
 /* In attribs.c.  */

 extern void register_attribute (const struct attribute_spec *attr);

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 16:04                           ` Diego Novillo
@ 2010-04-27 17:16                             ` Richard Guenther
  2010-04-27 20:15                               ` Brian Hackett
  0 siblings, 1 reply; 42+ messages in thread
From: Richard Guenther @ 2010-04-27 17:16 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Brian Hackett, Richard Guenther, gcc-patches, Jakub Jelinek

On Tue, 27 Apr 2010, Diego Novillo wrote:

> On 4/27/10 11:54 , Richard Guenther wrote:
> 
> > Yes, preferably not as a function but a global variable directly.
> 
> Ugh, please no more global variables.

;)  Works for me as well (it's slightly uncomfortable at -O0 ...)

Richard.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 16:03                         ` Richard Guenther
@ 2010-04-27 16:04                           ` Diego Novillo
  2010-04-27 17:16                             ` Richard Guenther
  0 siblings, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2010-04-27 16:04 UTC (permalink / raw)
  To: Richard Guenther
  Cc: Brian Hackett, Richard Guenther, gcc-patches, Jakub Jelinek

On 4/27/10 11:54 , Richard Guenther wrote:

> Yes, preferably not as a function but a global variable directly.

Ugh, please no more global variables.

> static inline int invoke_plugin_callbacks(...)
> { if (plugin_enabled_p ()) return invoke_plugin_callbacks_1 (...);
>   else reuturn ???;
>  }

return PLUGEVT_NO_CALLBACK would be.  The return value is never checked,
currently.  We could just hide that in plugin.c


Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 16:00                       ` Diego Novillo
@ 2010-04-27 16:03                         ` Richard Guenther
  2010-04-27 16:04                           ` Diego Novillo
  0 siblings, 1 reply; 42+ messages in thread
From: Richard Guenther @ 2010-04-27 16:03 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Brian Hackett, Richard Guenther, gcc-patches, Jakub Jelinek

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1005 bytes --]

On Tue, 27 Apr 2010, Diego Novillo wrote:

> On Tue, Apr 27, 2010 at 11:46, Richard Guenther <rguenther@suse.de> wrote:
> > On Tue, 27 Apr 2010, Brian Hackett wrote:
> >
> >> I'll put together a patch using an inline function which checks a
> >> plugin_loaded_p.
> >
> > Thanks.  It should also be completely optimized out if
> > ENABLE_PLUGIN is not #defined.  I see it is currently not, ugh.
> 
> Good idea.  That would completely remove all plugin-related predicates
> from common code paths.
> 
> Just to be clear, you're thinking of this?
> 
> #if defined ENABLE_PLUGIN
> static inline bool plugin_enabled_p() { return flag_plugin<sp?>; }
> #else
> static inline bool plugin_enabled_p() { return false; }
> #endif

Yes, preferably not as a function but a global variable directly.

static inline int invoke_plugin_callbacks(...)
{ if (plugin_enabled_p ()) return invoke_plugin_callbacks_1 (...);
  else reuturn ???;
 }

plugin.c seems to use its internal plugin_name_args_tab as flag.

Richard.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 15:50                     ` Richard Guenther
@ 2010-04-27 16:00                       ` Diego Novillo
  2010-04-27 16:03                         ` Richard Guenther
  0 siblings, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2010-04-27 16:00 UTC (permalink / raw)
  To: Richard Guenther
  Cc: Brian Hackett, Richard Guenther, gcc-patches, Jakub Jelinek

On Tue, Apr 27, 2010 at 11:46, Richard Guenther <rguenther@suse.de> wrote:
> On Tue, 27 Apr 2010, Brian Hackett wrote:
>
>> I'll put together a patch using an inline function which checks a
>> plugin_loaded_p.
>
> Thanks.  It should also be completely optimized out if
> ENABLE_PLUGIN is not #defined.  I see it is currently not, ugh.

Good idea.  That would completely remove all plugin-related predicates
from common code paths.

Just to be clear, you're thinking of this?

#if defined ENABLE_PLUGIN
static inline bool plugin_enabled_p() { return flag_plugin<sp?>; }
#else
static inline bool plugin_enabled_p() { return false; }
#endif


Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 15:46                   ` Brian Hackett
@ 2010-04-27 15:50                     ` Richard Guenther
  2010-04-27 16:00                       ` Diego Novillo
  0 siblings, 1 reply; 42+ messages in thread
From: Richard Guenther @ 2010-04-27 15:50 UTC (permalink / raw)
  To: Brian Hackett; +Cc: Richard Guenther, Diego Novillo, gcc-patches, Jakub Jelinek

On Tue, 27 Apr 2010, Brian Hackett wrote:

> I'll put together a patch using an inline function which checks a
> plugin_loaded_p.

Thanks.  It should also be completely optimized out if
ENABLE_PLUGIN is not #defined.  I see it is currently not, ugh.

Richard.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 15:32                 ` Richard Guenther
@ 2010-04-27 15:46                   ` Brian Hackett
  2010-04-27 15:50                     ` Richard Guenther
  0 siblings, 1 reply; 42+ messages in thread
From: Brian Hackett @ 2010-04-27 15:46 UTC (permalink / raw)
  To: Richard Guenther
  Cc: Diego Novillo, gcc-patches, Richard Guenther, Jakub Jelinek

I'll put together a patch using an inline function which checks a
plugin_loaded_p.

Brian

On Tue, Apr 27, 2010 at 8:29 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> Thus, can we have -plugin binary-patch all call sites to NOPs
> by some fancy relocation like GNU_IFUNC?  Or at least please
> have a global variable plugin_loaded_p and wrap the callback
> in an inline function.
>
> Thanks.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 15:31               ` Richard Guenther
  2010-04-27 15:32                 ` Richard Guenther
@ 2010-04-27 15:45                 ` Diego Novillo
  1 sibling, 0 replies; 42+ messages in thread
From: Diego Novillo @ 2010-04-27 15:45 UTC (permalink / raw)
  To: Richard Guenther
  Cc: Brian Hackett, gcc-patches, Richard Guenther, Jakub Jelinek

On Tue, Apr 27, 2010 at 11:27, Richard Guenther
<richard.guenther@gmail.com> wrote:

> So I object plugin callbacks in such frequently called places until
> that issue is addressed.

Should be easy to address via an inline function checking for plugins.


Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 15:31               ` Richard Guenther
@ 2010-04-27 15:32                 ` Richard Guenther
  2010-04-27 15:46                   ` Brian Hackett
  2010-04-27 15:45                 ` Diego Novillo
  1 sibling, 1 reply; 42+ messages in thread
From: Richard Guenther @ 2010-04-27 15:32 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Brian Hackett, gcc-patches, Richard Guenther, Jakub Jelinek

On Tue, Apr 27, 2010 at 5:27 PM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Tue, Apr 27, 2010 at 5:23 PM, Diego Novillo <dnovillo@google.com> wrote:
>> On 4/27/10 10:39 , Brian Hackett wrote:
>>> Hi, can this patch be applied?  Also, is it possible for this change
>>> to make it into the 4.5 branch?
>>
>> I'm doing a final bootstrap today.  Richard/Jakub should decide whether
>> we can apply this in 4.5.
>
> No please.
>
>>> http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00780.html
>
> This adds a function call for _every_ decl, pushing/popping a timevar
> even if no plugins are loaded.  That's triple bad.
>
> So I object plugin callbacks in such frequently called places until
> that issue is addressed.

Thus, can we have -plugin binary-patch all call sites to NOPs
by some fancy relocation like GNU_IFUNC?  Or at least please
have a global variable plugin_loaded_p and wrap the callback
in an inline function.

Thanks.

> Richard.
>
>>
>> Diego.
>>
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 15:29             ` Diego Novillo
@ 2010-04-27 15:31               ` Richard Guenther
  2010-04-27 15:32                 ` Richard Guenther
  2010-04-27 15:45                 ` Diego Novillo
  0 siblings, 2 replies; 42+ messages in thread
From: Richard Guenther @ 2010-04-27 15:31 UTC (permalink / raw)
  To: Diego Novillo; +Cc: Brian Hackett, gcc-patches, Richard Guenther, Jakub Jelinek

On Tue, Apr 27, 2010 at 5:23 PM, Diego Novillo <dnovillo@google.com> wrote:
> On 4/27/10 10:39 , Brian Hackett wrote:
>> Hi, can this patch be applied?  Also, is it possible for this change
>> to make it into the 4.5 branch?
>
> I'm doing a final bootstrap today.  Richard/Jakub should decide whether
> we can apply this in 4.5.

No please.

>> http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00780.html

This adds a function call for _every_ decl, pushing/popping a timevar
even if no plugins are loaded.  That's triple bad.

So I object plugin callbacks in such frequently called places until
that issue is addressed.

Richard.

>
> Diego.
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-27 15:09           ` Brian Hackett
@ 2010-04-27 15:29             ` Diego Novillo
  2010-04-27 15:31               ` Richard Guenther
  0 siblings, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2010-04-27 15:29 UTC (permalink / raw)
  To: Brian Hackett; +Cc: gcc-patches, Richard Guenther, Jakub Jelinek

On 4/27/10 10:39 , Brian Hackett wrote:
> Hi, can this patch be applied?  Also, is it possible for this change
> to make it into the 4.5 branch?

I'm doing a final bootstrap today.  Richard/Jakub should decide whether
we can apply this in 4.5.

> http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00780.html


Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-14 14:15         ` Brian Hackett
@ 2010-04-27 15:09           ` Brian Hackett
  2010-04-27 15:29             ` Diego Novillo
  0 siblings, 1 reply; 42+ messages in thread
From: Brian Hackett @ 2010-04-27 15:09 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

Hi, can this patch be applied?  Also, is it possible for this change
to make it into the 4.5 branch?

Brian

http://gcc.gnu.org/ml/gcc-patches/2010-04/msg00780.html

On Wed, Apr 14, 2010 at 6:54 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
> On Mon, Apr 12, 2010 at 12:54 PM, Brian Hackett <bhackett1024@gmail.com> wrote:
>> Hi, I don't have write access.  I'll update the patch and rerun the
>> regressions for the current trunk (the patch below is a few months
>> old) and reply when that's done.
>>
>> Brian
>>
>> On Mon, Apr 12, 2010 at 12:39 PM, Diego Novillo <dnovillo@google.com> wrote:
>>> On Wed, Apr 7, 2010 at 14:30, Brian Hackett <bhackett1024@gmail.com> wrote:
>>>
>>>> http://gcc.gnu.org/ml/gcc-patches/2009-12/msg01032.html
>>>
>>> This is OK for trunk.  If you don't have write access let me know and
>>> I will help you applying the patch.
>>>
>>>
>>> Thanks.  Diego.
>
> OK, below is an updated patch against revision 158253.   I get the
> same regression results with and without this patch (modulo the new
> testcase).  Thanks,
>
> Brian
>
>
> 2010-04-14  Brian Hackett  <bhackett1024@gmail.com>
>
> gcc/ChangeLog:
>
>       * 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.
>
> gcc/cp/ChangeLog:
>
>       * decl.c (cp_finish_decl): Invoke callbacks on finish_decl event.
>
> gcc/testsuite/ChangeLog:
>
>       * g++.dg/plugin/decl_plugin.c: New test plugin.
>       * g++.dg/plugin/decl-plugin-test.C: Testcase for above plugin.
>       * g++.dg/plugin/plugin.exp: Add above testcase.
>
>
> Index: gcc/doc/plugins.texi
> ===================================================================
> --- gcc/doc/plugins.texi        (revision 158253)
> +++ gcc/doc/plugins.texi        (working copy)
> @@ -149,6 +149,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.  */
> Index: gcc/plugin.def
> ===================================================================
> --- gcc/plugin.def      (revision 158253)
> +++ gcc/plugin.def      (working copy)
> @@ -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)
>
> Index: gcc/testsuite/g++.dg/plugin/plugin.exp
> ===================================================================
> --- gcc/testsuite/g++.dg/plugin/plugin.exp      (revision 158253)
> +++ gcc/testsuite/g++.dg/plugin/plugin.exp      (working copy)
> @@ -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
> Index: gcc/testsuite/g++.dg/plugin/decl-plugin-test.C
> ===================================================================
> --- gcc/testsuite/g++.dg/plugin/decl-plugin-test.C      (revision 0)
> +++ gcc/testsuite/g++.dg/plugin/decl-plugin-test.C      (revision 0)
> @@ -0,0 +1,32 @@
> +
> +
> +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;
> +  }
> +};
> Index: gcc/testsuite/g++.dg/plugin/decl_plugin.c
> ===================================================================
> --- gcc/testsuite/g++.dg/plugin/decl_plugin.c   (revision 0)
> +++ gcc/testsuite/g++.dg/plugin/decl_plugin.c   (revision 0)
> @@ -0,0 +1,51 @@
> +/* 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"
> +
> +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_CONTEXT(decl) != NULL)
> +      kind = "Local";
> +    else
> +      kind = "Global";
> +    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;
> +}
> Index: gcc/cp/decl.c
> ===================================================================
> --- gcc/cp/decl.c       (revision 158253)
> +++ gcc/cp/decl.c       (working copy)
> @@ -5972,6 +5972,8 @@ cp_finish_decl (tree decl, tree init, bo
>   /* If this was marked 'used', be sure it will be output.  */
>   if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
>     mark_decl_referenced (decl);
> +
> +  invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
>  }
>
>  /* Returns a declaration for a VAR_DECL as if:
> Index: gcc/c-decl.c
> ===================================================================
> --- gcc/c-decl.c        (revision 158253)
> +++ gcc/c-decl.c        (working copy)
> @@ -4405,6 +4405,8 @@ finish_decl (tree decl, location_t init_
>       && DECL_INITIAL (decl) == NULL_TREE)
>     warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
>                "uninitialized const %qD is invalid in C++", decl);
> +
> +  invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
>  }
>
>  /* Given a parsed parameter declaration, decode it into a PARM_DECL.  */
> Index: gcc/plugin.c
> ===================================================================
> --- gcc/plugin.c        (revision 158253)
> +++ gcc/plugin.c        (working copy)
> @@ -425,6 +425,7 @@ register_callback (const char *plugin_na
>          }
>       /* Fall through.  */
>       case PLUGIN_FINISH_TYPE:
> +      case PLUGIN_FINISH_DECL:
>       case PLUGIN_START_UNIT:
>       case PLUGIN_FINISH_UNIT:
>       case PLUGIN_PRE_GENERICIZE:
> @@ -506,6 +507,7 @@ invoke_plugin_callbacks (int event, void
>        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:
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-12 19:54       ` Brian Hackett
@ 2010-04-14 14:15         ` Brian Hackett
  2010-04-27 15:09           ` Brian Hackett
  0 siblings, 1 reply; 42+ messages in thread
From: Brian Hackett @ 2010-04-14 14:15 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

On Mon, Apr 12, 2010 at 12:54 PM, Brian Hackett <bhackett1024@gmail.com> wrote:
> Hi, I don't have write access.  I'll update the patch and rerun the
> regressions for the current trunk (the patch below is a few months
> old) and reply when that's done.
>
> Brian
>
> On Mon, Apr 12, 2010 at 12:39 PM, Diego Novillo <dnovillo@google.com> wrote:
>> On Wed, Apr 7, 2010 at 14:30, Brian Hackett <bhackett1024@gmail.com> wrote:
>>
>>> http://gcc.gnu.org/ml/gcc-patches/2009-12/msg01032.html
>>
>> This is OK for trunk.  If you don't have write access let me know and
>> I will help you applying the patch.
>>
>>
>> Thanks.  Diego.

OK, below is an updated patch against revision 158253.   I get the
same regression results with and without this patch (modulo the new
testcase).  Thanks,

Brian


2010-04-14  Brian Hackett  <bhackett1024@gmail.com>

gcc/ChangeLog:

       * 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.

gcc/cp/ChangeLog:

       * decl.c (cp_finish_decl): Invoke callbacks on finish_decl event.

gcc/testsuite/ChangeLog:

       * g++.dg/plugin/decl_plugin.c: New test plugin.
       * g++.dg/plugin/decl-plugin-test.C: Testcase for above plugin.
       * g++.dg/plugin/plugin.exp: Add above testcase.


Index: gcc/doc/plugins.texi
===================================================================
--- gcc/doc/plugins.texi	(revision 158253)
+++ gcc/doc/plugins.texi	(working copy)
@@ -149,6 +149,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.  */
Index: gcc/plugin.def
===================================================================
--- gcc/plugin.def	(revision 158253)
+++ gcc/plugin.def	(working copy)
@@ -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)

Index: gcc/testsuite/g++.dg/plugin/plugin.exp
===================================================================
--- gcc/testsuite/g++.dg/plugin/plugin.exp	(revision 158253)
+++ gcc/testsuite/g++.dg/plugin/plugin.exp	(working copy)
@@ -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
Index: gcc/testsuite/g++.dg/plugin/decl-plugin-test.C
===================================================================
--- gcc/testsuite/g++.dg/plugin/decl-plugin-test.C	(revision 0)
+++ gcc/testsuite/g++.dg/plugin/decl-plugin-test.C	(revision 0)
@@ -0,0 +1,32 @@
+
+
+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;
+  }
+};
Index: gcc/testsuite/g++.dg/plugin/decl_plugin.c
===================================================================
--- gcc/testsuite/g++.dg/plugin/decl_plugin.c	(revision 0)
+++ gcc/testsuite/g++.dg/plugin/decl_plugin.c	(revision 0)
@@ -0,0 +1,51 @@
+/* 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"
+
+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_CONTEXT(decl) != NULL)
+      kind = "Local";
+    else
+      kind = "Global";
+    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;
+}
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 158253)
+++ gcc/cp/decl.c	(working copy)
@@ -5972,6 +5972,8 @@ cp_finish_decl (tree decl, tree init, bo
   /* If this was marked 'used', be sure it will be output.  */
   if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
     mark_decl_referenced (decl);
+
+  invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
 }

 /* Returns a declaration for a VAR_DECL as if:
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revision 158253)
+++ gcc/c-decl.c	(working copy)
@@ -4405,6 +4405,8 @@ finish_decl (tree decl, location_t init_
       && DECL_INITIAL (decl) == NULL_TREE)
     warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
 		"uninitialized const %qD is invalid in C++", decl);
+
+  invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl);
 }

 /* Given a parsed parameter declaration, decode it into a PARM_DECL.  */
Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c	(revision 158253)
+++ gcc/plugin.c	(working copy)
@@ -425,6 +425,7 @@ register_callback (const char *plugin_na
 	  }
       /* Fall through.  */
       case PLUGIN_FINISH_TYPE:
+      case PLUGIN_FINISH_DECL:
       case PLUGIN_START_UNIT:
       case PLUGIN_FINISH_UNIT:
       case PLUGIN_PRE_GENERICIZE:
@@ -506,6 +507,7 @@ invoke_plugin_callbacks (int event, void
 	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:

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-12 19:39     ` Diego Novillo
@ 2010-04-12 19:54       ` Brian Hackett
  2010-04-14 14:15         ` Brian Hackett
  0 siblings, 1 reply; 42+ messages in thread
From: Brian Hackett @ 2010-04-12 19:54 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

Hi, I don't have write access.  I'll update the patch and rerun the
regressions for the current trunk (the patch below is a few months
old) and reply when that's done.

Brian

On Mon, Apr 12, 2010 at 12:39 PM, Diego Novillo <dnovillo@google.com> wrote:
> On Wed, Apr 7, 2010 at 14:30, Brian Hackett <bhackett1024@gmail.com> wrote:
>
>> http://gcc.gnu.org/ml/gcc-patches/2009-12/msg01032.html
>
> This is OK for trunk.  If you don't have write access let me know and
> I will help you applying the patch.
>
>
> Thanks.  Diego.
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2010-04-07 18:30   ` Brian Hackett
@ 2010-04-12 19:39     ` Diego Novillo
  2010-04-12 19:54       ` Brian Hackett
  0 siblings, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2010-04-12 19:39 UTC (permalink / raw)
  To: Brian Hackett; +Cc: gcc-patches

On Wed, Apr 7, 2010 at 14:30, Brian Hackett <bhackett1024@gmail.com> wrote:

> http://gcc.gnu.org/ml/gcc-patches/2009-12/msg01032.html

This is OK for trunk.  If you don't have write access let me know and
I will help you applying the patch.


Thanks.  Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2009-12-22 21:01 ` Diego Novillo
@ 2010-04-07 18:30   ` Brian Hackett
  2010-04-12 19:39     ` Diego Novillo
  0 siblings, 1 reply; 42+ messages in thread
From: Brian Hackett @ 2010-04-07 18:30 UTC (permalink / raw)
  To: Diego Novillo; +Cc: gcc-patches

On Tue, Dec 22, 2009 at 11:45 AM, Diego Novillo <dnovillo@google.com> wrote:
> On Tue, Dec 22, 2009 at 13:00, Brian Hackett <bhackett1024@gmail.com> wrote:
>> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
>> at every finish_decl in the C and C++ frontends.  Previously there did
>> not seem to be a way for a plugin to see the definition for a global
>> that is never used in the input file, or the initializer for a global
>> which is declared before a function but defined after.  This event
>> isn't restricted to just globals though, but also locals, fields, and
>> parameters (C frontend only).
>
> Thanks for your patch.  This will be great to fix
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41757 but we need to wait
> for your copyright assignment to go through before we can accept it.

Hi, this is a patch from a few months ago which I was not able to get
an assignment for.  The FSF has a personal copyright assignment for
me, but I could not get one from my employer at the time, Stanford
(according to Stanford's policies they would not claim copyright on
this patch).  I now work for Mozilla, which (I understand) has a
company wide copyright assignment.  Are there issues if I from scratch
rewrite and resubmit a new patch?

Original patch (9 new lines of code, doc change and new regression):

http://gcc.gnu.org/ml/gcc-patches/2009-12/msg01032.html

Brian

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2009-12-22 18:42 Brian Hackett
  2009-12-22 18:45 ` H.J. Lu
@ 2009-12-22 21:01 ` Diego Novillo
  2010-04-07 18:30   ` Brian Hackett
  1 sibling, 1 reply; 42+ messages in thread
From: Diego Novillo @ 2009-12-22 21:01 UTC (permalink / raw)
  To: Brian Hackett; +Cc: gcc-patches

On Tue, Dec 22, 2009 at 13:00, Brian Hackett <bhackett1024@gmail.com> wrote:
> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
> at every finish_decl in the C and C++ frontends.  Previously there did
> not seem to be a way for a plugin to see the definition for a global
> that is never used in the input file, or the initializer for a global
> which is declared before a function but defined after.  This event
> isn't restricted to just globals though, but also locals, fields, and
> parameters (C frontend only).

Thanks for your patch.  This will be great to fix
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41757 but we need to wait
for your copyright assignment to go through before we can accept it.


Thanks.  Diego.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2009-12-22 19:46         ` H.J. Lu
@ 2009-12-22 20:37           ` Brian Hackett
  0 siblings, 0 replies; 42+ messages in thread
From: Brian Hackett @ 2009-12-22 20:37 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

OK, here is an updated ChangeLog:

2009-12-22  Brian Hackett  <bhackett1024@gmail.com>

gcc/ChangeLog:

	* 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.

gcc/cp/ChangeLog:

	* decl.c (cp_finish_decl): Invoke callbacks on finish_decl event.

gcc/testsuite/ChangeLog:

	* g++.dg/plugin/decl_plugin.c: New test plugin.
	* g++.dg/plugin/decl-plugin-test.C: Testcase for above plugin.
	* g++.dg/plugin/plugin.exp


On Tue, Dec 22, 2009 at 10:45 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Dec 22, 2009 at 10:42 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>> Where should texi ChangeLog changes go?  There's no changelog in
>> gcc/doc and no .texi updates in gcc/ChangeLog.
>
> They should be listed in gcc/ChanngeLog:
>
> [hjl@gnu-6 gcc]$ grep doc/ gcc/ChangeLog | head -10
>        * doc/plugins.texi: Rename pre-genericize event.
>        * doc/invoke.texi: Fix typo.
>        * doc/tm.texi (ARG_POINTER_CFA_OFFSET): Document new default.
>        * doc/rtl.texi (Vector Operations): Clarify vec_select result mode.
>        * doc/invoke.texi, doc/options.texi, doc/plugins.texi,
>        doc/tm.texi: Fix typos.
>        * doc/extend.texi (Function Attributes, Extended Asm):
>        * doc/md.texi (Standard Names): Likewise.
>        * doc/plugins.texi (Plugins): Likewise.
>        * doc/c-tree.texi (Expression trees): Use @itemx for all but
> [hjl@gnu-6 gcc]$
>
>> Brian
>>
>> On Tue, Dec 22, 2009 at 10:24 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Tue, Dec 22, 2009 at 10:16 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>>>> Hi, I added comments/documentation in plugin.def and doc/plugins.texi
>>>> consistent with other plugins.  Is there another place documentation
>>>> should go?
>>>
>>> doc/plugins.texi isn't mentioned in ChangeLog.
>>>
>>>
>>> H.J.
>>> ---
>>>> Brian
>>>>
>>>> On Tue, Dec 22, 2009 at 10:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Tue, Dec 22, 2009 at 10:00 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>>>>>> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
>>>>>> at every finish_decl in the C and C++ frontends.  Previously there did
>>>>>> not seem to be a way for a plugin to see the definition for a global
>>>>>> that is never used in the input file, or the initializer for a global
>>>>>> which is declared before a function but defined after.  This event
>>>>>> isn't restricted to just globals though, but also locals, fields, and
>>>>>> parameters (C frontend only).
>>>>>>
>>>>>> Brian
>>>>>>
>>>>>>
>>>>>>
>>>>>> 2009-12-22  Brian Hackett  <bhackett1024@gmail.com>
>>>>>>
>>>>>> gcc/ChangeLog:
>>>>>>
>>>>>>        * 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.
>>>>>>
>>>>>
>>>>> Shouldn't it be documented?
>>>>>
>>>>>
>>>
>>
>
>
>
> --
> H.J.
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2009-12-22 19:04       ` Brian Hackett
@ 2009-12-22 19:46         ` H.J. Lu
  2009-12-22 20:37           ` Brian Hackett
  0 siblings, 1 reply; 42+ messages in thread
From: H.J. Lu @ 2009-12-22 19:46 UTC (permalink / raw)
  To: Brian Hackett; +Cc: gcc-patches

On Tue, Dec 22, 2009 at 10:42 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
> Where should texi ChangeLog changes go?  There's no changelog in
> gcc/doc and no .texi updates in gcc/ChangeLog.

They should be listed in gcc/ChanngeLog:

[hjl@gnu-6 gcc]$ grep doc/ gcc/ChangeLog | head -10
	* doc/plugins.texi: Rename pre-genericize event.
	* doc/invoke.texi: Fix typo.
	* doc/tm.texi (ARG_POINTER_CFA_OFFSET): Document new default.
	* doc/rtl.texi (Vector Operations): Clarify vec_select result mode.
	* doc/invoke.texi, doc/options.texi, doc/plugins.texi,
	doc/tm.texi: Fix typos.
	* doc/extend.texi (Function Attributes, Extended Asm):
	* doc/md.texi (Standard Names): Likewise.
	* doc/plugins.texi (Plugins): Likewise.
	* doc/c-tree.texi (Expression trees): Use @itemx for all but
[hjl@gnu-6 gcc]$

> Brian
>
> On Tue, Dec 22, 2009 at 10:24 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, Dec 22, 2009 at 10:16 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>>> Hi, I added comments/documentation in plugin.def and doc/plugins.texi
>>> consistent with other plugins.  Is there another place documentation
>>> should go?
>>
>> doc/plugins.texi isn't mentioned in ChangeLog.
>>
>>
>> H.J.
>> ---
>>> Brian
>>>
>>> On Tue, Dec 22, 2009 at 10:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Tue, Dec 22, 2009 at 10:00 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>>>>> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
>>>>> at every finish_decl in the C and C++ frontends.  Previously there did
>>>>> not seem to be a way for a plugin to see the definition for a global
>>>>> that is never used in the input file, or the initializer for a global
>>>>> which is declared before a function but defined after.  This event
>>>>> isn't restricted to just globals though, but also locals, fields, and
>>>>> parameters (C frontend only).
>>>>>
>>>>> Brian
>>>>>
>>>>>
>>>>>
>>>>> 2009-12-22  Brian Hackett  <bhackett1024@gmail.com>
>>>>>
>>>>> gcc/ChangeLog:
>>>>>
>>>>>        * 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.
>>>>>
>>>>
>>>> Shouldn't it be documented?
>>>>
>>>>
>>
>



-- 
H.J.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2009-12-22 18:50     ` H.J. Lu
@ 2009-12-22 19:04       ` Brian Hackett
  2009-12-22 19:46         ` H.J. Lu
  0 siblings, 1 reply; 42+ messages in thread
From: Brian Hackett @ 2009-12-22 19:04 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

Where should texi ChangeLog changes go?  There's no changelog in
gcc/doc and no .texi updates in gcc/ChangeLog.

Brian

On Tue, Dec 22, 2009 at 10:24 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Dec 22, 2009 at 10:16 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>> Hi, I added comments/documentation in plugin.def and doc/plugins.texi
>> consistent with other plugins.  Is there another place documentation
>> should go?
>
> doc/plugins.texi isn't mentioned in ChangeLog.
>
>
> H.J.
> ---
>> Brian
>>
>> On Tue, Dec 22, 2009 at 10:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>> On Tue, Dec 22, 2009 at 10:00 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>>>> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
>>>> at every finish_decl in the C and C++ frontends.  Previously there did
>>>> not seem to be a way for a plugin to see the definition for a global
>>>> that is never used in the input file, or the initializer for a global
>>>> which is declared before a function but defined after.  This event
>>>> isn't restricted to just globals though, but also locals, fields, and
>>>> parameters (C frontend only).
>>>>
>>>> Brian
>>>>
>>>>
>>>>
>>>> 2009-12-22  Brian Hackett  <bhackett1024@gmail.com>
>>>>
>>>> gcc/ChangeLog:
>>>>
>>>>        * 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.
>>>>
>>>
>>> Shouldn't it be documented?
>>>
>>>
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2009-12-22 18:46   ` Brian Hackett
@ 2009-12-22 18:50     ` H.J. Lu
  2009-12-22 19:04       ` Brian Hackett
  0 siblings, 1 reply; 42+ messages in thread
From: H.J. Lu @ 2009-12-22 18:50 UTC (permalink / raw)
  To: Brian Hackett; +Cc: gcc-patches

On Tue, Dec 22, 2009 at 10:16 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
> Hi, I added comments/documentation in plugin.def and doc/plugins.texi
> consistent with other plugins.  Is there another place documentation
> should go?

doc/plugins.texi isn't mentioned in ChangeLog.


H.J.
---
> Brian
>
> On Tue, Dec 22, 2009 at 10:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Tue, Dec 22, 2009 at 10:00 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>>> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
>>> at every finish_decl in the C and C++ frontends.  Previously there did
>>> not seem to be a way for a plugin to see the definition for a global
>>> that is never used in the input file, or the initializer for a global
>>> which is declared before a function but defined after.  This event
>>> isn't restricted to just globals though, but also locals, fields, and
>>> parameters (C frontend only).
>>>
>>> Brian
>>>
>>>
>>>
>>> 2009-12-22  Brian Hackett  <bhackett1024@gmail.com>
>>>
>>> gcc/ChangeLog:
>>>
>>>        * 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.
>>>
>>
>> Shouldn't it be documented?
>>
>>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2009-12-22 18:45 ` H.J. Lu
@ 2009-12-22 18:46   ` Brian Hackett
  2009-12-22 18:50     ` H.J. Lu
  0 siblings, 1 reply; 42+ messages in thread
From: Brian Hackett @ 2009-12-22 18:46 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches

Hi, I added comments/documentation in plugin.def and doc/plugins.texi
consistent with other plugins.  Is there another place documentation
should go?

Brian

On Tue, Dec 22, 2009 at 10:13 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Dec 22, 2009 at 10:00 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
>> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
>> at every finish_decl in the C and C++ frontends.  Previously there did
>> not seem to be a way for a plugin to see the definition for a global
>> that is never used in the input file, or the initializer for a global
>> which is declared before a function but defined after.  This event
>> isn't restricted to just globals though, but also locals, fields, and
>> parameters (C frontend only).
>>
>> Brian
>>
>>
>>
>> 2009-12-22  Brian Hackett  <bhackett1024@gmail.com>
>>
>> gcc/ChangeLog:
>>
>>        * 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.
>>
>
> Shouldn't it be documented?
>
>
> --
> H.J.
>

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: plugin event for C/C++ declarations
  2009-12-22 18:42 Brian Hackett
@ 2009-12-22 18:45 ` H.J. Lu
  2009-12-22 18:46   ` Brian Hackett
  2009-12-22 21:01 ` Diego Novillo
  1 sibling, 1 reply; 42+ messages in thread
From: H.J. Lu @ 2009-12-22 18:45 UTC (permalink / raw)
  To: Brian Hackett; +Cc: gcc-patches

On Tue, Dec 22, 2009 at 10:00 AM, Brian Hackett <bhackett1024@gmail.com> wrote:
> Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
> at every finish_decl in the C and C++ frontends.  Previously there did
> not seem to be a way for a plugin to see the definition for a global
> that is never used in the input file, or the initializer for a global
> which is declared before a function but defined after.  This event
> isn't restricted to just globals though, but also locals, fields, and
> parameters (C frontend only).
>
> Brian
>
>
>
> 2009-12-22  Brian Hackett  <bhackett1024@gmail.com>
>
> gcc/ChangeLog:
>
>        * 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.
>

Shouldn't it be documented?


-- 
H.J.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* plugin event for C/C++ declarations
@ 2009-12-22 18:42 Brian Hackett
  2009-12-22 18:45 ` H.J. Lu
  2009-12-22 21:01 ` Diego Novillo
  0 siblings, 2 replies; 42+ messages in thread
From: Brian Hackett @ 2009-12-22 18:42 UTC (permalink / raw)
  To: gcc-patches

Hi, this patch adds a new plugin event FINISH_DECL, which is invoked
at every finish_decl in the C and C++ frontends.  Previously there did
not seem to be a way for a plugin to see the definition for a global
that is never used in the input file, or the initializer for a global
which is declared before a function but defined after.  This event
isn't restricted to just globals though, but also locals, fields, and
parameters (C frontend only).

Brian



2009-12-22  Brian Hackett  <bhackett1024@gmail.com>

gcc/ChangeLog:

	* 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.

gcc/cp/ChangeLog:

	* decl.c (cp_finish_decl): Invoke callbacks on finish_decl event.

gcc/testsuite/ChangeLog:

	* g++.dg/plugin/decl_plugin.c: New test plugin.
	* g++.dg/plugin/decl-plugin-test.C: Testcase for above plugin.
	* g++.dg/plugin/plugin.exp




Index: gcc/doc/plugins.texi
===================================================================
--- gcc/doc/plugins.texi	(revision 155401)
+++ gcc/doc/plugins.texi	(working copy)
@@ -146,6 +146,7 @@ enum plugin_event
   PLUGIN_FINISH_TYPE,           /* After finishing parsing a type.  */
   PLUGIN_FINISH_UNIT,           /* Useful for summary processing.  */
   PLUGIN_PRE_GENERICIZE,        /* Allows to see low level AST in C
and C++ frontends.  */
+  PLUGIN_FINISH_DECL,           /* Allows to see all declarations in
C and C++ frontends. */
   PLUGIN_FINISH,                /* Called before GCC exits.  */
   PLUGIN_INFO,                  /* Information about the plugin. */
   PLUGIN_GGC_START,		/* Called at start of GCC Garbage Collection. */
Index: gcc/plugin.def
===================================================================
--- gcc/plugin.def	(revision 155386)
+++ gcc/plugin.def	(working copy)
@@ -30,6 +30,9 @@ DEFEVENT (PLUGIN_FINISH_UNIT)
 /* Allows to see low level AST in C and C++ frontends. */
 DEFEVENT (PLUGIN_PRE_GENERICIZE)

+/* Allows to see all declarations in C and C++ frontends. */
+DEFEVENT (PLUGIN_FINISH_DECL)
+
 /* Called before GCC exits.  */
 DEFEVENT (PLUGIN_FINISH)

Index: gcc/testsuite/g++.dg/plugin/plugin.exp
===================================================================
--- gcc/testsuite/g++.dg/plugin/plugin.exp	(revision 155401)
+++ gcc/testsuite/g++.dg/plugin/plugin.exp	(working copy)
@@ -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
Index: gcc/testsuite/g++.dg/plugin/decl-plugin-test.C
===================================================================
--- gcc/testsuite/g++.dg/plugin/decl-plugin-test.C	(revision 0)
+++ gcc/testsuite/g++.dg/plugin/decl-plugin-test.C	(revision 0)
@@ -0,0 +1,32 @@
+
+
+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;
+  }
+};
Index: gcc/testsuite/g++.dg/plugin/decl_plugin.c
===================================================================
--- gcc/testsuite/g++.dg/plugin/decl_plugin.c	(revision 0)
+++ gcc/testsuite/g++.dg/plugin/decl_plugin.c	(revision 0)
@@ -0,0 +1,51 @@
+/* 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"
+
+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_CONTEXT(decl) != NULL)
+      kind = "Local";
+    else
+      kind = "Global";
+    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;
+}
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c	(revision 155386)
+++ gcc/cp/decl.c	(working copy)
@@ -5949,6 +5949,8 @@ cp_finish_decl (tree decl, tree init, bo
   /* If this was marked 'used', be sure it will be output.  */
   if (lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
     mark_decl_referenced (decl);
+
+  invoke_plugin_callbacks(PLUGIN_FINISH_DECL, decl);
 }

 /* Returns a declaration for a VAR_DECL as if:
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c	(revision 155386)
+++ gcc/c-decl.c	(working copy)
@@ -4389,6 +4389,8 @@ finish_decl (tree decl, location_t init_
       && DECL_INITIAL (decl) == NULL_TREE)
     warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat,
 		"uninitialized const %qD is invalid in C++", decl);
+
+  invoke_plugin_callbacks(PLUGIN_FINISH_DECL, decl);
 }

 /* Given a parsed parameter declaration, decode it into a PARM_DECL.  */
Index: gcc/plugin.c
===================================================================
--- gcc/plugin.c	(revision 155386)
+++ gcc/plugin.c	(working copy)
@@ -403,6 +403,7 @@ register_callback (const char *plugin_na
       case PLUGIN_START_UNIT:
       case PLUGIN_FINISH_UNIT:
       case PLUGIN_PRE_GENERICIZE:
+      case PLUGIN_FINISH_DECL:
       case PLUGIN_GGC_START:
       case PLUGIN_GGC_MARKING:
       case PLUGIN_GGC_END:
@@ -484,6 +485,7 @@ invoke_plugin_callbacks (int event, void
       case PLUGIN_START_UNIT:
       case PLUGIN_FINISH_UNIT:
       case PLUGIN_PRE_GENERICIZE:
+      case PLUGIN_FINISH_DECL:
       case PLUGIN_ATTRIBUTES:
       case PLUGIN_PRAGMAS:
       case PLUGIN_FINISH:

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2011-08-11 15:58 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-29 13:00 plugin event for C/C++ declarations Dominique Dhumieres
  -- strict thread matches above, loose matches on Subject: below --
2011-07-07  9:09 Romain Geissler
2011-07-07 12:19 ` Diego Novillo
2011-07-11  8:21   ` Romain Geissler
2011-07-18  9:28     ` Romain Geissler
2011-07-20 12:37       ` Diego Novillo
2011-08-08 12:13         ` Romain Geissler
2011-08-10 15:59           ` Diego Novillo
2011-08-11 13:37             ` Romain Geissler
2011-08-11 17:11               ` Diego Novillo
2009-12-22 18:42 Brian Hackett
2009-12-22 18:45 ` H.J. Lu
2009-12-22 18:46   ` Brian Hackett
2009-12-22 18:50     ` H.J. Lu
2009-12-22 19:04       ` Brian Hackett
2009-12-22 19:46         ` H.J. Lu
2009-12-22 20:37           ` Brian Hackett
2009-12-22 21:01 ` Diego Novillo
2010-04-07 18:30   ` Brian Hackett
2010-04-12 19:39     ` Diego Novillo
2010-04-12 19:54       ` Brian Hackett
2010-04-14 14:15         ` Brian Hackett
2010-04-27 15:09           ` Brian Hackett
2010-04-27 15:29             ` Diego Novillo
2010-04-27 15:31               ` Richard Guenther
2010-04-27 15:32                 ` Richard Guenther
2010-04-27 15:46                   ` Brian Hackett
2010-04-27 15:50                     ` Richard Guenther
2010-04-27 16:00                       ` Diego Novillo
2010-04-27 16:03                         ` Richard Guenther
2010-04-27 16:04                           ` Diego Novillo
2010-04-27 17:16                             ` Richard Guenther
2010-04-27 20:15                               ` Brian Hackett
2010-04-28 10:01                                 ` Richard Guenther
2010-04-28 14:34                                 ` Diego Novillo
2010-04-29  2:24                                   ` Brian Hackett
2010-04-29 10:02                                     ` Richard Guenther
2010-04-29 13:22                                     ` H.J. Lu
2010-04-29 14:03                                       ` Brian Hackett
2010-04-29 14:04                                         ` H.J. Lu
2010-04-29 14:37                                           ` Brian Hackett
2010-04-27 15:45                 ` Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).