From da2e71c999f964c6b76581d8dd96c8f9bc48624d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Mon, 29 Jun 2015 16:25:26 +0000 Subject: [PATCH] Wunused-parameter warnings are given from cgraph::finalize_function, MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. gcc/ChangeLog: 2015-06-29 Manuel López-Ibáñez 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-29 Manuel López-Ibáñez 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-29 Manuel López-Ibáñez PR fortran/66605 * gcc-interface/misc.c (gnat_post_options): No need to disable warn_unused_parameter anymore. gcc/cp/ChangeLog: 2015-06-29 Manuel López-Ibáñez PR fortran/66605 * decl.c (finish_function): Call do_warn_unused_parameter. gcc/testsuite/ChangeLog: 2015-06-29 Manuel López-Ibáñez PR fortran/66605 * gfortran.dg/wunused-parameter.f90: New test. gcc/c/ChangeLog: 2015-06-29 Manuel López-Ibáñez PR fortran/66605 * c-decl.c (finish_function): Call do_warn_unused_parameter. From-SVN: r225135 --- gcc/ChangeLog | 8 ++++++++ gcc/ada/ChangeLog | 6 ++++++ gcc/ada/gcc-interface/misc.c | 3 --- gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-common.c | 17 +++++++++++++++++ gcc/c-family/c-common.h | 1 + gcc/c/ChangeLog | 5 +++++ gcc/c/c-decl.c | 4 ++++ gcc/cgraphunit.c | 4 ---- gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 6 ++++++ gcc/function.c | 14 -------------- gcc/function.h | 1 - gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gfortran.dg/wunused-parameter.f90 | 15 +++++++++++++++ 15 files changed, 78 insertions(+), 22 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/wunused-parameter.f90 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index fd533ab464f..0de1eadae55 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-06-29 Manuel López-Ibáñez + + 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. + 2015-06-29 Matthew Wahab PR target/65697 diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 89d8898e58d..97e293dec12 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,9 @@ +2015-06-29 Manuel López-Ibáñez + + PR fortran/66605 + * gcc-interface/misc.c (gnat_post_options): No need to disable + warn_unused_parameter anymore. + 2015-06-26 Eric Botcazou * gcc-interface/trans.c (Handled_Sequence_Of_Statements_to_gnu): When diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c index 2f397ba1fe7..fec71999ac3 100644 --- a/gcc/ada/gcc-interface/misc.c +++ b/gcc/ada/gcc-interface/misc.c @@ -262,9 +262,6 @@ gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED) 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; diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 2d6e3c5ec2a..0e03e7e87d0 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2015-06-29 Manuel López-Ibáñez + + PR fortran/66605 + * c-common.c (do_warn_unused_parameter): Move here. + * c-common.h (do_warn_unused_parameter): Declare. + 2015-06-29 Marek Polacek PR c/66322 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 8156d6a1e2a..ac42e4aea9a 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -12103,6 +12103,23 @@ do_warn_double_promotion (tree result_type, tree type1, tree type2, 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 diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 2b03703af86..dd9839682c2 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -1045,6 +1045,7 @@ extern void warn_for_sign_compare (location_t, 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); diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 2c5ba6db6a4..15c2303c2de 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2015-06-29 Manuel López-Ibáñez + + PR fortran/66605 + * c-decl.c (finish_function): Call do_warn_unused_parameter. + 2015-06-29 Marek Polacek PR c/66322 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 6aac8c36157..383f0a766bf 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -9028,6 +9028,10 @@ finish_function (void) 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; diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index 1b356467b72..7e78bf78915 100644 --- a/gcc/cgraphunit.c +++ b/gcc/cgraphunit.c @@ -472,10 +472,6 @@ cgraph_node::finalize_function (tree decl, bool no_collect) 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 (); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c16b068f8f2..aad780f6aea 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2015-06-29 Manuel López-Ibáñez + + PR fortran/66605 + * decl.c (finish_function): Call do_warn_unused_parameter. + 2015-06-29 Marek Polacek PR c/66322 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 498ed71bcf9..3f1cd340e16 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -14323,6 +14323,12 @@ finish_function (int flags) 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) { diff --git a/gcc/function.c b/gcc/function.c index 4389bbd1aba..de0b38fe52a 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -5210,20 +5210,6 @@ 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 diff --git a/gcc/function.h b/gcc/function.h index dc4a8cc7c0f..e92c17c6fcc 100644 --- a/gcc/function.h +++ b/gcc/function.h @@ -614,7 +614,6 @@ 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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3163ba6305e..b4e9732fc0b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-06-29 Manuel López-Ibáñez + + PR fortran/66605 + * gfortran.dg/wunused-parameter.f90: New test. + 2015-06-29 Richard Henderson * gcc.target/i386/asm-flag-1.c: New. diff --git a/gcc/testsuite/gfortran.dg/wunused-parameter.f90 b/gcc/testsuite/gfortran.dg/wunused-parameter.f90 new file mode 100644 index 00000000000..df39af8aa57 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/wunused-parameter.f90 @@ -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 -- 2.30.2