http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56474



--- Comment #7 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2013-03-04 
11:29:16 UTC ---

> What will the result be used for in this case?  The result, usizetype_max,

> is certainly not 0 - 1 == -1 as it is unsigned.



It's used for the upper bound of variable-sized arrays:



          /* Finally we use (hb >= lb) ? hb : lb - 1 for the upper bound

         in all the other cases.  Note that, here as well as above,

         the condition used in the comparison must be equivalent to

         the condition (length != 0).  This is relied upon in order

         to optimize array comparisons in compare_arrays.  */

          else

        gnu_high

          = build_cond_expr (sizetype,

                     build_binary_op (GE_EXPR,

                              boolean_type_node,

                              gnu_orig_max,

                              gnu_orig_min),

                     gnu_max,

                     size_binop (MINUS_EXPR, gnu_min,

                         size_one_node));



The result wraps around but that's fine; we just don't want the overflow.



> Adding kludges like that might work, but I'd rather try to fix callers

> to "ask more intelligent questions".  That is,

> 

> +         /* ??? We make an exception for 0 - 1 because it's an idiom

> +            used in length calculations for zero-based arrays.  */

> +         if (integer_zerop (arg0) && integer_onep (arg1))

> +           overflowable = 1;

> 

> the length of an array is max-index - min-index + 1.  What's the call

> stack of this testcases case triggering the overflow?



Yes, the formula for the upper bound is designed to yield a length of zero if

the upper bound is lower than the lower bound.



size_binop is called from ada/gcc-interface/decl.c:gnat_to_gnu_entity.

Reply via email to