From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25882 invoked by alias); 27 Jan 2007 15:47:06 -0000 Received: (qmail 25792 invoked by uid 48); 27 Jan 2007 15:46:57 -0000 Date: Sat, 27 Jan 2007 15:47:00 -0000 Message-ID: <20070127154657.25791.qmail@sourceware.org> X-Bugzilla-Reason: CC References: Subject: [Bug c/4076] -Wunused doesn't warn about static function only called by itself. In-Reply-To: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "manu at gcc dot gnu dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2007-01/txt/msg02351.txt.bz2 ------- 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