diff options
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/fortran/lang.opt | 4 | ||||
-rw-r--r-- | gcc/fortran/options.c | 4 | ||||
-rw-r--r-- | gcc/fortran/trans-decl.c | 40 |
4 files changed, 55 insertions, 6 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 2082054..20e5ae3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,16 @@ +2008-02-28 Daniel Franke <franke.daniel@gmail.com> + + PR fortran/31463 + PR fortran/33950 + PR fortran/34296 + * lang.opt: Added -Wreturn-type. + * options.c (gfc_handle_option): Recognize -Wreturn-type. + * trans-decl.c (gfc_trans_deferred_vars): Emit warnings for funtions + where the result value is not set. + (gfc_generate_function_code): Likewise. + (generate_local_decl): Emit warnings for funtions whose RESULT + variable is not set. + 2008-02-28 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org> PR fortran/34868 diff --git a/gcc/fortran/lang.opt b/gcc/fortran/lang.opt index 967f634..16db192 100644 --- a/gcc/fortran/lang.opt +++ b/gcc/fortran/lang.opt @@ -65,6 +65,10 @@ Wnonstd-intrinsics Fortran Warning Warn about usage of non-standard intrinsics +Wreturn-type +Fortran Warning +; Documented in C + Wsurprising Fortran Warning Warn about \"suspicious\" constructs diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index 7d35fb7..ecab0c5 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -492,6 +492,10 @@ gfc_handle_option (size_t scode, const char *arg, int value) gfc_option.warn_line_truncation = value; break; + case OPT_Wreturn_type: + warn_return_type = value; + break; + case OPT_Wsurprising: gfc_option.warn_surprising = value; break; diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index bf07a88..6f430cb 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -2607,8 +2607,10 @@ gfc_trans_deferred_vars (gfc_symbol * proc_sym, tree fnbody) if (el->sym != el->sym->result) break; } - if (el == NULL) - warning (0, "Function does not return a value"); + /* TODO: move to the appropriate place in resolve.c. */ + if (warn_return_type && el == NULL) + gfc_warning ("Return value of function '%s' at %L not set", + proc_sym->name, &proc_sym->declared_at); } else if (proc_sym->as) { @@ -2952,7 +2954,7 @@ generate_local_decl (gfc_symbol * sym) /* 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)) + && !(sym->attr.in_common || sym->attr.use_assoc || sym->mark)) gfc_warning ("Unused variable '%s' declared at %L", sym->name, &sym->declared_at); /* For variable length CHARACTER parameters, the PARM_DECL already @@ -2982,6 +2984,25 @@ generate_local_decl (gfc_symbol * sym) gfc_warning ("Unused parameter '%s' declared at %L", sym->name, &sym->declared_at); } + else if (sym->attr.flavor == FL_PROCEDURE) + { + /* TODO: move to the appropriate place in resolve.c. */ + if (warn_return_type + && sym->attr.function + && sym->result + && sym != sym->result + && !sym->result->attr.referenced + && !sym->attr.use_assoc + && sym->attr.if_source != IFSRC_IFBODY) + { + gfc_warning ("Return value '%s' of function '%s' declared at " + "%L not set", sym->result->name, sym->name, + &sym->result->declared_at); + + /* Prevents "Unused variable" warning for RESULT variables. */ + sym->mark = sym->result->mark = 1; + } + } if (sym->attr.dummy == 1) { @@ -3275,10 +3296,17 @@ gfc_generate_function_code (gfc_namespace * ns) gfc_add_expr_to_block (&block, tmp2); } - gfc_add_expr_to_block (&block, tmp); + gfc_add_expr_to_block (&block, tmp); + + if (result == NULL_TREE) + { + /* TODO: move to the appropriate place in resolve.c. */ + if (warn_return_type && !sym->attr.referenced && sym == sym->result) + gfc_warning ("Return value of function '%s' at %L not set", + sym->name, &sym->declared_at); - if (result == NULL_TREE) - warning (0, "Function return value not set"); + TREE_NO_WARNING(sym->backend_decl) = 1; + } else { /* Set the return value to the dummy result variable. The |