[patch] Eliminate signed sizetypes (1/3)

Richard Guenther richard.guenther@gmail.com
Tue Apr 13 10:02:00 GMT 2010


On Tue, Apr 13, 2010 at 11:50 AM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Every compiler in the GNU collection can choose to use either signed or
> unsigned sizetypes (exclusively, mixed signedness isn't allowed); the Ada
> compiler uses signed ones, all the other compilers (including LTO) use
> unsigned ones.  As a consequence, LTO doesn't really work with Ada, even
> intra-language LTO.
>
> So I'm proposing to eliminate signed sizetypes from the middle-end altogether,
> so that people aren't tempted to make the wrong choice anymore :-), switching
> the Ada compiler over to unsigned sizetypes in the process.  As a bonus, this
> will also fix bugs in some corner cases for Ada.
>
> The delicate part is converting the Ada compiler because it is still relying
> heavily on subtle overflow handling for sizetypes and flipping the signedness
> changes the semantics.  This dependency should probably be reworked at some
> point, but this won't be easy at all and is not planned yet.
>
> The attached first patch contains changes to the constant folder necessary to
> properly support overflow in unsigned sizetypes; nothing new, this support is
> already there, but it has been slightly damaged, especially by the fix for PR
> middle-end/32628, so the patch undoes it and fixes the problem differently.
>
> The second patch will be the gigi patch and the third patch the one really
> eliminating signed sizetypes from the middle-end.
>
> Tested on x86_64-suse-linux and i586-suse-linux, OK for mainline?

Ok apart from

+     Do this multiplication as signed, then convert to the appropriate type
+     for the pointer operation and disregard an overflow that occured only
+     because of the sign-extension change in the latter conversion.  */
+  {
+    tree t = build_binary_op (loc,
+                             MULT_EXPR, intop,
+                             convert (TREE_TYPE (intop), size_exp), 1);
+    intop = convert (sizetype, t);
+    if (TREE_OVERFLOW_P (intop) && !TREE_OVERFLOW (t))
+      TREE_OVERFLOW (intop) = 0;

can you instead of setting TREE_OVERFLOW to zero build
a new (shared) constant here?  Like

  intop = build_int_cst_wide (TREE_TYPE (intop), TREE_LOW_CST (intop),
TREE_HIGH_CST (intop));

?  That avoids keeping references to the unshared originally overflowed
constants.

Thanks,
Richard.




>
> 2010-04-13  Eric Botcazou  <ebotcazou@adacore.com>
>
>        PR middle-end/32628
>        * c-common.c (pointer_int_sum): Disregard overflow that occured only
>        because of sign-extension change when converting to sizetype here...
>        * fold-const.c (fold_convert_const_int_from_int): ...and not here.
>
>        * fold-const.c (fold_binary_op_with_conditional_arg): Do not restrict
>        the folding to constants.  Remove redundant final conversion.
>        (fold_binary) <associate>: Do not associate if the re-association of
>        constants alone overflows.
>        (fold_binary) <FLOOR_MOD_EXPR>: Move transformation into BIT_AND_EXPR
>        to the end of the list.
>        (multiple_of_p) <COND_EXPR>: New case.
>
>
> --
> Eric Botcazou
>



More information about the Gcc-patches mailing list