diff options
author | Marek Polacek <polacek@redhat.com> | 2015-09-30 11:26:44 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2015-09-30 11:26:44 +0000 |
commit | de8ddd5fb1eb0f61e304dda5044ef18a24a16f69 (patch) | |
tree | 36db101171db6bb1d32a8f4bb020799de6660143 /gcc | |
parent | 6ea2f74cf9dbee7a3e41d4c2bd3757a2ea303b8e (diff) | |
download | gcc-de8ddd5fb1eb0f61e304dda5044ef18a24a16f69.zip gcc-de8ddd5fb1eb0f61e304dda5044ef18a24a16f69.tar.gz gcc-de8ddd5fb1eb0f61e304dda5044ef18a24a16f69.tar.bz2 |
re PR c/67730 (No warning when returning NULL in void function)
PR c/67730
* c-typeck.c (c_finish_return): Use the expansion point location for
certain "return with value" warnings.
* gcc.dg/pr67730.c: New test.
From-SVN: r228286
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c/c-typeck.c | 10 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr67730.c | 11 |
4 files changed, 29 insertions, 3 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index aa6d715..10ed324 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2015-09-30 Marek Polacek <polacek@redhat.com> + + PR c/67730 + * c-typeck.c (c_finish_return): Use the expansion point location for + certain "return with value" warnings. + 2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org> * c-parser.c (pragma_lex): Add loc argument. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 3b26231..a11ccb2 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -9369,8 +9369,12 @@ c_finish_return (location_t loc, tree retval, tree origtype) bool npc = false; size_t rank = 0; + /* Use the expansion point to handle cases such as returning NULL + in a function returning void. */ + source_location xloc = expansion_point_location_if_in_system_header (loc); + if (TREE_THIS_VOLATILE (current_function_decl)) - warning_at (loc, 0, + warning_at (xloc, 0, "function declared %<noreturn%> has a %<return%> statement"); if (flag_cilkplus && contains_array_notation_expr (retval)) @@ -9425,10 +9429,10 @@ c_finish_return (location_t loc, tree retval, tree origtype) { current_function_returns_null = 1; if (TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE) - pedwarn (loc, 0, + pedwarn (xloc, 0, "%<return%> with a value, in function returning void"); else - pedwarn (loc, OPT_Wpedantic, "ISO C forbids " + pedwarn (xloc, OPT_Wpedantic, "ISO C forbids " "%<return%> with expression, in function returning void"); } else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 36a41d6..8192f18 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2015-09-30 Marek Polacek <polacek@redhat.com> + PR c/67730 + * gcc.dg/pr67730.c: New test. + +2015-09-30 Marek Polacek <polacek@redhat.com> + PR tree-optimization/67690 * gcc.dg/torture/pr67690.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr67730.c b/gcc/testsuite/gcc.dg/pr67730.c new file mode 100644 index 0000000..54d73a6 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr67730.c @@ -0,0 +1,11 @@ +/* PR c/67730 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +#include <stddef.h> + +void +fn1 (void) +{ + return NULL; /* { dg-warning "10:.return. with a value" } */ +} |