[Bug middle-end/56474] [4.8 regression] bogus Storage_Error raised for record containing empty zero-based array

rguenther at suse dot de gcc-bugzilla@gcc.gnu.org
Mon Mar 4 15:12:00 GMT 2013


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

--- Comment #8 from rguenther at suse dot de <rguenther at suse dot de> 2013-03-04 15:12:25 UTC ---
On Mon, 4 Mar 2013, ebotcazou at gcc dot gnu.org wrote:

> 
> 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.

Hm, if hb < lb - what kind of pair do you expect?  The only case
where lb - 1 is the "upper bound" (whatever upper bound is for an
empty array ...) - isn't lb - 1 always equal to hb in that case,
thus are not hb and lb one element apart for empty arrays (length == 0)?

So just do ...

  gnu_high = gnu_orig_max;

?

Maybe I'm missign something ...

Richard.



More information about the Gcc-bugs mailing list