From ad960f56f2e381290d1a83b0ee2f1d7b0e9d3a97 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Sat, 30 Jun 2007 12:56:43 +0000 Subject: [PATCH] re PR c/4076 (-Wunused doesn't warn about static function only called by itself.) 2007-06-30 Manuel Lopez-Ibanez 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. testsuite/ * gcc.dg/Wunused-function.c: New. From-SVN: r126144 --- gcc/ChangeLog | 7 +++++++ gcc/c-typeck.c | 10 +++++++--- gcc/calls.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/Wunused-function.c | 6 ++++++ 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/Wunused-function.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7a9af4b229b..104942acd59 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2007-06-30 Manuel Lopez-Ibanez + + 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. + 2007-06-30 Richard Sandiford Revert: diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 2a19f0875fb..0793b6005ac 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -2090,9 +2090,13 @@ build_external_ref (tree id, int fun, location_t loc) 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) { diff --git a/gcc/calls.c b/gcc/calls.c index 868edfc396d..aa63755d26d 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1493,7 +1493,7 @@ rtx_for_function_call (tree fndecl, tree addr) { /* 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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e848e23f05b..5367e3f1028 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-06-30 Manuel Lopez-Ibanez + + PR c/4076 + * gcc.dg/Wunused-function.c: New. + 2007-06-29 Jerry DeLisle * gfortran.fortran-torture/compile/inline_1.f90: Fix test. diff --git a/gcc/testsuite/gcc.dg/Wunused-function.c b/gcc/testsuite/gcc.dg/Wunused-function.c new file mode 100644 index 00000000000..1c59c50038b --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wunused-function.c @@ -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" } */ -- 2.30.2