public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself
@ 2007-03-03 11:48 Manuel López-Ibáñez
  2007-03-14 23:15 ` [PING^2] " Manuel López-Ibáñez
  0 siblings, 1 reply; 13+ messages in thread
From: Manuel López-Ibáñez @ 2007-03-03 11:48 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joseph Myers, Nathan Sidwell, Richard Henderson

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

:ADDPATCH C / C++:

-Wunused currently does not warn about static functions that are
called only by themselves. This patch prevents marking a function as
used if the call is done within the same function.

Bootstrapped and regression tested with --enable-languages=all.
This patch has found a few unused in GCC codebase.

OK for mainline?


2007-03-03  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

  PR c/4076
  * c-typeck.c (build_external_ref): Don't mark as used if called from itself.
  * calls.c (rtx_for_function_call): Likewise.

cp/
  * call.c (build_call_a): Don't mark as used if called from itself.
  * semantics.c (finish_id_expression): Likewise.

testsuite/
  * gcc.dg/Wunused-function.c: New.
  * g++.dg/warn/Wunused-function.C: New.

[-- Attachment #2: wunused-function.diff --]
[-- Type: text/plain, Size: 3747 bytes --]

Index: gcc/testsuite/gcc.dg/Wunused-function.c
===================================================================
--- gcc/testsuite/gcc.dg/Wunused-function.c	(revision 0)
+++ gcc/testsuite/gcc.dg/Wunused-function.c	(revision 0)
@@ -0,0 +1,6 @@
+/* PR c/4076  -Wunused doesn't warn about static function only called by itself.  */
+/* { dg-do compile } */
+/* { dg-options "-Wunused-function" } */
+
+static void foo (void) {} /* { dg-warning "'foo' defined but not used" } */
+static void bar (void) { bar (); } /* { dg-warning "'bar' defined but not used" } */
Index: gcc/testsuite/g++.dg/warn/Wunused-function.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wunused-function.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/Wunused-function.C	(revision 0)
@@ -0,0 +1,9 @@
+// PR c/4076  -Wunused doesn't warn about static function only called by itself.  
+// { dg-do compile } 
+// { dg-options "-Wunused-function" }
+
+static void foo (void);
+static void bar (void);
+
+static void foo (void) {} // { dg-warning "foo.?.?' defined but not used" } 
+static void bar (void) { bar (); } // { dg-warning "bar.?.?' defined but not used" } 
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c	(revision 122472)
+++ gcc/cp/call.c	(working copy)
@@ -314,7 +314,9 @@ build_call_a (tree function, int n, tree
       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
     {
       decl = TREE_OPERAND (function, 0);
-      if (!TREE_USED (decl))
+
+      /* Recursive call does not count as usage.  */
+      if (!TREE_USED (decl) && decl != current_function_decl)
 	{
 	  /* We invoke build_call directly for several library
 	     functions.  These may have been declared normally if
@@ -5028,7 +5030,9 @@ build_over_call (struct z_candidate *can
       return val;
     }
 
-  mark_used (fn);
+  /* Recursive call does not count as usage.  */
+  if (fn != current_function_decl)
+    mark_used (fn);
 
   if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
     {
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 122472)
+++ gcc/cp/semantics.c	(working copy)
@@ -2852,7 +2852,8 @@ finish_id_expression (tree id_expression
 	  if (TREE_CODE (first_fn) == TEMPLATE_DECL)
 	    first_fn = DECL_TEMPLATE_RESULT (first_fn);
 
-	  if (!really_overloaded_fn (decl))
+	  /* Recursive call does not count as usage.  */
+	  if (!really_overloaded_fn (decl) && decl != current_function_decl)
 	    mark_used (first_fn);
 
 	  if (!template_arg_p
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 122472)
+++ gcc/c-typeck.c	(working copy)
@@ -2077,9 +2077,13 @@ build_external_ref (tree id, int fun, lo
   if (TREE_DEPRECATED (ref))
     warn_deprecated_use (ref);
 
-  if (!skip_evaluation)
-    assemble_external (ref);
-  TREE_USED (ref) = 1;
+  /* Recursive call does not count as usage.  */
+  if (ref != current_function_decl) 
+    {
+      if (!skip_evaluation)
+	assemble_external (ref);
+      TREE_USED (ref) = 1;
+    }
 
   if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
     {
Index: gcc/calls.c
===================================================================
--- gcc/calls.c	(revision 122472)
+++ gcc/calls.c	(working copy)
@@ -1482,7 +1482,7 @@ rtx_for_function_call (tree fndecl, tree
     {
       /* If this is the first use of the function, see if we need to
 	 make an external definition for it.  */
-      if (! TREE_USED (fndecl))
+      if (!TREE_USED (fndecl) && fndecl != current_function_decl)
 	{
 	  assemble_external (fndecl);
 	  TREE_USED (fndecl) = 1;

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

* [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself
  2007-03-03 11:48 [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself Manuel López-Ibáñez
@ 2007-03-14 23:15 ` Manuel López-Ibáñez
  2007-03-15 10:17   ` Nathan Sidwell
  0 siblings, 1 reply; 13+ messages in thread
From: Manuel López-Ibáñez @ 2007-03-14 23:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: Joseph Myers, Nathan Sidwell, Richard Henderson

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

This is the last ping of tonight, I don't want to annoy people.

http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00171.html

Cheers,

Manuel.

On 03/03/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> :ADDPATCH C / C++:
>
> -Wunused currently does not warn about static functions that are
> called only by themselves. This patch prevents marking a function as
> used if the call is done within the same function.
>
> Bootstrapped and regression tested with --enable-languages=all.
> This patch has found a few unused in GCC codebase.
>
> OK for mainline?
>
>
> 2007-03-03  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
>
>   PR c/4076
>   * c-typeck.c (build_external_ref): Don't mark as used if called from itself.
>   * calls.c (rtx_for_function_call): Likewise.
>
> cp/
>   * call.c (build_call_a): Don't mark as used if called from itself.
>   * semantics.c (finish_id_expression): Likewise.
>
> testsuite/
>   * gcc.dg/Wunused-function.c: New.
>   * g++.dg/warn/Wunused-function.C: New.
>
>

[-- Attachment #2: wunused-function.diff --]
[-- Type: text/plain, Size: 3747 bytes --]

Index: gcc/testsuite/gcc.dg/Wunused-function.c
===================================================================
--- gcc/testsuite/gcc.dg/Wunused-function.c	(revision 0)
+++ gcc/testsuite/gcc.dg/Wunused-function.c	(revision 0)
@@ -0,0 +1,6 @@
+/* PR c/4076  -Wunused doesn't warn about static function only called by itself.  */
+/* { dg-do compile } */
+/* { dg-options "-Wunused-function" } */
+
+static void foo (void) {} /* { dg-warning "'foo' defined but not used" } */
+static void bar (void) { bar (); } /* { dg-warning "'bar' defined but not used" } */
Index: gcc/testsuite/g++.dg/warn/Wunused-function.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wunused-function.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/Wunused-function.C	(revision 0)
@@ -0,0 +1,9 @@
+// PR c/4076  -Wunused doesn't warn about static function only called by itself.  
+// { dg-do compile } 
+// { dg-options "-Wunused-function" }
+
+static void foo (void);
+static void bar (void);
+
+static void foo (void) {} // { dg-warning "foo.?.?' defined but not used" } 
+static void bar (void) { bar (); } // { dg-warning "bar.?.?' defined but not used" } 
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c	(revision 122472)
+++ gcc/cp/call.c	(working copy)
@@ -314,7 +314,9 @@ build_call_a (tree function, int n, tree
       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
     {
       decl = TREE_OPERAND (function, 0);
-      if (!TREE_USED (decl))
+
+      /* Recursive call does not count as usage.  */
+      if (!TREE_USED (decl) && decl != current_function_decl)
 	{
 	  /* We invoke build_call directly for several library
 	     functions.  These may have been declared normally if
@@ -5028,7 +5030,9 @@ build_over_call (struct z_candidate *can
       return val;
     }
 
-  mark_used (fn);
+  /* Recursive call does not count as usage.  */
+  if (fn != current_function_decl)
+    mark_used (fn);
 
   if (DECL_VINDEX (fn) && (flags & LOOKUP_NONVIRTUAL) == 0)
     {
Index: gcc/cp/semantics.c
===================================================================
--- gcc/cp/semantics.c	(revision 122472)
+++ gcc/cp/semantics.c	(working copy)
@@ -2852,7 +2852,8 @@ finish_id_expression (tree id_expression
 	  if (TREE_CODE (first_fn) == TEMPLATE_DECL)
 	    first_fn = DECL_TEMPLATE_RESULT (first_fn);
 
-	  if (!really_overloaded_fn (decl))
+	  /* Recursive call does not count as usage.  */
+	  if (!really_overloaded_fn (decl) && decl != current_function_decl)
 	    mark_used (first_fn);
 
 	  if (!template_arg_p
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 122472)
+++ gcc/c-typeck.c	(working copy)
@@ -2077,9 +2077,13 @@ build_external_ref (tree id, int fun, lo
   if (TREE_DEPRECATED (ref))
     warn_deprecated_use (ref);
 
-  if (!skip_evaluation)
-    assemble_external (ref);
-  TREE_USED (ref) = 1;
+  /* Recursive call does not count as usage.  */
+  if (ref != current_function_decl) 
+    {
+      if (!skip_evaluation)
+	assemble_external (ref);
+      TREE_USED (ref) = 1;
+    }
 
   if (TREE_CODE (ref) == FUNCTION_DECL && !in_alignof)
     {
Index: gcc/calls.c
===================================================================
--- gcc/calls.c	(revision 122472)
+++ gcc/calls.c	(working copy)
@@ -1482,7 +1482,7 @@ rtx_for_function_call (tree fndecl, tree
     {
       /* If this is the first use of the function, see if we need to
 	 make an external definition for it.  */
-      if (! TREE_USED (fndecl))
+      if (!TREE_USED (fndecl) && fndecl != current_function_decl)
 	{
 	  assemble_external (fndecl);
 	  TREE_USED (fndecl) = 1;

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static  function only called by itself
  2007-03-14 23:15 ` [PING^2] " Manuel López-Ibáñez
@ 2007-03-15 10:17   ` Nathan Sidwell
  2007-03-16 11:32     ` Manuel López-Ibáñez
  0 siblings, 1 reply; 13+ messages in thread
From: Nathan Sidwell @ 2007-03-15 10:17 UTC (permalink / raw)
  To: Manuel López-Ibáñez
  Cc: gcc-patches, Joseph Myers, Richard Henderson

Manuel López-Ibáñez wrote:

> Index: gcc/cp/semantics.c
> ===================================================================
> --- gcc/cp/semantics.c	(revision 122472)
> +++ gcc/cp/semantics.c	(working copy)
> @@ -2852,7 +2852,8 @@ finish_id_expression (tree id_expression
>  	  if (TREE_CODE (first_fn) == TEMPLATE_DECL)
>  	    first_fn = DECL_TEMPLATE_RESULT (first_fn);
>  
> -	  if (!really_overloaded_fn (decl))
> +	  /* Recursive call does not count as usage.  */
> +	  if (!really_overloaded_fn (decl) && decl != current_function_decl)
>  	    mark_used (first_fn);
>  
>  	  if (!template_arg_p

what about the other mark_used earlier on in that function:

       if (scope)
	{
	  decl = (adjust_result_of_qualified_name_lookup
		  (decl, scope, current_class_type));

	  if (TREE_CODE (decl) == FUNCTION_DECL)
	    mark_used (decl);

why not similarly protect that?  the other c++ bits are ok.

nathan
-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself
  2007-03-15 10:17   ` Nathan Sidwell
@ 2007-03-16 11:32     ` Manuel López-Ibáñez
  2007-03-16 12:38       ` Nathan Sidwell
  2007-03-16 15:29       ` [PING^2] " Gabriel Dos Reis
  0 siblings, 2 replies; 13+ messages in thread
From: Manuel López-Ibáñez @ 2007-03-16 11:32 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: gcc-patches, Joseph Myers, Richard Henderson

On 15/03/07, Nathan Sidwell <nathan@codesourcery.com> wrote:
> Manuel López-Ibáñez wrote:
>
> > Index: gcc/cp/semantics.c
> > ===================================================================
> > --- gcc/cp/semantics.c        (revision 122472)
> > +++ gcc/cp/semantics.c        (working copy)
> > @@ -2852,7 +2852,8 @@ finish_id_expression (tree id_expression
> >         if (TREE_CODE (first_fn) == TEMPLATE_DECL)
> >           first_fn = DECL_TEMPLATE_RESULT (first_fn);
> >
> > -       if (!really_overloaded_fn (decl))
> > +       /* Recursive call does not count as usage.  */
> > +       if (!really_overloaded_fn (decl) && decl != current_function_decl)
> >           mark_used (first_fn);
> >
> >         if (!template_arg_p
>
> what about the other mark_used earlier on in that function:
>
>        if (scope)
>         {
>           decl = (adjust_result_of_qualified_name_lookup
>                   (decl, scope, current_class_type));
>
>           if (TREE_CODE (decl) == FUNCTION_DECL)
>             mark_used (decl);
>
> why not similarly protect that?  the other c++ bits are ok.
>
> nathan

I could but I was not able to construct a case where it was necessary.
How can a static function make a scoped recursive call? Sorry my
knowledge of C++ is not so good.

Cheers,

Manuel.

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static  function only called by itself
  2007-03-16 11:32     ` Manuel López-Ibáñez
@ 2007-03-16 12:38       ` Nathan Sidwell
  2007-03-16 15:21         ` Gabriel Dos Reis
  2007-03-17  0:47         ` Manuel López-Ibáñez
  2007-03-16 15:29       ` [PING^2] " Gabriel Dos Reis
  1 sibling, 2 replies; 13+ messages in thread
From: Nathan Sidwell @ 2007-03-16 12:38 UTC (permalink / raw)
  To: Manuel López-Ibáñez
  Cc: gcc-patches, Joseph Myers, Richard Henderson

Manuel López-Ibáñez wrote:

> I could but I was not able to construct a case where it was necessary.
> How can a static function make a scoped recursive call? Sorry my
> knowledge of C++ is not so good.

namespace { struct X { void Foo () { X::Foo (); }}}

might just cut it.  Yes I know anonymous namespaces are not quite the same as 
static, and I don't know if we'll check this, but it seems wise to copy the 
idiom you've introduced.

nathan

-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static  function only called by itself
  2007-03-16 12:38       ` Nathan Sidwell
@ 2007-03-16 15:21         ` Gabriel Dos Reis
  2007-03-17  0:47         ` Manuel López-Ibáñez
  1 sibling, 0 replies; 13+ messages in thread
From: Gabriel Dos Reis @ 2007-03-16 15:21 UTC (permalink / raw)
  To: Nathan Sidwell
  Cc: Manuel López-Ibáñez, gcc-patches, Joseph Myers,
	Richard Henderson

Nathan Sidwell <nathan@codesourcery.com> writes:

| Manuel López-Ibáñez wrote:
| 
| > I could but I was not able to construct a case where it was necessary.
| > How can a static function make a scoped recursive call? Sorry my
| > knowledge of C++ is not so good.
| 
| namespace { struct X { void Foo () { X::Foo (); }}}
| 
| might just cut it.

I think the same would apply member functions of local classes, no?

| Yes I know anonymous namespaces are not quite the
| same as static, and I don't know if we'll check this, but it seems
| wise to copy the idiom you've introduced.

speaking of unnamed namespaces member being treated "static", a
regression was introduced recently where the compiler will reject use
of unnamed namespace members as template arguments.

-- Gaby

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself
  2007-03-16 11:32     ` Manuel López-Ibáñez
  2007-03-16 12:38       ` Nathan Sidwell
@ 2007-03-16 15:29       ` Gabriel Dos Reis
  2007-03-16 15:42         ` Manuel López-Ibáñez
  1 sibling, 1 reply; 13+ messages in thread
From: Gabriel Dos Reis @ 2007-03-16 15:29 UTC (permalink / raw)
  To: Manuel López-Ibáñez
  Cc: Nathan Sidwell, gcc-patches, Joseph Myers, Richard Henderson

"Manuel López-Ibáñez" <lopezibanez@gmail.com> writes:

| On 15/03/07, Nathan Sidwell <nathan@codesourcery.com> wrote:
| > Manuel López-Ibáñez wrote:
| >
| > > Index: gcc/cp/semantics.c
| > > ===================================================================
| > > --- gcc/cp/semantics.c        (revision 122472)
| > > +++ gcc/cp/semantics.c        (working copy)
| > > @@ -2852,7 +2852,8 @@ finish_id_expression (tree id_expression
| > >         if (TREE_CODE (first_fn) == TEMPLATE_DECL)
| > >           first_fn = DECL_TEMPLATE_RESULT (first_fn);
| > >
| > > -       if (!really_overloaded_fn (decl))
| > > +       /* Recursive call does not count as usage.  */
| > > +       if (!really_overloaded_fn (decl) && decl != current_function_decl)
| > >           mark_used (first_fn);
| > >
| > >         if (!template_arg_p
| >
| > what about the other mark_used earlier on in that function:
| >
| >        if (scope)
| >         {
| >           decl = (adjust_result_of_qualified_name_lookup
| >                   (decl, scope, current_class_type));
| >
| >           if (TREE_CODE (decl) == FUNCTION_DECL)
| >             mark_used (decl);
| >
| > why not similarly protect that?  the other c++ bits are ok.
| >
| > nathan
| 
| I could but I was not able to construct a case where it was necessary.
| How can a static function make a scoped recursive call?
                                   ^^^^^^^^^^^^^^^^^^^^

I'm unclear about what you mean by that.

-- Gaby

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself
  2007-03-16 15:29       ` [PING^2] " Gabriel Dos Reis
@ 2007-03-16 15:42         ` Manuel López-Ibáñez
  0 siblings, 0 replies; 13+ messages in thread
From: Manuel López-Ibáñez @ 2007-03-16 15:42 UTC (permalink / raw)
  To: Gabriel Dos Reis
  Cc: Nathan Sidwell, gcc-patches, Joseph Myers, Richard Henderson

On 16 Mar 2007 06:04:41 -0500, Gabriel Dos Reis <gdr@cs.tamu.edu> wrote:
> "Manuel López-Ibáñez" <lopezibanez@gmail.com> writes:
>
> | On 15/03/07, Nathan Sidwell <nathan@codesourcery.com> wrote:
> | > Manuel López-Ibáñez wrote:
> | >
> | > > Index: gcc/cp/semantics.c
> | > > ===================================================================
> | > > --- gcc/cp/semantics.c        (revision 122472)
> | > > +++ gcc/cp/semantics.c        (working copy)
> | > > @@ -2852,7 +2852,8 @@ finish_id_expression (tree id_expression
> | > >         if (TREE_CODE (first_fn) == TEMPLATE_DECL)
> | > >           first_fn = DECL_TEMPLATE_RESULT (first_fn);
> | > >
> | > > -       if (!really_overloaded_fn (decl))
> | > > +       /* Recursive call does not count as usage.  */
> | > > +       if (!really_overloaded_fn (decl) && decl != current_function_decl)
> | > >           mark_used (first_fn);
> | > >
> | > >         if (!template_arg_p
> | >
> | > what about the other mark_used earlier on in that function:
> | >
> | >        if (scope)
> | >         {
> | >           decl = (adjust_result_of_qualified_name_lookup
> | >                   (decl, scope, current_class_type));
> | >
> | >           if (TREE_CODE (decl) == FUNCTION_DECL)
> | >             mark_used (decl);
> | >
> | > why not similarly protect that?  the other c++ bits are ok.
> | >
> | > nathan
> |
> | I could but I was not able to construct a case where it was necessary.
> | How can a static function make a scoped recursive call?
>                                    ^^^^^^^^^^^^^^^^^^^^
>
> I'm unclear about what you mean by that.
>

I mean, how can a recursive call of a static function can enter in the
condition guarded by 'if (scope)' ? Nathan provided an example. If you
have more examples, I would like to add them to the testcase.

Cheers,

Manuel.

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself
  2007-03-16 12:38       ` Nathan Sidwell
  2007-03-16 15:21         ` Gabriel Dos Reis
@ 2007-03-17  0:47         ` Manuel López-Ibáñez
  2007-03-19 12:16           ` Nathan Sidwell
  1 sibling, 1 reply; 13+ messages in thread
From: Manuel López-Ibáñez @ 2007-03-17  0:47 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: gcc-patches, Joseph Myers, Richard Henderson

On 16/03/07, Nathan Sidwell <nathan@codesourcery.com> wrote:
> Manuel López-Ibáñez wrote:
>
> > I could but I was not able to construct a case where it was necessary.
> > How can a static function make a scoped recursive call? Sorry my
> > knowledge of C++ is not so good.
>
> namespace { struct X { void Foo () { X::Foo (); }}}
>
> might just cut it.  Yes I know anonymous namespaces are not quite the same as
> static, and I don't know if we'll check this, but it seems wise to copy the
> idiom you've introduced.
>

I can copy the condition. Much better, I can put it inside mark_used
so we don't have to duplicate it everywhere. But still we cannot catch
the above case. We don't even catch

namespace {
    void foobar();
    void foobar() { return; }
}

It seems that check_global_declarations, which is the one that emits
the Wunused-function warnings, is not called for functions in an
anonymous namespace. I tried finding where the decision is made
without any success. Any ideas?

Manuel.

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static  function only called by itself
  2007-03-17  0:47         ` Manuel López-Ibáñez
@ 2007-03-19 12:16           ` Nathan Sidwell
  2007-03-24 17:23             ` Manuel López-Ibáñez
  0 siblings, 1 reply; 13+ messages in thread
From: Nathan Sidwell @ 2007-03-19 12:16 UTC (permalink / raw)
  To: Manuel López-Ibáñez
  Cc: gcc-patches, Joseph Myers, Richard Henderson

Manuel López-Ibáñez wrote:

> I can copy the condition. Much better, I can put it inside mark_used
> so we don't have to duplicate it everywhere. 

that seems a much better approach :)

> It seems that check_global_declarations, which is the one that emits
> the Wunused-function warnings, is not called for functions in an
> anonymous namespace. I tried finding where the decision is made
> without any success. Any ideas?

sorry, nothing comes to mind.  It is an orthogonal issue though, IMHO.

nathan
-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

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

* Re: [PING^2] [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself
  2007-03-19 12:16           ` Nathan Sidwell
@ 2007-03-24 17:23             ` Manuel López-Ibáñez
  2007-04-03 22:22               ` [PING^3] " Manuel López-Ibáñez
  0 siblings, 1 reply; 13+ messages in thread
From: Manuel López-Ibáñez @ 2007-03-24 17:23 UTC (permalink / raw)
  To: Nathan Sidwell; +Cc: gcc-patches, Joseph Myers, Richard Henderson

On 19/03/07, Nathan Sidwell <nathan@codesourcery.com> wrote:
> Manuel López-Ibáñez wrote:
>
> > I can copy the condition. Much better, I can put it inside mark_used
> > so we don't have to duplicate it everywhere.
>
> that seems a much better approach :)
>

Bad news. It produces ICE in:
libstdc++-v3/src/pool_allocator.cc:112: internal compiler error: in
build_call_a, at cp/call.c:325

 if (TREE_CODE (function) == ADDR_EXPR
      && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
    {
      decl = TREE_OPERAND (function, 0);
      if (!TREE_USED (decl))
        {
          /* We invoke build_call directly for several library
             functions.  These may have been declared normally if
             we're building libgcc, so we can't just check
             DECL_ARTIFICIAL.  */
          gcc_assert (DECL_ARTIFICIAL (decl)
                      || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
                                   "__", 2));
          mark_used (decl);
        }
    }

DECL_ARTIFICIAL is false and IDENTIFIER_POINTER (DECL_NAME (decl)) is
"_M_allocate_chunk"

Any ideas?


> > It seems that check_global_declarations, which is the one that emits
> > the Wunused-function warnings, is not called for functions in an
> > anonymous namespace. I tried finding where the decision is made
> > without any success. Any ideas?
>
> sorry, nothing comes to mind.  It is an orthogonal issue though, IMHO.
>

So what is the point in making my patch to worry about functions in
anonymous namespaces if anyway they are not equivalent to static with
respect to TREE_USED ? That is, no matter what my patch does, the
warning is not going to be emitted.

Cheers,
Manuel.

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

* [PING^3] [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself
  2007-03-24 17:23             ` Manuel López-Ibáñez
@ 2007-04-03 22:22               ` Manuel López-Ibáñez
  2007-04-09 10:44                 ` Nathan Sidwell
  0 siblings, 1 reply; 13+ messages in thread
From: Manuel López-Ibáñez @ 2007-04-03 22:22 UTC (permalink / raw)
  To: gcc-patches; +Cc: Nathan Sidwell

I ping my original patch:
http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00171.html
because it worked fine for its intended purpose. The only case for
which it seems it doesn't work is for functions inside of anonymous
namespaces. However, those are not considered static functions anyway
and -Wunused-function only warns for static functions. So no matter
what my patch does, they are not going to be used. Also, moving the
condition into mark_used causes a weird ICE.

An alternative would be to fix the issue in the C front-end and open a
new PR exclusively for the C++ front-end.

Cheers,

Manuel.

On 24/03/07, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
> On 19/03/07, Nathan Sidwell <nathan@codesourcery.com> wrote:
> > Manuel López-Ibáñez wrote:
> >
> > > I can copy the condition. Much better, I can put it inside mark_used
> > > so we don't have to duplicate it everywhere.
> >
> > that seems a much better approach :)
> >
>
> Bad news. It produces ICE in:
> libstdc++-v3/src/pool_allocator.cc:112: internal compiler error: in
> build_call_a, at cp/call.c:325
>
>  if (TREE_CODE (function) == ADDR_EXPR
>       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL)
>     {
>       decl = TREE_OPERAND (function, 0);
>       if (!TREE_USED (decl))
>         {
>           /* We invoke build_call directly for several library
>              functions.  These may have been declared normally if
>              we're building libgcc, so we can't just check
>              DECL_ARTIFICIAL.  */
>           gcc_assert (DECL_ARTIFICIAL (decl)
>                       || !strncmp (IDENTIFIER_POINTER (DECL_NAME (decl)),
>                                    "__", 2));
>           mark_used (decl);
>         }
>     }
>
> DECL_ARTIFICIAL is false and IDENTIFIER_POINTER (DECL_NAME (decl)) is
> "_M_allocate_chunk"
>
> Any ideas?
>
>
> > > It seems that check_global_declarations, which is the one that emits
> > > the Wunused-function warnings, is not called for functions in an
> > > anonymous namespace. I tried finding where the decision is made
> > > without any success. Any ideas?
> >
> > sorry, nothing comes to mind.  It is an orthogonal issue though, IMHO.
> >
>
> So what is the point in making my patch to worry about functions in
> anonymous namespaces if anyway they are not equivalent to static with
> respect to TREE_USED ? That is, no matter what my patch does, the
> warning is not going to be emitted.
>
> Cheers,
> Manuel.
>

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

* Re: [PING^3] [C/C++] PR c/4076 -Wunused doesn't warn about static  function only called by itself
  2007-04-03 22:22               ` [PING^3] " Manuel López-Ibáñez
@ 2007-04-09 10:44                 ` Nathan Sidwell
  0 siblings, 0 replies; 13+ messages in thread
From: Nathan Sidwell @ 2007-04-09 10:44 UTC (permalink / raw)
  To: Manuel López-Ibáñez; +Cc: gcc-patches

Manuel López-Ibáñez wrote:
> I ping my original patch:
> http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00171.html
> because it worked fine for its intended purpose. The only case for
> which it seems it doesn't work is for functions inside of anonymous
> namespaces. However, those are not considered static functions anyway
> and -Wunused-function only warns for static functions. So no matter
> what my patch does, they are not going to be used. Also, moving the
> condition into mark_used causes a weird ICE.
> 
> An alternative would be to fix the issue in the C front-end and open a
> new PR exclusively for the C++ front-end.

I'm taking a look at the assert issue

nathan
-- 
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

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

end of thread, other threads:[~2007-04-09 10:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-03 11:48 [C/C++] PR c/4076 -Wunused doesn't warn about static function only called by itself Manuel López-Ibáñez
2007-03-14 23:15 ` [PING^2] " Manuel López-Ibáñez
2007-03-15 10:17   ` Nathan Sidwell
2007-03-16 11:32     ` Manuel López-Ibáñez
2007-03-16 12:38       ` Nathan Sidwell
2007-03-16 15:21         ` Gabriel Dos Reis
2007-03-17  0:47         ` Manuel López-Ibáñez
2007-03-19 12:16           ` Nathan Sidwell
2007-03-24 17:23             ` Manuel López-Ibáñez
2007-04-03 22:22               ` [PING^3] " Manuel López-Ibáñez
2007-04-09 10:44                 ` Nathan Sidwell
2007-03-16 15:29       ` [PING^2] " Gabriel Dos Reis
2007-03-16 15:42         ` Manuel López-Ibáñez

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