This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Genericize IF_STMT already during genericization, before gimplification (PR c++/36254)
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Jakub Jelinek" <jakub at redhat dot com>
- Cc: "Jason Merrill" <jason at redhat dot com>, "Mark Mitchell" <mark at codesourcery dot com>, gcc-patches at gcc dot gnu dot org
- Date: Thu, 8 Jan 2009 23:35:50 +0100
- Subject: Re: [C++ PATCH] Genericize IF_STMT already during genericization, before gimplification (PR c++/36254)
- References: <20090108223012.GQ25055@tyan-ft48-01.lab.bos.redhat.com>
On Thu, Jan 8, 2009 at 11:30 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> shortcut_cond_expr uses block_may_fallthru to determine whether
> a jump around else is needed or not. But this happens during
> gimplification, before then and else are gimplified, and block_may_fallthru,
> being a middle-end function, doesn't understand FE specific trees.
> For if this can be fixed simply by genericizing IF_STMT into COND_EXPR
> already during cp_genericize, before gimplification - there is nothing
> in IF_STMT genericization that needs to be deferred till gimplification.
Isn't this true for all frontend specific trees? That is, FOR_STMT isn't proper
GENERIC either - and don't we want to feed the gimplifier with GENERIC only?
Richard.
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
>
> 2009-01-08 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/36254
> * cp-gimplify.c (genericize_if_stmt): Renamed from ...
> (gimplify_if_stmt): ... this.
> (cp_gimplify_expr): Don't handle IF_STMT here.
> (cp_genericize_r): Call genericize_if_stmt for IF_STMT.
>
> * g++.dg/warn/Wreturn-type-5.C: New test.
>
> --- gcc/cp/cp-gimplify.c.jj 2008-11-04 21:03:14.000000000 +0100
> +++ gcc/cp/cp-gimplify.c 2009-01-08 22:16:52.000000000 +0100
> @@ -158,7 +158,7 @@ genericize_eh_spec_block (tree *stmt_p)
> /* Genericize an IF_STMT by turning it into a COND_EXPR. */
>
> static void
> -gimplify_if_stmt (tree *stmt_p)
> +genericize_if_stmt (tree *stmt_p)
> {
> tree stmt, cond, then_, else_;
> location_t locus = EXPR_LOCATION (*stmt_p);
> @@ -611,11 +611,6 @@ cp_gimplify_expr (tree *expr_p, gimple_s
> ret = GS_ALL_DONE;
> break;
>
> - case IF_STMT:
> - gimplify_if_stmt (expr_p);
> - ret = GS_OK;
> - break;
> -
> case FOR_STMT:
> gimplify_for_stmt (expr_p, pre_p);
> ret = GS_OK;
> @@ -803,6 +798,13 @@ cp_genericize_r (tree *stmt_p, int *walk
> CLEANUP_BODY (stmt),
> CLEANUP_EXPR (stmt));
>
> + else if (TREE_CODE (stmt) == IF_STMT)
> + {
> + genericize_if_stmt (stmt_p);
> + /* *stmt_p has changed, tail recurse to handle it again. */
> + return cp_genericize_r (stmt_p, walk_subtrees, data);
> + }
> +
> /* 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)
> --- gcc/testsuite/g++.dg/warn/Wreturn-type-5.C.jj 2009-01-08 17:43:06.000000000 +0100
> +++ gcc/testsuite/g++.dg/warn/Wreturn-type-5.C 2009-01-08 17:43:06.000000000 +0100
> @@ -0,0 +1,21 @@
> +// PR c++/36254
> +// { dg-do compile }
> +// { dg-options "-Wreturn-type" }
> +
> +int i, j, k;
> +struct X { X (); ~X (); };
> +
> +bool
> +foo ()
> +{
> + X x;
> + if (i && j)
> + {
> + if (k)
> + return true;
> + else
> + return false;
> + }
> + else
> + return false;
> +}
>
> Jakub
>