This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Truncate constants in build_int_cstu.


2010/5/17 Anatoly Sokolov <aesok@post.ru>:
> Hello.
>
> 2010/5/8 Richard Guenther <richard.guenther@gmail.com>:
>> ... ?Btw,
>> both build_int_cst and build_int_cstu should do proper sign/zero
>> extension as the types precision may be lower than that of
>> HOST_WIDE_INT.
>
> ?This patch change build_int_cstu function to truncate constants to the
> type precision.
>
> ?Bootstrapped/regtested on x86_64-unknown-linux-gnu for c, c++, ada, fortran
> and java.
>
> ?OK for mainline?

Ok with the assertions removed - they do not add additional
checks as the following TYPE_UNSIGNED check will segfault
for NULL type anyway.

Thanks,
Richard.

> ? ? ? ?* tree.h (build_int_cstu): Implement as static inline.
> ? ? ? ?* tree.c (build_int_cstu): Remove function.
> ? ? ? ?(double_int_to_tree, double_int_fits_to_tree_p): Handle size types as
> ? ? ? ?sign extended. Add assertion.
>
>
> Index: gcc/tree.c
> ===================================================================
> --- gcc/tree.c ?(revision 159494)
> +++ gcc/tree.c ?(working copy)
> @@ -1041,14 +1041,6 @@
> ? return build_int_cst_wide (type, low, low < 0 ? -1 : 0);
> ?}
>
> -/* Create an INT_CST node with a LOW value zero extended. ?*/
> -
> -tree
> -build_int_cstu (tree type, unsigned HOST_WIDE_INT low)
> -{
> - ?return build_int_cst_wide (type, low, 0);
> -}
> -
> ?/* Create an INT_CST node with a LOW value in TYPE. ?The value is sign extended
> ? ?if it is negative. ?This function is similar to build_int_cst, but
> ? ?the extra bits outside of the type precision are cleared. ?Constants
> @@ -1088,8 +1080,17 @@
> ?tree
> ?double_int_to_tree (tree type, double_int cst)
> ?{
> - ?cst = double_int_ext (cst, TYPE_PRECISION (type), TYPE_UNSIGNED (type));
> + ?bool sign_extended_type;
>
> + ?gcc_assert (type);
> +
> + ?/* Size types *are* sign extended. ?*/
> + ?sign_extended_type = (!TYPE_UNSIGNED (type)
> + ? ? ? ? ? ? ? ? ? ? ? || (TREE_CODE (type) == INTEGER_TYPE
> + ? ? ? ? ? ? ? ? ? ? ? ? ?&& TYPE_IS_SIZETYPE (type)));
> +
> + ?cst = double_int_ext (cst, TYPE_PRECISION (type), !sign_extended_type);
> +
> ? return build_int_cst_wide (type, cst.low, cst.high);
> ?}
>
> @@ -1099,10 +1100,18 @@
> ?bool
> ?double_int_fits_to_tree_p (const_tree type, double_int cst)
> ?{
> - ?double_int ext = double_int_ext (cst,
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE_PRECISION (type),
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?TYPE_UNSIGNED (type));
> + ?double_int ext;
> + ?bool sign_extended_type;
>
> + ?gcc_assert (type);
> +
> + ?/* Size types *are* sign extended. ?*/
> + ?sign_extended_type = (!TYPE_UNSIGNED (type)
> + ? ? ? ? ? ? ? ? ? ? ? ?|| (TREE_CODE (type) == INTEGER_TYPE
> + ? ? ? ? ? ? ? ? ? ? ? ? ? && TYPE_IS_SIZETYPE (type)));
> +
> + ?ext = double_int_ext (cst, TYPE_PRECISION (type), !sign_extended_type);
> +
> ? return double_int_equal_p (cst, ext);
> ?}
>
> Index: gcc/tree.h
> ===================================================================
> --- gcc/tree.h ?(revision 159494)
> +++ gcc/tree.h ?(working copy)
> @@ -4002,9 +4002,16 @@
> ?extern tree double_int_to_tree (tree, double_int);
> ?extern bool double_int_fits_to_tree_p (const_tree, double_int);
>
> +/* Create an INT_CST node with a CST value zero extended. ?*/
> +
> +static inline tree
> +build_int_cstu (tree type, unsigned HOST_WIDE_INT cst)
> +{
> + ?return double_int_to_tree (type, uhwi_to_double_int (cst));
> +}
> +
> ?extern tree build_int_cst (tree, HOST_WIDE_INT);
> ?extern tree build_int_cst_type (tree, HOST_WIDE_INT);
> -extern tree build_int_cstu (tree, unsigned HOST_WIDE_INT);
> ?extern tree build_int_cst_wide (tree, unsigned HOST_WIDE_INT, HOST_WIDE_INT);
> ?extern tree build_int_cst_wide_type (tree,
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? unsigned HOST_WIDE_INT, HOST_WIDE_INT);
>
>
> Anatoly.
>
>
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]