From 4ed44cccdd2243a585cd3beb4bb3fbe616e7d156 Mon Sep 17 00:00:00 2001 From: Daniel Franke Date: Thu, 20 May 2010 17:49:07 -0400 Subject: re PR fortran/38407 (Wishlist: -Wunused-dummy-argument and -Wno-unused-dummy-argument) gcc/fortran/: 2010-05-20 Daniel Franke PR fortran/38407 * lang.opt (Wunused-dummy-argument): New option. * gfortran.h (gfc_option_t): Add warn_unused_dummy_argument. * options.c (gfc_init_options): Disable warn_unused_dummy_argument. (set_Wall): Enable warn_unused_dummy_argument. (gfc_handle_option): Set warn_unused_dummy_argument according to command line. * trans-decl.c (generate_local_decl): Separate warnings about unused variables and unused dummy arguments. * invoke.texi: Documented new option. gcc/testsuite/: 2010-05-20 Daniel Franke PR fortran/38407 * warn_unused_dummy_argument_1.f90: New. * warn_unused_dummy_argument_2.f90: New. From-SVN: r159641 --- gcc/fortran/ChangeLog | 13 ++++++++ gcc/fortran/gfortran.h | 1 + gcc/fortran/invoke.texi | 16 +++++++--- gcc/fortran/lang.opt | 4 +++ gcc/fortran/options.c | 6 ++++ gcc/fortran/trans-decl.c | 37 ++++++++++++---------- gcc/testsuite/ChangeLog | 6 ++++ .../gfortran.dg/warn_unused_dummy_argument_1.f90 | 10 ++++++ .../gfortran.dg/warn_unused_dummy_argument_2.f90 | 10 ++++++ 9 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/warn_unused_dummy_argument_1.f90 create mode 100644 gcc/testsuite/gfortran.dg/warn_unused_dummy_argument_2.f90 (limited to 'gcc') diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index a531b27..6e139cc 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,16 @@ +2010-05-20 Daniel Franke + + PR fortran/38407 + * lang.opt (Wunused-dummy-argument): New option. + * gfortran.h (gfc_option_t): Add warn_unused_dummy_argument. + * options.c (gfc_init_options): Disable warn_unused_dummy_argument. + (set_Wall): Enable warn_unused_dummy_argument. + (gfc_handle_option): Set warn_unused_dummy_argument according to + command line. + * trans-decl.c (generate_local_decl): Separate warnings about + unused variables and unused dummy arguments. + * invoke.texi: Documented new option. + 2010-05-20 Steven Bosscher * trans-expr.c: Do not include convert.h, ggc.h, real.h, and gimple.h. diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 15f2728..ec334c5 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2117,6 +2117,7 @@ typedef struct int warn_character_truncation; int warn_array_temp; int warn_align_commons; + int warn_unused_dummy_argument; int max_errors; int flag_all_intrinsics; diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi index 1b14cef..78c1c43 100644 --- a/gcc/fortran/invoke.texi +++ b/gcc/fortran/invoke.texi @@ -690,7 +690,8 @@ Enables commonly used warning options pertaining to usage that we recommend avoiding and that we believe are easy to avoid. This currently includes @option{-Waliasing}, @option{-Wampersand}, @option{-Wconversion}, @option{-Wsurprising}, @option{-Wintrinsics-std}, -@option{-Wno-tabs}, @option{-Wintrinsic-shadow} and @option{-Wline-truncation}. +@option{-Wno-tabs}, @option{-Wintrinsic-shadow}, @option{-Wline-truncation}, +and @option{-Wunused}. @item -Waliasing @opindex @code{Waliasing} @@ -832,15 +833,22 @@ intrinsic; in this case, an explicit interface or @code{EXTERNAL} or @code{INTRINSIC} declaration might be needed to get calls later resolved to the desired intrinsic/procedure. +@item -Wunused-dummy-argument +@opindex @code{Wunused-dummy-argument} +@cindex warnings, unused dummy argument +@cindex unused dummy argument +@cindex dummy argument, unused +Warn about unused dummy arguments. This option is implied by @option{-Wall}. + @item -Wunused-parameter @opindex @code{Wunused-parameter} @cindex warnings, unused parameter @cindex unused parameter Contrary to @command{gcc}'s meaning of @option{-Wunused-parameter}, @command{gfortran}'s implementation of this option does not warn -about unused dummy arguments, but about unused @code{PARAMETER} values. -@option{-Wunused-parameter} is not included in @option{-Wall} but is -implied by @option{-Wall -Wextra}. +about unused dummy arguments (see @option{-Wunused-dummy-argument}), +but about unused @code{PARAMETER} values. @option{-Wunused-parameter} +is not included in @option{-Wall} but is implied by @option{-Wall -Wextra}. @item -Walign-commons @opindex @code{Walign-commons} diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 57ac429..c1a86dd 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -132,6 +132,10 @@ Wintrinsic-shadow Fortran Warning Warn if a user-procedure has the same name as an intrinsic +Wunused-dummy-argument +Fortran Warning +Warn about unused dummy arguments. + cpp Fortran Joined Separate Negative(nocpp) Enable preprocessing diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 365b326..a5c0b92 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -87,6 +87,7 @@ gfc_init_options (unsigned int argc, const char **argv) gfc_option.warn_intrinsic_shadow = 0; gfc_option.warn_intrinsics_std = 0; gfc_option.warn_align_commons = 1; + gfc_option.warn_unused_dummy_argument = 0; gfc_option.max_errors = 25; gfc_option.flag_all_intrinsics = 0; @@ -417,6 +418,7 @@ set_Wall (int setting) gfc_option.warn_intrinsic_shadow = setting; gfc_option.warn_intrinsics_std = setting; gfc_option.warn_character_truncation = setting; + gfc_option.warn_unused_dummy_argument = setting; warn_unused = setting; warn_return_type = setting; @@ -616,6 +618,10 @@ gfc_handle_option (size_t scode, const char *arg, int value, gfc_option.warn_align_commons = value; break; + case OPT_Wunused_dummy_argument: + gfc_option.warn_unused_dummy_argument = value; + break; + case OPT_fall_intrinsics: gfc_option.flag_all_intrinsics = 1; break; diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index 5afc5f4..5bafdcc 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -3878,24 +3878,29 @@ generate_local_decl (gfc_symbol * sym) if (sym->attr.referenced) gfc_get_symbol_decl (sym); - /* INTENT(out) dummy arguments are likely meant to be set. */ - else if (warn_unused_variable - && sym->attr.dummy - && sym->attr.intent == INTENT_OUT) + + /* Warnings for unused dummy arguments. */ + else if (sym->attr.dummy) { - if (sym->ts.type != BT_DERIVED) - gfc_warning ("Dummy argument '%s' at %L was declared INTENT(OUT) " - "but was not set", sym->name, &sym->declared_at); - else if (!gfc_has_default_initializer (sym->ts.u.derived)) - gfc_warning ("Derived-type dummy argument '%s' at %L was " - "declared INTENT(OUT) but was not set and does " - "not have a default initializer", - sym->name, &sym->declared_at); + /* INTENT(out) dummy arguments are likely meant to be set. */ + if (gfc_option.warn_unused_dummy_argument + && sym->attr.intent == INTENT_OUT) + { + if (sym->ts.type != BT_DERIVED) + gfc_warning ("Dummy argument '%s' at %L was declared " + "INTENT(OUT) but was not set", sym->name, + &sym->declared_at); + else if (!gfc_has_default_initializer (sym->ts.u.derived)) + gfc_warning ("Derived-type dummy argument '%s' at %L was " + "declared INTENT(OUT) but was not set and " + "does not have a default initializer", + sym->name, &sym->declared_at); + } + else if (gfc_option.warn_unused_dummy_argument) + gfc_warning ("Unused dummy argument '%s' at %L", sym->name, + &sym->declared_at); } - /* Specific warning for unused dummy arguments. */ - else if (warn_unused_variable && sym->attr.dummy) - gfc_warning ("Unused dummy argument '%s' at %L", sym->name, - &sym->declared_at); + /* Warn for unused variables, but not if they're inside a common block or are use-associated. */ else if (warn_unused_variable diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d4c10f3..77bc135 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2010-05-20 Daniel Franke + + PR fortran/38407 + * warn_unused_dummy_argument_1.f90: New. + * warn_unused_dummy_argument_2.f90: New. + 2010-05-20 Paolo Carlini PR c++/30298 diff --git a/gcc/testsuite/gfortran.dg/warn_unused_dummy_argument_1.f90 b/gcc/testsuite/gfortran.dg/warn_unused_dummy_argument_1.f90 new file mode 100644 index 0000000..94e74c9 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/warn_unused_dummy_argument_1.f90 @@ -0,0 +1,10 @@ +! { dg-do "compile" } +! { dg-options "-Wall" } +! +! PR fortran/38407 +! + +SUBROUTINE s(dummy) ! { dg-warning "Unused dummy" } + INTEGER, INTENT(in) :: dummy + INTEGER :: variable ! { dg-warning "Unused variable" } +END SUBROUTINE diff --git a/gcc/testsuite/gfortran.dg/warn_unused_dummy_argument_2.f90 b/gcc/testsuite/gfortran.dg/warn_unused_dummy_argument_2.f90 new file mode 100644 index 0000000..85472dd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/warn_unused_dummy_argument_2.f90 @@ -0,0 +1,10 @@ +! { dg-do "compile" } +! { dg-options "-Wall -Wno-unused-dummy-argument" } +! +! PR fortran/38407 +! + +SUBROUTINE s(dummy) + INTEGER, INTENT(in) :: dummy + INTEGER :: variable ! { dg-warning "Unused variable" } +END SUBROUTINE -- cgit v1.1