This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR c++/36254 wrong "control reaches end of non-void function" warning
- From: "Manuel López-Ibáñez" <lopezibanez at gmail dot com>
- To: "Gcc Patch List" <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 23 Oct 2008 02:57:01 +0200
- Subject: Re: PR c++/36254 wrong "control reaches end of non-void function" warning
- References: <6c33472e0810221756oc92a9e3p48270ed3bc311567@mail.gmail.com>
Now with patch.
2008/10/23 Manuel López-Ibáñez <lopezibanez@gmail.com>:
> This is similar case as my patch for PR 31246: more cases of
> compiler-generated code. In fact, there is some overlap between them.
>
> Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
> --enable-languages=all,obj-c++ --enable-decimal-float.
>
> OK for trunk?
>
> 2008-10-23 Manuel López-Ibáñez <manu@gcc.gnu.org>
>
> PR c++/36254
> * gimplify.c (gimplify_bind_expr): Set NO_WARNING for compiler-generated
> code.
> (gimplify_cleanup_point_expr): Likewise.
> (gimplify_expr): Propagate the no_warning flag.
> * gimple-low.c (lower_function_body): Propagate the no_warning
> flag.
> testsuite/
> * g++dg/eh/pr36254.C: New.
> cp/
> * init.c (build_new_1): Set TREE_NO_WARNING for compiler-generated
> code.
> * except.c (build_throw): Likewise.
> * cp-gimplify.c (cp_genericize_r): Likewise.
>
Index: gcc/testsuite/g++.dg/eh/pr36254.C
===================================================================
--- gcc/testsuite/g++.dg/eh/pr36254.C (revision 0)
+++ gcc/testsuite/g++.dg/eh/pr36254.C (revision 0)
@@ -0,0 +1,10 @@
+extern int i, j, k;
+struct X { X(); ~X(); };
+bool f()
+{
+ X x;
+ if ( i && j )
+ if ( k < 0 ) return true; else return false;
+ else
+ return false;
+}
Index: gcc/cp/init.c
===================================================================
--- gcc/cp/init.c (revision 141266)
+++ gcc/cp/init.c (working copy)
@@ -2256,12 +2256,18 @@ build_new_1 (tree placement, tree type,
if (!cleanup)
/* We're done. */;
else if (stable)
/* This is much simpler if we were able to preevaluate all of
the arguments to the constructor call. */
- init_expr = build2 (TRY_CATCH_EXPR, void_type_node,
- init_expr, cleanup);
+ {
+ /* CLEANUP is compiler-generated, so no diagnostics. */
+ TREE_NO_WARNING (cleanup) = true;
+ init_expr = build2 (TRY_CATCH_EXPR, void_type_node,
+ init_expr, cleanup);
+ /* Likewise, this try-catch is compiler-generated. */
+ TREE_NO_WARNING (init_expr) = true;
+ }
else
/* Ack! First we allocate the memory. Then we set our sentry
variable to true, and expand a cleanup that deletes the
memory if sentry is true. Then we run the constructor, and
finally clear the sentry.
@@ -2277,10 +2283,13 @@ build_new_1 (tree placement, tree type,
begin = get_target_expr (boolean_true_node);
CLEANUP_EH_ONLY (begin) = 1;
sentry = TARGET_EXPR_SLOT (begin);
+ /* CLEANUP is compiler-generated, so no diagnostics. */
+ TREE_NO_WARNING (cleanup) = true;
+
TARGET_EXPR_CLEANUP (begin)
= build3 (COND_EXPR, void_type_node, sentry,
cleanup, void_zero_node);
end = build2 (MODIFY_EXPR, TREE_TYPE (sentry),
@@ -2288,12 +2297,13 @@ build_new_1 (tree placement, tree type,
init_expr
= build2 (COMPOUND_EXPR, void_type_node, begin,
build2 (COMPOUND_EXPR, void_type_node, init_expr,
end));
+ /* Likewise, this is compiler-generated. */
+ TREE_NO_WARNING (init_expr) = true;
}
-
}
}
else
init_expr = NULL_TREE;
Index: gcc/cp/except.c
===================================================================
--- gcc/cp/except.c (revision 141266)
+++ gcc/cp/except.c (working copy)
@@ -791,12 +791,16 @@ build_throw (tree exp)
for temporaries within the initialization are run before the one
for the exception object, preserving LIFO order. */
exp = build1 (CLEANUP_POINT_EXPR, void_type_node, exp);
if (elided)
- exp = build2 (TRY_CATCH_EXPR, void_type_node, exp,
- do_free_exception (ptr));
+ {
+ exp = build2 (TRY_CATCH_EXPR, void_type_node, exp,
+ do_free_exception (ptr));
+ /* This try-catch is compiler-generated. */
+ TREE_NO_WARNING (exp) = true;
+ }
else
exp = build1 (MUST_NOT_THROW_EXPR, void_type_node, exp);
/* Prepend the allocation. */
exp = build2 (COMPOUND_EXPR, TREE_TYPE (exp), allocate_expr, exp);
Index: gcc/cp/cp-gimplify.c
===================================================================
--- gcc/cp/cp-gimplify.c (revision 141266)
+++ gcc/cp/cp-gimplify.c (working copy)
@@ -795,15 +795,18 @@ cp_genericize_r (tree *stmt_p, int *walk
/* Due to the way voidify_wrapper_expr is written, we don't get a chance
to lower this construct before scanning it, so we need to lower these
before doing anything else. */
else if (TREE_CODE (stmt) == CLEANUP_STMT)
- *stmt_p = build2 (CLEANUP_EH_ONLY (stmt) ? TRY_CATCH_EXPR
- : TRY_FINALLY_EXPR,
- void_type_node,
- CLEANUP_BODY (stmt),
- CLEANUP_EXPR (stmt));
+ {
+ *stmt_p = build2 (CLEANUP_EH_ONLY (stmt) ? TRY_CATCH_EXPR
+ : TRY_FINALLY_EXPR,
+ void_type_node,
+ CLEANUP_BODY (stmt), CLEANUP_EXPR (stmt));
+ /* This is a compiler-generated artifact, so no diagnostics. */
+ TREE_NO_WARNING (*stmt_p) = true;
+ }
/* COND_EXPR might have incompatible types in branches if one or both
arms are bitfields. Fix it up now. */
else if (TREE_CODE (stmt) == COND_EXPR)
{
Index: gcc/gimple-low.c
===================================================================
--- gcc/gimple-low.c (revision 141266)
+++ gcc/gimple-low.c (working copy)
@@ -130,10 +130,13 @@ lower_function_body (void)
&& (VEC_empty (return_statements_t, data.return_statements)
|| gimple_return_retval (VEC_last (return_statements_t,
data.return_statements)->stmt) != NULL))
{
x = gimple_build_return (NULL);
+ /* Propagate the no_warning flag. */
+ if (!gsi_end_p (i))
+ gimple_set_no_warning (x, gimple_no_warning_p (gsi_stmt (i)));
gimple_set_location (x, cfun->function_end_locus);
gimple_set_block (x, DECL_INITIAL (current_function_decl));
gsi_insert_after (&i, x, GSI_CONTINUE_LINKING);
}
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c (revision 141266)
+++ gcc/gimplify.c (working copy)
@@ -1281,10 +1281,11 @@ gimplify_bind_expr (tree *expr_p, gimple
cleanup = new_body = NULL;
gimplify_seq_add_stmt (&cleanup, stack_restore);
gs = gimple_build_try (gimple_bind_body (gimple_bind), cleanup,
GIMPLE_TRY_FINALLY);
+ gimple_set_no_warning (gs, true);
gimplify_seq_add_stmt (&new_body, stack_save);
gimplify_seq_add_stmt (&new_body, gs);
gimple_bind_set_body (gimple_bind, new_body);
}
@@ -4880,10 +4881,12 @@ gimplify_cleanup_point_expr (tree *expr_
else
kind = GIMPLE_TRY_FINALLY;
seq = gsi_split_seq_after (iter);
gtry = gimple_build_try (seq, gimple_wce_cleanup (wce), kind);
+ /* This is a compiler-generated artifact, so no diagnostics. */
+ gimple_set_no_warning (gtry, true);
/* Do not use gsi_replace here, as it may scan operands.
We want to do a simple structural modification only. */
*gsi_stmt_ptr (&iter) = gtry;
iter = gsi_start (seq);
}
@@ -6618,10 +6621,12 @@ gimplify_expr (tree *expr_p, gimple_seq
? GIMPLE_TRY_FINALLY
: GIMPLE_TRY_CATCH);
if (TREE_CODE (*expr_p) == TRY_CATCH_EXPR)
gimple_try_set_catch_is_cleanup (try_,
TRY_CATCH_IS_CLEANUP (*expr_p));
+ /* Propagate no_warning flag. */
+ gimple_set_no_warning (try_, TREE_NO_WARNING (*expr_p));
gimplify_seq_add_stmt (pre_p, try_);
ret = GS_ALL_DONE;
break;
}