diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index aa6d715288d..10ed324c9f5 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2015-09-30 Marek Polacek + + 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 * c-parser.c (pragma_lex): Add loc argument. diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 3b2623140e3..a11ccb20b33 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 % has a % 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, "% with a value, in function returning void"); else - pedwarn (loc, OPT_Wpedantic, "ISO C forbids " + pedwarn (xloc, OPT_Wpedantic, "ISO C forbids " "% with expression, in function returning void"); } else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 36a41d6c129..8192f188083 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-09-30 Marek Polacek + + PR c/67730 + * gcc.dg/pr67730.c: New test. + 2015-09-30 Marek Polacek PR tree-optimization/67690 diff --git a/gcc/testsuite/gcc.dg/pr67730.c b/gcc/testsuite/gcc.dg/pr67730.c new file mode 100644 index 00000000000..54d73a62cf8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr67730.c @@ -0,0 +1,11 @@ +/* PR c/67730 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +#include + +void +fn1 (void) +{ + return NULL; /* { dg-warning "10:.return. with a value" } */ +}