[PATCH][RFC] Regularize sizetypes

H.J. Lu hjl.tools@gmail.com
Thu Jun 16 13:59:00 GMT 2011

On Thu, Jun 16, 2011 at 6:09 AM, Richard Guenther <rguenther@suse.de> wrote:
> For some reason I split out sanitizing sizetypes from the
> no-undefined-overflow-branch.  In fact the following patch tries
> to only fix one thing - make unsigned sizetypes no longer sign-extended.
> This has (unfortunately) interesting side-effects, and some of them
> have been mitigated by already committed patches during the last half
> year.  The main remaining issue I run into (and that sort-of blocks
> me from persuing this really really ...) is that there is a lot of
> code in GCC that assumes it can do modulo arithmetic on HOST_WIDE_INTs
> for sizetypes (pointers / offsets in general).  Which happens to
> be wrong when a HOST_WIDE_INT is wider than sizetype (on -m32 multilib
> on x86_64 for example).  It happens to work in almost all cases
> if we sign-extend from 32bit to 64bit HWI but not when we zero-extend.
> I'm not exactly sure how to proceeed here, other than adding fixups
> to various places (as seen in the patch below) and hope to catch
> all existing errors.  [yes, I already tried making all sizetypes
> signed, really signed, but that has loads of fallout as well]
> That said, the fact that sizetypes are sign-extended has caused
> wrong-code bugs in the past, and TYPE_UNSIGNED is really used
> inconsistently.  So I think this is definitely worth fixing.
> Eventually a first move would be to (finally) get rid of the
> requirement of sizetype offset arguments for POINTER_PLUS_EXPR.
> I didn't yet start on that project though.
> I remember the following bootstrapped fine on x86_64-unknown-linux-gnu
> at least for C, with a few remaining regressions.  I'm trying
> a full all-lang bootstrap & regtest now.
> Comments?  Questions?

Any expected impacts on x32 branch after this changed is merged?

> Thanks,
> Richard.
> 2011-06-16  Richard Guenther  <rguenther@suse.de>
>        * fold-const.c (div_if_zero_remainder): sizetypes no longer
>        sign-extend.
>        * stor-layout.c (initialize_sizetypes): Likewise.
>        * tree-ssa-ccp.c (bit_value_unop_1): Likewise.
>        (bit_value_binop_1): Likewise.
>        * tree.c (double_int_to_tree): Likewise.
>        (double_int_fits_to_tree_p): Likewise.
>        (force_fit_type_double): Likewise.
>        (host_integerp): Likewise.
>        (int_fits_type_p): Likewise.
>        * expr.c (get_inner_reference): Sign-extend offset.
>        * tree-ssa-structalias.c (get_constraint_for_ptr_offset): Likewise.
>        * tree-cfg.c (verify_types_in_gimple_reference): Do not compare
>        sizes by pointer.


More information about the Gcc-patches mailing list