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
2008/10/25 Manuel López-Ibáñez <lopezibanez@gmail.com>:
> 2008/10/23 Richard Guenther <richard.guenther@gmail.com>:
>> On Thu, Oct 23, 2008 at 2:57 AM, Manuel López-Ibáñez
>> <lopezibanez@gmail.com> wrote:
>>> 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?
>>
>> Wherever you just set TREE_NO_WARNING or gimple_set_no_warning
>> (and not propagate it) during gimplification looks fishy.
>>
>> It looks like for both patches it might work to just disable these warnings for
>> EH related code? (The propagation of the no-warning flag during gimplification
>> _does_ look correct, though)
>>
The previous patch didn't make sense because the try/finally was
created during gimplification and nothing marked it as no_warning, so
propagating cannot be enough. I rechecked it and I must have mixed up
the results. The artificial try/finally created during gimplification
does need to be marked as no_warning to avoid warning.
Bootstrapped and regression tested on x86_64-unknown-linux-gnu with
--enable-languages=all,obj-c++ --enable-decimal-float.
2008-10-23 Manuel López-Ibáñez <manu@gcc.gnu.org>
PR c++/36254
* gimplify.c (gimplify_expr): Propagate the no_warning flag.
* gimple-low.c (lower_function_body): Propagate the no_warning
flag.
cp/
* cp-gimplify (cp_genericize_r): Set no_warning flag for
artificial try/catch and try/finally.
testsuite/
* g++dg/eh/pr36254.C: New.
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,13 @@
+/* PR c++/36254: wrong "control reaches end of non-void function" warning. */
+/* { dg-do compile } */
+/* { dg-options "-Wall -Wreturn-type" } */
+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/cp-gimplify.c
===================================================================
--- gcc/cp/cp-gimplify.c (revision 141322)
+++ gcc/cp/cp-gimplify.c (working copy)
@@ -795,15 +795,19 @@ 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 141322)
+++ 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 141322)
+++ gcc/gimplify.c (working copy)
@@ -6618,10 +6618,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;
}