This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch, fortran] PR24784, PR28004 - about unused variables
- From: Daniel Franke <franke dot daniel at gmail dot com>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Wed, 4 Jul 2007 07:57:50 +0200
- Subject: [patch, fortran] PR24784, PR28004 - about unused variables
Depending on the command-line arguments -Wall and -Wextra, gfortran gives
different kinds of warnings for unused dummy arguments. In addition,
sometimes the middle-end chimes in and emits a default warning as well
(PR27484). Further, PR28004 requests a warning if dummy arguments of
INTENT(out) are not set.
This patch addresses all this in a single sweep, the corrected warnings are
emitted on -Wall regardless of -Wextra (via warn_unused_variable). The
changes should be self explanatory, those in function.c probably need to be
approved by a C- or global maintainer?!
Example:
SUBROUTINE f(i)
INTEGER, INTENT(out) :: i
END SUBROUTINE
before (-Wall):
Warning: Unused variable i declared at (1)
before (-Wall -Wextra):
Warning: Unused parameter i declared at (1)
function.f90:3: warning: unused parameter 'i'
after (-Wall, -Wall -Wextra):
Warning: dummy argument 'i' at (1) was declared INTENT(OUT) but was not set
SUBROUTINE g(i)
INTEGER :: i
END SUBROUTINE
before, same as above
after: Warning: unused dummy argument 'i' at (1)
:ADDPATCH fortran:
gcc:
2007-07-04 Daniel Franke <franke.daniel@gmail.com>
* function.c (do_warn_unused_parameter): Do not warn if TREE_NO_WARNING is
set.
gcc/fortran:
2007-07-04 Daniel Franke <franke.daniel@gmail.com>
PR fortran/24784
PR fortran/28004
* trans-decl.c (generate_local_decl): Adjusted warning on unused
dummy arguments, tell middle-end not to emit additional warnings.
Bootstrapped and regtested c and fortran on i686-pc-linux-gnu.
Ok for trunk?
Regards
Daniel
Index: function.c
===================================================================
--- function.c (revision 126214)
+++ function.c (working copy)
@@ -4287,7 +4287,8 @@
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))
+ && DECL_NAME (decl) && !DECL_ARTIFICIAL (decl)
+ && !TREE_NO_WARNING (decl))
warning (OPT_Wunused_parameter, "unused parameter %q+D", decl);
}
Index: fortran/trans-decl.c
===================================================================
--- fortran/trans-decl.c (revision 126214)
+++ fortran/trans-decl.c (working copy)
@@ -2999,14 +2999,21 @@
if (sym->attr.referenced)
gfc_get_symbol_decl (sym);
- else if (sym->attr.dummy && warn_unused_parameter)
- gfc_warning ("Unused parameter %s declared at %L", sym->name,
+ /* INTENT(out) dummy arguments are likely meant to be set. */
+ else if (warn_unused_variable
+ && sym->attr.dummy
+ && sym->attr.intent == INTENT_OUT)
+ gfc_warning ("dummy argument '%s' at %L was declared INTENT(OUT) but was not set",
+ 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
&& !(sym->attr.in_common || sym->attr.use_assoc))
- gfc_warning ("Unused variable %s declared at %L", sym->name,
+ gfc_warning ("unused variable '%s' declared at %L", sym->name,
&sym->declared_at);
/* For variable length CHARACTER parameters, the PARM_DECL already
references the length variable, so force gfc_get_symbol_decl
@@ -3021,6 +3028,11 @@
sym->attr.referenced = 1;
gfc_get_symbol_decl (sym);
}
+
+ /* We do not want the middle-end to warn about unused parameters
+ as this was already done above. */
+ if (sym->attr.dummy && sym->backend_decl != NULL_TREE)
+ TREE_NO_WARNING(sym->backend_decl) = 1;
}
if (sym->attr.dummy == 1)