From 902edd367b9d585a610eabdad8110a188effd707 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Wed, 28 Apr 2004 22:40:55 +0200 Subject: [PATCH] re PR c/15004 ([unit-at-a-time] no warning for unused paramater in static function) * gcc.dg/unused-6.c: New test. PR c/15004 * function.c (do_warn_unused_parameter): Break out form ... (expand_function_end): ... here; warn only when not using cgraphunit. * function.h (do_warn_unused_parameter): Declare. * cgraphunit.c: Include function.h. (cgraph_finalize_function): Do unused parameter warning. * Makefile.in (cgraphunit.o): Depend on function.h From-SVN: r81260 --- gcc/ChangeLog | 10 ++++++++++ gcc/Makefile.in | 3 ++- gcc/cgraphunit.c | 5 +++++ gcc/function.c | 30 +++++++++++++++++++----------- gcc/function.h | 2 ++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/unused-6.c | 11 +++++++++++ 7 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/unused-6.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 72cdbcbd540..cc665a4d1d6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2004-04-28 Jan Hubicka + + PR c/15004 + * function.c (do_warn_unused_parameter): Break out form ... + (expand_function_end): ... here; warn only when not using cgraphunit. + * function.h (do_warn_unused_parameter): Declare. + * cgraphunit.c: Include function.h. + (cgraph_finalize_function): Do unused parameter warning. + * Makefile.in (cgraphunit.o): Depend on function.h + 2004-04-28 Joseph S. Myers * Makefile.in ($(DESTDIR)$(infodir)/%.info): Don't condition diff --git a/gcc/Makefile.in b/gcc/Makefile.in index e2d74e73678..b35159b0be6 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1660,7 +1660,8 @@ cgraph.o : cgraph.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ langhooks.h toplev.h flags.h $(GGC_H) $(TARGET_H) cgraph.h gt-cgraph.h \ output.h intl.h cgraphunit.o : cgraphunit.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \ - langhooks.h tree-inline.h toplev.h flags.h $(GGC_H) $(TARGET_H) cgraph.h intl.h + langhooks.h tree-inline.h toplev.h flags.h $(GGC_H) $(TARGET_H) cgraph.h intl.h \ + function.h coverage.o : coverage.c gcov-io.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ $(TM_H) $(RTL_H) $(TREE_H) flags.h output.h $(REGS_H) $(EXPR_H) function.h \ toplev.h $(GGC_H) $(TARGET_H) langhooks.h $(COVERAGE_H) libfuncs.h \ diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 7495a7595e5..4bdd41a5aa9 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -183,6 +183,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA #include "fibheap.h" #include "c-common.h" #include "intl.h" +#include "function.h" #define INSNS_PER_CALL 10 @@ -377,6 +378,10 @@ cgraph_finalize_function (tree decl, bool nested) early then. */ if (DECL_EXTERNAL (decl)) DECL_STRUCT_FUNCTION (decl) = NULL; + + /* Possibly warn about unused parameters. */ + if (warn_unused_parameter) + do_warn_unused_parameter (decl); } /* Walk tree and record all calls. Called via walk_tree. */ diff --git a/gcc/function.c b/gcc/function.c index 69f9b8f568b..b1f888f141f 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -6919,6 +6919,19 @@ use_return_register (void) diddle_return_value (do_use_return_reg, NULL); } +/* Possibly warn about unused parameters. */ +void +do_warn_unused_parameter (tree fn) +{ + tree decl; + + for (decl = DECL_ARGUMENTS (fn); + decl; decl = TREE_CHAIN (decl)) + if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL + && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)) + warning ("%Junused parameter '%D'", decl, decl); +} + static GTY(()) rtx initial_trampoline; /* Generate RTL for the end of the current function. */ @@ -7007,17 +7020,12 @@ expand_function_end (void) } } - /* Possibly warn about unused parameters. */ - if (warn_unused_parameter) - { - tree decl; - - for (decl = DECL_ARGUMENTS (current_function_decl); - decl; decl = TREE_CHAIN (decl)) - if (! TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL - && DECL_NAME (decl) && ! DECL_ARTIFICIAL (decl)) - warning ("%Junused parameter '%D'", decl, decl); - } + /* Possibly warn about unused parameters. + When frontend does unit-at-a-time, the warning is already + issued at finalization time. */ + if (warn_unused_parameter + && !lang_hooks.callgraph.expand_function) + do_warn_unused_parameter (current_function_decl); /* Delete handlers for nonlocal gotos if nothing uses them. */ if (nonlocal_goto_handler_slots != 0 diff --git a/gcc/function.h b/gcc/function.h index 2c3a847cb58..7e34633d848 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -648,4 +648,6 @@ extern const char *current_function_name (void); /* Called once, at initialization, to initialize function.c. */ extern void init_function_once (void); +extern void do_warn_unused_parameter (tree); + #endif /* GCC_FUNCTION_H */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 47fdd8aad44..1de727de43e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2004-04-28 Jan Hubicka + + * gcc.dg/unused-6.c: New test. + 2004-04-24 Laurent GUERBY Ulrich Weigand diff --git a/gcc/testsuite/gcc.dg/unused-6.c b/gcc/testsuite/gcc.dg/unused-6.c new file mode 100644 index 00000000000..7651ecb28c9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/unused-6.c @@ -0,0 +1,11 @@ + +/* { dg-do compile } */ +/* { dg-options "-O3 -Wunused-parameter" } */ +static int t(int i) /* { dg-warning "unused parameter" "unused parameter warning" } */ +{ + return 0; +} +int tt() +{ + return t(0); +} -- 2.30.2