diff options
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 9 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 6 |
3 files changed, 17 insertions, 7 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index f3a387d..1be683d 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,12 @@ +2018-05-30 David Pagan <dave.pagan@oracle.com> + + PR c/55976 + * c-decl.c (grokdeclarator): Update check for return type warnings. + (start_function): Likewise. + (finish_function): Likewise. + * c-typeck.c (c_finish_return): Update check for return type warnings. + Pass OPT_Wreturn_type to pedwarn when appropriate. + 2018-05-18 Richard Sandiford <richard.sandiford@linaro.org> * gimple-parser.c (c_parser_gimple_postfix_expression): Remove diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 3c4b18e..54f58a5 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -5758,7 +5758,7 @@ grokdeclarator (const struct c_declarator *declarator, /* Issue a warning if this is an ISO C 99 program or if -Wreturn-type and this is a function, or if -Wimplicit; prefer the former warning since it is more explicit. */ - if ((warn_implicit_int || warn_return_type || flag_isoc99) + if ((warn_implicit_int || warn_return_type > 0 || flag_isoc99) && funcdef_flag) warn_about_return_type = 1; else @@ -8752,7 +8752,7 @@ start_function (struct c_declspecs *declspecs, struct c_declarator *declarator, if (warn_about_return_type) warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int - : (warn_return_type ? OPT_Wreturn_type + : (warn_return_type > 0 ? OPT_Wreturn_type : OPT_Wimplicit_int), "return type defaults to %<int%>"); @@ -9463,8 +9463,9 @@ finish_function (void) finish_fname_decls (); - /* Complain if there's just no return statement. */ - if (warn_return_type + /* Complain if there's no return statement only if option specified on + command line. */ + if (warn_return_type > 0 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE && !current_function_returns_value && !current_function_returns_null /* Don't complain if we are no-return. */ diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 45a4529..f346eae 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -10133,13 +10133,13 @@ c_finish_return (location_t loc, tree retval, tree origtype) if (!retval) { current_function_returns_null = 1; - if ((warn_return_type || flag_isoc99) + if ((warn_return_type >= 0 || flag_isoc99) && valtype != NULL_TREE && TREE_CODE (valtype) != VOID_TYPE) { bool warned_here; if (flag_isoc99) warned_here = pedwarn - (loc, 0, + (loc, warn_return_type >= 0 ? OPT_Wreturn_type : 0, "%<return%> with no value, in function returning non-void"); else warned_here = warning_at @@ -10157,7 +10157,7 @@ c_finish_return (location_t loc, tree retval, tree origtype) bool warned_here; if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) warned_here = pedwarn - (xloc, 0, + (xloc, warn_return_type >= 0 ? OPT_Wreturn_type : 0, "%<return%> with a value, in function returning void"); else warned_here = pedwarn |