Wunused-parameter warnings are given from cgraph::finalize_function, which is the middle-end. This is an oddity compared to other -Wunused-* warnings. Moreover, Fortran has its own definition of -Wunused-parameter that conflicts with the middle-end definition.
This patch moves the middle-end part of Wunused-parameter to the C/C++ FEs. I'm not sure if other FEs expected this warning to work. If so, they do not seem to test for it. Ada, for example, explicitly disables it. This also fixes [fortran/66605] -Wunused-parameter causes internal compiler error with gfortran 5.1.0. Bootstrapped & regression tested on x86_64-linux-gnu with languages c,c++,objc,fortran,ada,obj-c++ OK? gcc/ChangeLog: 2015-06-28 Manuel López-Ibáñez <m...@gcc.gnu.org> PR fortran/66605 * cgraphunit.c (cgraph_node::finalize_function): Do not call do_warn_unused_parameter. * function.c (do_warn_unused_parameter): Move from here. * function.h (do_warn_unused_parameter): Do not declare. gcc/c-family/ChangeLog: 2015-06-28 Manuel López-Ibáñez <m...@gcc.gnu.org> PR fortran/66605 * c-common.c (do_warn_unused_parameter): Move here. * c-common.h (do_warn_unused_parameter): Declare. gcc/ada/ChangeLog: 2015-06-28 Manuel López-Ibáñez <m...@gcc.gnu.org> PR fortran/66605 * gcc-interface/misc.c (gnat_post_options): No need to disable warn_unused_parameter anymore. gcc/cp/ChangeLog: 2015-06-28 Manuel López-Ibáñez <m...@gcc.gnu.org> PR fortran/66605 * decl.c (finish_function): Call do_warn_unused_parameter. gcc/testsuite/ChangeLog: 2015-06-28 Manuel López-Ibáñez <m...@gcc.gnu.org> PR fortran/66605 * gfortran.dg/wunused-parameter.f90: New test. gcc/c/ChangeLog: 2015-06-28 Manuel López-Ibáñez <m...@gcc.gnu.org> PR fortran/66605 * c-decl.c (finish_function): Call do_warn_unused_parameter.
Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 224997) +++ gcc/c-family/c-common.c (working copy) @@ -12045,10 +12045,27 @@ do_warn_double_promotion (tree result_ty else return; warning_at (loc, OPT_Wdouble_promotion, gmsgid, source_type, result_type); } +/* Possibly warn about unused parameters. */ + +void +do_warn_unused_parameter (tree fn) +{ + tree decl; + + for (decl = DECL_ARGUMENTS (fn); + decl; decl = DECL_CHAIN (decl)) + if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL + && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl) + && !TREE_NO_WARNING (decl)) + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wunused_parameter, + "unused parameter %qD", decl); +} + + /* Setup a TYPE_DECL node as a typedef representation. X is a TYPE_DECL for a typedef statement. Create a brand new ..._TYPE node (which will be just a variant of the existing ..._TYPE node with identical properties) and then install X Index: gcc/c-family/c-common.h =================================================================== --- gcc/c-family/c-common.h (revision 224997) +++ gcc/c-family/c-common.h (working copy) @@ -1041,10 +1041,11 @@ extern void warn_for_div_by_zero (locati extern void warn_for_sign_compare (location_t, tree orig_op0, tree orig_op1, tree op0, tree op1, tree result_type, enum tree_code resultcode); +extern void do_warn_unused_parameter (tree); extern void do_warn_double_promotion (tree, tree, tree, const char *, location_t); extern void set_underlying_type (tree); extern void record_types_used_by_current_var_decl (tree); extern void record_locally_defined_typedef (tree); Index: gcc/c/c-decl.c =================================================================== --- gcc/c/c-decl.c (revision 224997) +++ gcc/c/c-decl.c (working copy) @@ -9026,10 +9026,14 @@ finish_function (void) /* Complain about locally defined typedefs that are not used in this function. */ maybe_warn_unused_local_typedefs (); + /* Possibly warn about unused parameters. */ + if (warn_unused_parameter) + do_warn_unused_parameter (fndecl); + /* Store the end of the function, so that we get good line number info for the epilogue. */ cfun->function_end_locus = input_location; /* Finalize the ELF visibility for the function. */ Index: gcc/cgraphunit.c =================================================================== --- gcc/cgraphunit.c (revision 224997) +++ gcc/cgraphunit.c (working copy) @@ -470,14 +470,10 @@ cgraph_node::finalize_function (tree dec /* If we've not yet emitted decl, tell the debug info about it. */ if (!TREE_ASM_WRITTEN (decl)) (*debug_hooks->deferred_inline_function) (decl); - /* Possibly warn about unused parameters. */ - if (warn_unused_parameter) - do_warn_unused_parameter (decl); - if (!no_collect) ggc_collect (); if (symtab->state == CONSTRUCTION && (node->needed_p () || node->referred_to_p ())) Index: gcc/testsuite/gfortran.dg/wunused-parameter.f90 =================================================================== --- gcc/testsuite/gfortran.dg/wunused-parameter.f90 (revision 0) +++ gcc/testsuite/gfortran.dg/wunused-parameter.f90 (revision 0) @@ -0,0 +1,15 @@ +! { dg-do compile } +! { dg-options "-Wunused-parameter" } +! PR66605 +MODULE test + IMPLICIT NONE + INTEGER, PARAMETER :: wp = KIND(1.0D0) +CONTAINS +SUBROUTINE sub (neq, time, y, dydt) + IMPLICIT NONE + INTEGER :: neq + REAL(WP) :: time, y(neq), dydt(neq) + + dydt(1) = 1.0 / y(1) +END SUBROUTINE sub +END MODULE Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 224997) +++ gcc/cp/decl.c (working copy) @@ -14313,10 +14313,16 @@ finish_function (int flags) /* Complain about locally defined typedefs that are not used in this function. */ maybe_warn_unused_local_typedefs (); + /* Possibly warn about unused parameters. */ + if (warn_unused_parameter + && !processing_template_decl + && !DECL_CLONED_FUNCTION_P (fndecl)) + do_warn_unused_parameter (fndecl); + /* Genericize before inlining. */ if (!processing_template_decl) { struct language_function *f = DECL_SAVED_FUNCTION_DATA (fndecl); invoke_plugin_callbacks (PLUGIN_PRE_GENERICIZE, fndecl); Index: gcc/ada/gcc-interface/misc.c =================================================================== --- gcc/ada/gcc-interface/misc.c (revision 224997) +++ gcc/ada/gcc-interface/misc.c (working copy) @@ -259,13 +259,10 @@ gnat_post_options (const char **pfilenam if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD && TARGET_FLT_EVAL_METHOD_NON_DEFAULT) sorry ("-fexcess-precision=standard for Ada"); flag_excess_precision_cmdline = EXCESS_PRECISION_FAST; - /* ??? The warning machinery is outsmarted by Ada. */ - warn_unused_parameter = 0; - /* No psABI change warnings for Ada. */ warn_psabi = 0; /* No caret by default for Ada. */ if (!global_options_set.x_flag_diagnostics_show_caret) Index: gcc/function.c =================================================================== --- gcc/function.c (revision 224997) +++ gcc/function.c (working copy) @@ -5208,24 +5208,10 @@ static void 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 = DECL_CHAIN (decl)) - if (!TREE_USED (decl) && TREE_CODE (decl) == PARM_DECL - && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl) - && !TREE_NO_WARNING (decl)) - warning (OPT_Wunused_parameter, "unused parameter %q+D", decl); -} - /* Set the location of the insn chain starting at INSN to LOC. */ static void set_insn_locations (rtx_insn *insn, int loc) { Index: gcc/function.h =================================================================== --- gcc/function.h (revision 224997) +++ gcc/function.h (working copy) @@ -612,11 +612,10 @@ extern void expand_function_start (tree) extern void expand_dummy_function_end (void); extern void thread_prologue_and_epilogue_insns (void); extern void diddle_return_value (void (*)(rtx, void*), void*); extern void clobber_return_register (void); -extern void do_warn_unused_parameter (tree); extern void expand_function_end (void); extern rtx get_arg_pointer_save_area (void); extern void maybe_copy_prologue_epilogue_insn (rtx, rtx); extern int prologue_epilogue_contains (const_rtx); extern void emit_return_into_block (bool simple_p, basic_block bb);