This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: build_int_cstu does not work as advertised
- From: Richard Guenther <richard dot guenther at gmail dot com>
- To: Florian Weimer <fw at deneb dot enyo dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 5 Dec 2010 21:58:47 +0100
- Subject: Re: build_int_cstu does not work as advertised
- References: <877hfoi1uc.fsf@mid.deneb.enyo.de>
On Sun, Dec 5, 2010 at 6:08 PM, Florian Weimer <fw@deneb.enyo.de> wrote:
> Trunk has this:
>
> | /* 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));
> | }
>
> But the comment is misleading because of:
Well, you shouldn't call it with signed or sign-extended types ...
> | /* Constructs tree in type TYPE from with value given by CST. ?Signedness
> | ? ?of CST is assumed to be the same as the signedness of TYPE. ?*/
> |
> | tree
> | double_int_to_tree (tree type, double_int cst)
> | {
> | ? /* Size types *are* sign extended. ?*/
> | ? bool 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);
> | }
>
> So for size types, build_int_cstu does not peform zero extension, but
> sign extension.
And that's correct.
> If I don't want sign extension, what function should I use instead?
> Should I just call build_int_cst_wide directly?
You should use a different type, one that is not sign-extended. Non-canonical
constants are not allowed as we share them based on type and value.
> And is HOST_WIDE_INT guaraunteed to be able to hold 64 bits? ?I recall
> a discussion were it was said that cross-builds from hosts with narrow
> HOST_WIDE_INT to 64 bit targets weren't supported.
double_int is at least 64 bits.
Richard.