This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Temporarily handle COMPOUND_EXPR in convert_* (PR c++/56493)
- From: Richard Biener <rguenther at suse dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Thu, 4 Dec 2014 10:34:10 +0100 (CET)
- Subject: Re: [PATCH] Temporarily handle COMPOUND_EXPR in convert_* (PR c++/56493)
- Authentication-results: sourceware.org; auth=none
- References: <20141203171414 dot GA1860 at tucnak dot redhat dot com>
On Wed, 3 Dec 2014, Jakub Jelinek wrote:
> Hi!
>
> As discussed in the PR, ideally this should be done in the middle-end,
> but no fix materialized for it during the last 18 months and is unlikely
> to happen for GCC 5 either, so this patch just restores what the FEs used
> to produce. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for
> trunk?
Ok. Might want to backport this as well.
Thanks,
Richard.
> 2014-12-03 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/56493
> * convert.c (convert_to_real, convert_to_expr, convert_to_complex):
> Handle COMPOUND_EXPR.
>
> * c-c++-common/pr56493.c: New test.
>
> --- gcc/convert.c.jj 2014-11-11 00:06:25.016769050 +0100
> +++ gcc/convert.c 2014-12-03 11:22:16.193539558 +0100
> @@ -99,6 +99,15 @@ convert_to_real (tree type, tree expr)
> enum built_in_function fcode = builtin_mathfn_code (expr);
> tree itype = TREE_TYPE (expr);
>
> + if (TREE_CODE (expr) == COMPOUND_EXPR)
> + {
> + tree t = convert_to_real (type, TREE_OPERAND (expr, 1));
> + if (t == TREE_OPERAND (expr, 1))
> + return expr;
> + return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (t),
> + TREE_OPERAND (expr, 0), t);
> + }
> +
> /* Disable until we figure out how to decide whether the functions are
> present in runtime. */
> /* Convert (float)sqrt((double)x) where x is float into sqrtf(x) */
> @@ -406,6 +415,15 @@ convert_to_integer (tree type, tree expr
> return error_mark_node;
> }
>
> + if (ex_form == COMPOUND_EXPR)
> + {
> + tree t = convert_to_integer (type, TREE_OPERAND (expr, 1));
> + if (t == TREE_OPERAND (expr, 1))
> + return expr;
> + return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (t),
> + TREE_OPERAND (expr, 0), t);
> + }
> +
> /* Convert e.g. (long)round(d) -> lround(d). */
> /* If we're converting to char, we may encounter differing behavior
> between converting from double->char vs double->long->char.
> @@ -926,6 +944,14 @@ convert_to_complex (tree type, tree expr
>
> if (TYPE_MAIN_VARIANT (elt_type) == TYPE_MAIN_VARIANT (subtype))
> return expr;
> + else if (TREE_CODE (expr) == COMPOUND_EXPR)
> + {
> + tree t = convert_to_complex (type, TREE_OPERAND (expr, 1));
> + if (t == TREE_OPERAND (expr, 1))
> + return expr;
> + return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR,
> + TREE_TYPE (t), TREE_OPERAND (expr, 0), t);
> + }
> else if (TREE_CODE (expr) == COMPLEX_EXPR)
> return fold_build2 (COMPLEX_EXPR, type,
> convert (subtype, TREE_OPERAND (expr, 0)),
> --- gcc/testsuite/c-c++-common/pr56493.c.jj 2014-12-03 11:22:16.193539558 +0100
> +++ gcc/testsuite/c-c++-common/pr56493.c 2014-12-03 11:22:16.193539558 +0100
> @@ -0,0 +1,16 @@
> +/* PR c++/56493 */
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-gimple" } */
> +
> +unsigned long long bar (void);
> +int x;
> +
> +void
> +foo (void)
> +{
> + x += bar ();
> +}
> +
> +/* Verify we narrow the addition from unsigned long long to unsigned int type. */
> +/* { dg-final { scan-tree-dump " (\[a-zA-Z._0-9]*) = \\(unsigned int\\) \[^;\n\r]*;.* (\[a-zA-Z._0-9]*) = \\(unsigned int\\) \[^;\n\r]*;.* = \\1 \\+ \\2;" "gimple" { target { ilp32 || lp64 } } } } */
> +/* { dg-final { cleanup-tree-dump "gimple" } } */
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Jeff Hawn, Jennifer Guild, Felix Imendoerffer, HRB 21284
(AG Nuernberg)
Maxfeldstrasse 5, 90409 Nuernberg, Germany