This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Fix --enable-checking=types for FIXED_CONVERT_EXPR
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: gcc-patches at gcc dot gnu dot org, rdsandiford at googlemail dot com
- Date: Sat, 10 May 2008 14:12:39 +0200
- Subject: Re: Fix --enable-checking=types for FIXED_CONVERT_EXPR
- References: <87bq3ee5gj.fsf@firetop.home>
On Sat, May 10, 2008 at 1:58 PM, Richard Sandiford
<rdsandiford@googlemail.com> wrote:
> This patch adds a FIXED_CONVERT_EXPR case to verify_gimple_expr.
> The new code is similar to the CONVERT_EXPR handling, using:
>
> /* Conversion of a fixed-point value to an integer, a real, or a fixed-point
> value. Or conversion of a fixed-point value from an integer, a real, or
> a fixed-point value. */
> DEFTREECODE (FIXED_CONVERT_EXPR, "fixed_convert_expr", tcc_unary, 1)
>
> as a guide. (I spot-checked the sources and the comment still
> seems to be accurate.)
>
> Tested on mips64el-linux-gnu, where it fixes many fixed-point failures.
> OK to install?
Ok.
Thanks,
Richard.
> Richard
>
>
> gcc/
> * tree-cfg.c (valid_fixed_convert_types_p): New function.
> (verify_gimple_expr): Handle FIXED_CONVERT_EXPR.
>
> Index: gcc/tree-cfg.c
> ===================================================================
> --- gcc/tree-cfg.c 2008-05-09 18:35:44.000000000 +0100
> +++ gcc/tree-cfg.c 2008-05-09 18:36:08.000000000 +0100
> @@ -3599,6 +3599,18 @@ one_pointer_to_useless_type_conversion_p
> return false;
> }
>
> +/* Return true if TYPE1 is a fixed-point type and if conversions to and
> + from TYPE2 can be handled by FIXED_CONVERT_EXPR. */
> +
> +static bool
> +valid_fixed_convert_types_p (tree type1, tree type2)
> +{
> + return (FIXED_POINT_TYPE_P (type1)
> + && (INTEGRAL_TYPE_P (type2)
> + || SCALAR_FLOAT_TYPE_P (type2)
> + || FIXED_POINT_TYPE_P (type2)));
> +}
> +
> /* Verify the GIMPLE expression EXPR. Returns true if there is an
> error, otherwise false. */
>
> @@ -3656,6 +3668,27 @@ verify_gimple_expr (tree expr)
> return false;
> }
>
> + case FIXED_CONVERT_EXPR:
> + {
> + tree op = TREE_OPERAND (expr, 0);
> + if (!is_gimple_val (op))
> + {
> + error ("invalid operand in conversion");
> + return true;
> + }
> +
> + if (!valid_fixed_convert_types_p (type, TREE_TYPE (op))
> + && !valid_fixed_convert_types_p (TREE_TYPE (op), type))
> + {
> + error ("invalid types in fixed-point conversion");
> + debug_generic_expr (type);
> + debug_generic_expr (TREE_TYPE (op));
> + return true;
> + }
> +
> + return false;
> + }
> +
> case FLOAT_EXPR:
> {
> tree op = TREE_OPERAND (expr, 0);
>