Commit fba5ace0 by Tobias Burnus

re PR fortran/50923 (No warning if function return value is not set)

2011-12-11  Tobias Burnus  <burnus@net-b.de>

        PR fortran/50923
        * trans-decl.c (generate_local_decl): Set TREE_NO_WARNING only
        if the front end has printed a warning.
        (gfc_generate_function_code): Fix unset-result warning.

2011-12-11  Tobias Burnus  <burnus@net-b.de>

        PR fortran/50923
        * gfortran.dg/warn_function_without_result_2.f90: New.

From-SVN: r182211
parent c49ea23d
2011-12-11 Tobias Burnus <burnus@net-b.de>
PR fortran/50923
* trans-decl.c (generate_local_decl): Set TREE_NO_WARNING only
if the front end has printed a warning.
(gfc_generate_function_code): Fix unset-result warning.
2011-12-11 Paul Thomas <pault@gcc.gnu.org> 2011-12-11 Paul Thomas <pault@gcc.gnu.org>
Tobias Burnus <burnus@gcc.gnu.org> Tobias Burnus <burnus@gcc.gnu.org>
...@@ -24,7 +31,7 @@ ...@@ -24,7 +31,7 @@
elemental procedure call retain the ss to provide the elemental procedure call retain the ss to provide the
scalarized array reference. Moved in file. scalarized array reference. Moved in file.
(gfc_conv_class_to_class): New function. (gfc_conv_class_to_class): New function.
(gfc_conv_subref_array_arg): Use the type of the (gfc_conv_subref_array_arg): Use the type of the
class _data component as a basetype. class _data component as a basetype.
(gfc_conv_procedure_call): Ensure that class array expressions (gfc_conv_procedure_call): Ensure that class array expressions
have both the _data reference and an array reference. Use have both the _data reference and an array reference. Use
......
...@@ -4544,10 +4544,16 @@ generate_local_decl (gfc_symbol * sym) ...@@ -4544,10 +4544,16 @@ generate_local_decl (gfc_symbol * sym)
"declared INTENT(OUT) but was not set and " "declared INTENT(OUT) but was not set and "
"does not have a default initializer", "does not have a default initializer",
sym->name, &sym->declared_at); sym->name, &sym->declared_at);
if (sym->backend_decl != NULL_TREE)
TREE_NO_WARNING(sym->backend_decl) = 1;
} }
else if (gfc_option.warn_unused_dummy_argument) else if (gfc_option.warn_unused_dummy_argument)
gfc_warning ("Unused dummy argument '%s' at %L", sym->name, {
gfc_warning ("Unused dummy argument '%s' at %L", sym->name,
&sym->declared_at); &sym->declared_at);
if (sym->backend_decl != NULL_TREE)
TREE_NO_WARNING(sym->backend_decl) = 1;
}
} }
/* Warn for unused variables, but not if they're inside a common /* Warn for unused variables, but not if they're inside a common
...@@ -4555,11 +4561,19 @@ generate_local_decl (gfc_symbol * sym) ...@@ -4555,11 +4561,19 @@ generate_local_decl (gfc_symbol * sym)
else if (warn_unused_variable else if (warn_unused_variable
&& !(sym->attr.in_common || sym->attr.use_assoc || sym->mark && !(sym->attr.in_common || sym->attr.use_assoc || sym->mark
|| sym->attr.in_namelist)) || sym->attr.in_namelist))
gfc_warning ("Unused variable '%s' declared at %L", sym->name, {
&sym->declared_at); gfc_warning ("Unused variable '%s' declared at %L", sym->name,
&sym->declared_at);
if (sym->backend_decl != NULL_TREE)
TREE_NO_WARNING(sym->backend_decl) = 1;
}
else if (warn_unused_variable && sym->attr.use_only) else if (warn_unused_variable && sym->attr.use_only)
gfc_warning ("Unused module variable '%s' which has been explicitly " {
"imported at %L", sym->name, &sym->declared_at); gfc_warning ("Unused module variable '%s' which has been explicitly "
"imported at %L", sym->name, &sym->declared_at);
if (sym->backend_decl != NULL_TREE)
TREE_NO_WARNING(sym->backend_decl) = 1;
}
/* For variable length CHARACTER parameters, the PARM_DECL already /* For variable length CHARACTER parameters, the PARM_DECL already
references the length variable, so force gfc_get_symbol_decl references the length variable, so force gfc_get_symbol_decl
...@@ -4595,11 +4609,6 @@ generate_local_decl (gfc_symbol * sym) ...@@ -4595,11 +4609,6 @@ generate_local_decl (gfc_symbol * sym)
mark the symbol now, as well as in traverse_ns, to prevent mark the symbol now, as well as in traverse_ns, to prevent
getting stuck in a circular dependency. */ getting stuck in a circular dependency. */
sym->mark = 1; sym->mark = 1;
/* 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;
} }
else if (sym->attr.flavor == FL_PARAMETER) else if (sym->attr.flavor == FL_PARAMETER)
{ {
...@@ -5323,11 +5332,11 @@ gfc_generate_function_code (gfc_namespace * ns) ...@@ -5323,11 +5332,11 @@ gfc_generate_function_code (gfc_namespace * ns)
if (result == NULL_TREE) if (result == NULL_TREE)
{ {
/* TODO: move to the appropriate place in resolve.c. */ /* TODO: move to the appropriate place in resolve.c. */
if (warn_return_type && !sym->attr.referenced && sym == sym->result) if (warn_return_type && sym == sym->result)
gfc_warning ("Return value of function '%s' at %L not set", gfc_warning ("Return value of function '%s' at %L not set",
sym->name, &sym->declared_at); sym->name, &sym->declared_at);
if (warn_return_type)
TREE_NO_WARNING(sym->backend_decl) = 1; TREE_NO_WARNING(sym->backend_decl) = 1;
} }
else else
gfc_add_expr_to_block (&body, gfc_generate_return ()); gfc_add_expr_to_block (&body, gfc_generate_return ());
......
2011-12-11 Tobias Burnus <burnus@net-b.de>
PR fortran/50923
* gfortran.dg/warn_function_without_result_2.f90: New.
2011-12-11 Paul Thomas <pault@gcc.gnu.org> 2011-12-11 Paul Thomas <pault@gcc.gnu.org>
Tobias Burnus <burnus@gcc.gnu.org> Tobias Burnus <burnus@gcc.gnu.org>
......
! { dg-do compile }
! { dg-options "-Wall" }
!
! PR fortran/50923
!
module m
contains
integer pure function f() ! { dg-warning "Return value of function 'f' at .1. not set" }
end function f
integer pure function g() result(h) ! { dg-warning "Return value 'h' of function 'g' declared at .1. not set" }
end function g
integer pure function i()
i = 7
end function i
integer pure function j() result(k)
k = 8
end function j
end module m
! { dg-final { cleanup-modules "mod" } }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment