aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-09-06 22:07:13 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2005-09-06 22:07:13 +0200
commit0c9b182b9f454fb2d5f57b17d22e860490c3c68f (patch)
tree26cc76717919b282649ef97b4afa9424d824fe86 /gcc
parent73109af7527b8c42510b1144cc2118a175960903 (diff)
downloadgcc-0c9b182b9f454fb2d5f57b17d22e860490c3c68f.zip
gcc-0c9b182b9f454fb2d5f57b17d22e860490c3c68f.tar.gz
gcc-0c9b182b9f454fb2d5f57b17d22e860490c3c68f.tar.bz2
re PR c/23075 (Redundant / bogus warning)
PR c/23075 * c-typeck.c (c_finish_return): Set TREE_NO_WARNING on RETURN_EXPR if "return with no value, in function returning non-void" warning has been issued. * tree-cfg.c (execute_warn_function_return): Don't look at RETURN_EXPRs with TREE_NO_WARNING set. * typeck.c (check_return_expr): Add no_warning argument. Set *no_warning to true if "return-statement with no value, in function returning" warning has been issued. * cp-tree.h (check_return_expr): Adjust prototype. * semantics.c (finish_return_stmt): Set TREE_NO_WARNING if check_return_expr set *no_warning to true. * gcc.dg/pr23075.c: New test. * g++.dg/warn/pr23075.C: New test. From-SVN: r103967
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/c-typeck.c14
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/cp-tree.h2
-rw-r--r--gcc/cp/semantics.c4
-rw-r--r--gcc/cp/typeck.c12
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/g++.dg/warn/pr23075.C14
-rw-r--r--gcc/testsuite/gcc.dg/pr23075.c14
-rw-r--r--gcc/tree-cfg.c3
10 files changed, 75 insertions, 9 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9c60317..7ed2b69 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2005-09-06 Jakub Jelinek <jakub@redhat.com>
+ PR c/23075
+ * c-typeck.c (c_finish_return): Set TREE_NO_WARNING on RETURN_EXPR
+ if "return with no value, in function returning non-void" warning
+ has been issued.
+ * tree-cfg.c (execute_warn_function_return): Don't look at
+ RETURN_EXPRs with TREE_NO_WARNING set.
+
PR target/22362
* config/i386/i386.c (ix86_function_regparm): Make sure automatic regparm
for internal functions doesn't use registers used by global registers
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index c72ba8a..ff8577b 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -6702,7 +6702,8 @@ c_finish_goto_ptr (tree expr)
tree
c_finish_return (tree retval)
{
- tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
+ tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl)), ret_stmt;
+ bool no_warning = false;
if (TREE_THIS_VOLATILE (current_function_decl))
warning (0, "function declared %<noreturn%> has a %<return%> statement");
@@ -6712,8 +6713,11 @@ c_finish_return (tree retval)
current_function_returns_null = 1;
if ((warn_return_type || flag_isoc99)
&& valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
- pedwarn_c99 ("%<return%> with no value, in "
- "function returning non-void");
+ {
+ pedwarn_c99 ("%<return%> with no value, in "
+ "function returning non-void");
+ no_warning = true;
+ }
}
else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
{
@@ -6789,7 +6793,9 @@ c_finish_return (tree retval)
retval = build2 (MODIFY_EXPR, TREE_TYPE (res), res, t);
}
- return add_stmt (build_stmt (RETURN_EXPR, retval));
+ ret_stmt = build_stmt (RETURN_EXPR, retval);
+ TREE_NO_WARNING (ret_stmt) |= no_warning;
+ return add_stmt (ret_stmt);
}
struct c_switch {
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 50ce226..f56a714 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,13 @@
+2005-09-06 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/23075
+ * typeck.c (check_return_expr): Add no_warning argument. Set
+ *no_warning to true if "return-statement with no value, in function
+ returning" warning has been issued.
+ * cp-tree.h (check_return_expr): Adjust prototype.
+ * semantics.c (finish_return_stmt): Set TREE_NO_WARNING if
+ check_return_expr set *no_warning to true.
+
2005-09-06 Mark Mitchell <mark@codesourcery.com>
* cp-tree.h (rvalue): New function.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 2803f51..cf24129 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4322,7 +4322,7 @@ extern tree type_after_usual_arithmetic_conversions (tree, tree);
extern tree composite_pointer_type (tree, tree, tree, tree,
const char*);
extern tree merge_types (tree, tree);
-extern tree check_return_expr (tree);
+extern tree check_return_expr (tree, bool *);
#define cp_build_binary_op(code, arg1, arg2) \
build_binary_op(code, arg1, arg2, 1)
#define cxx_sizeof(T) cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR, true)
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 074a7fd..c7fd1bb 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -743,8 +743,9 @@ tree
finish_return_stmt (tree expr)
{
tree r;
+ bool no_warning;
- expr = check_return_expr (expr);
+ expr = check_return_expr (expr, &no_warning);
if (!processing_template_decl)
{
if (DECL_DESTRUCTOR_P (current_function_decl)
@@ -760,6 +761,7 @@ finish_return_stmt (tree expr)
}
r = build_stmt (RETURN_EXPR, expr);
+ TREE_NO_WARNING (r) |= no_warning;
r = maybe_cleanup_point_expr_void (r);
r = add_stmt (r);
finish_stmt ();
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 67f631a..b0dfa60 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -6134,10 +6134,12 @@ maybe_warn_about_returning_address_of_local (tree retval)
/* Check that returning RETVAL from the current function is valid.
Return an expression explicitly showing all conversions required to
change RETVAL into the function return type, and to assign it to
- the DECL_RESULT for the function. */
+ the DECL_RESULT for the function. Set *NO_WARNING to true if
+ code reaches end of non-void function warning shouldn't be issued
+ on this RETURN_EXPR. */
tree
-check_return_expr (tree retval)
+check_return_expr (tree retval, bool *no_warning)
{
tree result;
/* The type actually returned by the function, after any
@@ -6145,6 +6147,8 @@ check_return_expr (tree retval)
tree valtype;
int fn_returns_value_p;
+ *no_warning = false;
+
/* A `volatile' function is one that isn't supposed to return, ever.
(This is a G++ extension, used to get better code for functions
that call the `volatile' function.) */
@@ -6195,6 +6199,10 @@ check_return_expr (tree retval)
end of a non-void function (which we don't, we gave a
return!). */
current_function_returns_null = 0;
+ /* And signal caller that TREE_NO_WARNING should be set on the
+ RETURN_EXPR to avoid control reaches end of non-void function
+ warnings in tree-cfg.c. */
+ *no_warning = true;
}
/* Check for a return statement with a value in a function that
isn't supposed to return a value. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b76b34b..74e070b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2005-09-06 Jakub Jelinek <jakub@redhat.com>
+ PR c/23075
+ * gcc.dg/pr23075.c: New test.
+ * g++.dg/warn/pr23075.C: New test.
+
PR target/22362
* gcc.target/i386/pr22362.c: New test.
diff --git a/gcc/testsuite/g++.dg/warn/pr23075.C b/gcc/testsuite/g++.dg/warn/pr23075.C
new file mode 100644
index 0000000..cc71dea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/pr23075.C
@@ -0,0 +1,14 @@
+// PR c/23075
+// { dg-do compile }
+// { dg-options "-O2 -Wreturn-type" }
+
+int
+foo (void)
+{
+ return; // { dg-error "with no value" }
+} // { dg-bogus "control reaches end" }
+
+int
+bar (void)
+{
+} // { dg-warning "control reaches end" }
diff --git a/gcc/testsuite/gcc.dg/pr23075.c b/gcc/testsuite/gcc.dg/pr23075.c
new file mode 100644
index 0000000..2d85fb0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr23075.c
@@ -0,0 +1,14 @@
+/* PR c/23075 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wreturn-type" } */
+
+int
+foo (void)
+{
+ return; /* { dg-warning "with no value" } */
+} /* { dg-bogus "control reaches end" } */
+
+int
+bar (void)
+{
+} /* { dg-warning "control reaches end" } */
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index df97058..3711556 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -5125,7 +5125,8 @@ execute_warn_function_return (void)
{
tree last = last_stmt (e->src);
if (TREE_CODE (last) == RETURN_EXPR
- && TREE_OPERAND (last, 0) == NULL)
+ && TREE_OPERAND (last, 0) == NULL
+ && !TREE_NO_WARNING (last))
{
#ifdef USE_MAPPED_LOCATION
location = EXPR_LOCATION (last);