[Bug c/4076] -Wunused doesn't warn about static function only called by itself.

manu at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sat Jan 27 15:47:00 GMT 2007



------- Comment #5 from manu at gcc dot gnu dot org  2007-01-27 15:46 -------
Anyway, here is my current patch, perhaps someone can find some use for it:

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/c-typeck.c
===================================================================
--- gcc/c-typeck.c      (revision 121039)
+++ 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 calls 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 121039)
+++ gcc/calls.c (working copy)
@@ -1449,7 +1449,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;


-- 


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



More information about the Gcc-bugs mailing list