diff options
author | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-12-17 21:25:36 +0000 |
---|---|---|
committer | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2015-12-17 21:25:36 +0000 |
commit | b9f9586abf43c7577a5d9377ae2cba00c28ec879 (patch) | |
tree | 4c095463412043a04cc04af52d434df35a82c396 /gcc/c | |
parent | 71130ef83b18d2ab7be350b472cfc4f56b9f876b (diff) | |
download | gcc-b9f9586abf43c7577a5d9377ae2cba00c28ec879.tar.gz |
C FE: improvements to ranges of bad return values
gcc/c/ChangeLog:
* c-parser.c (c_parser_statement_after_labels): When calling
c_finish_return, Use the return expression's location if it has
one, falling back to the location of the first token within it.
* c-typeck.c (c_finish_return): When issuing warnings about
the incorrect presence/absence of a return value, issue a note
showing the declaration of the function.
gcc/testsuite/ChangeLog:
* gcc.dg/diagnostic-range-bad-return.c: New test case.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231786 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 3 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 28 |
3 files changed, 31 insertions, 9 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 22692d42a64..7c1247d120e 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,14 @@ 2015-12-16 David Malcolm <dmalcolm@redhat.com> + * c-parser.c (c_parser_statement_after_labels): When calling + c_finish_return, Use the return expression's location if it has + one, falling back to the location of the first token within it. + * c-typeck.c (c_finish_return): When issuing warnings about + the incorrect presence/absence of a return value, issue a note + showing the declaration of the function. + +2015-12-16 David Malcolm <dmalcolm@redhat.com> + * c-parser.c (struct c_parser): Expand array "tokens_buf" from 2 to 4. (c_parser_peek_nth_token): New function. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 43c26ae7384..353e3da5377 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -5179,7 +5179,8 @@ c_parser_statement_after_labels (c_parser *parser, vec<tree> *chain) location_t xloc = c_parser_peek_token (parser)->location; struct c_expr expr = c_parser_expression_conv (parser); mark_exp_read (expr.value); - stmt = c_finish_return (xloc, expr.value, expr.original_type); + stmt = c_finish_return (EXPR_LOC_OR_LOC (expr.value, xloc), + expr.value, expr.original_type); goto expect_semicolon; } break; diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a147ac6a7ce..b605f81fb43 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9545,24 +9545,36 @@ c_finish_return (location_t loc, tree retval, tree origtype) if ((warn_return_type || flag_isoc99) && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE) { + bool warned_here; if (flag_isoc99) - pedwarn (loc, 0, "%<return%> with no value, in " - "function returning non-void"); + warned_here = pedwarn + (loc, 0, + "%<return%> with no value, in function returning non-void"); else - warning_at (loc, OPT_Wreturn_type, "%<return%> with no value, " - "in function returning non-void"); + warned_here = warning_at + (loc, OPT_Wreturn_type, + "%<return%> with no value, in function returning non-void"); no_warning = true; + if (warned_here) + inform (DECL_SOURCE_LOCATION (current_function_decl), + "declared here"); } } else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE) { current_function_returns_null = 1; + bool warned_here; if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) - pedwarn (xloc, 0, - "%<return%> with a value, in function returning void"); + warned_here = pedwarn + (xloc, 0, + "%<return%> with a value, in function returning void"); else - pedwarn (xloc, OPT_Wpedantic, "ISO C forbids " - "%<return%> with expression, in function returning void"); + warned_here = pedwarn + (xloc, OPT_Wpedantic, "ISO C forbids " + "%<return%> with expression, in function returning void"); + if (warned_here) + inform (DECL_SOURCE_LOCATION (current_function_decl), + "declared here"); } else { |