[Bug tree-optimization/86400] [8/9 regression] set<string>::set<char (*)[2]) constructor does not work with array argument

rguenther at suse dot de gcc-bugzilla@gcc.gnu.org
Thu Jul 5 07:29:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86400

--- Comment #9 from rguenther at suse dot de <rguenther at suse dot de> ---
On Thu, 5 Jul 2018, msebor at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86400
> 
> Martin Sebor <msebor at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>            Keywords|                            |wrong-code
>              Status|NEW                         |ASSIGNED
>              Blocks|                            |83819
>            Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
> 
> --- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
> Confirmed.  The strlen pass sees:
> 
>   static char root[1][2] = {"/"};
>   ...
>   _1 = __builtin_strlen (&root);
> 
> 
> but the code in maybe_set_strlen_range() assumes the argument has the correct
> type (i.e., char*, not char[][2])

But the address of an array type is a pointer to an array type
in GENERIC.

> and uses TYPE_DOMAIN to determine the upper
> bound of the array which returns the bound of the outer array in this case. 
> Using TYPE_SIZE instead avoids the problem:
> 
> Index: gcc/tree-ssa-strlen.c
> ===================================================================
> --- gcc/tree-ssa-strlen.c       (revision 262418)
> +++ gcc/tree-ssa-strlen.c       (working copy)
> @@ -1156,22 +1156,17 @@ maybe_set_strlen_range (tree lhs, tree src, tree b
>        if (src_is_array && !array_at_struct_end_p (src))
>         {
>           tree type = TREE_TYPE (src);
> -         if (tree dom = TYPE_DOMAIN (type))
> -           {
> -             tree maxval = TYPE_MAX_VALUE (dom);
> -             if (maxval)
> -               max = wi::to_wide (maxval);
> -             else
> -               max = wi::zero (min.get_precision ());
> +         if (tree size = TYPE_SIZE_UNIT (type))

That should indeed include sub-dimensions.  Note the above
is only correct if BITS_PER_UNIT == CHAR_TYPE_SIZE (we probably
do not have any target where that isn't true).

> +           if (size && TREE_CODE (size) == INTEGER_CST)
> +             max = wi::to_wide (size);
> 
> -             /* For strlen() the upper bound above is equal to
> -                the longest string that can be stored in the array
> -                (i.e., it accounts for the terminating nul.  For
> -                strnlen() bump up the maximum by one since the array
> -                need not be nul-terminated.  */
> -             if (bound)
> -               ++max;
> -           }
> +         /* For strlen() the upper bound above is equal to
> +            the longest string that can be stored in the array
> +            (i.e., it accounts for the terminating nul.  For
> +            strnlen() bump up the maximum by one since the array
> +            need not be nul-terminated.  */
> +         if (!bound && max != 0)
> +           --max;
>         }
>        else
>         {
> 
> 
> Referenced Bugs:
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83819
> [Bug 83819] [meta-bug] missing strlen optimizations
>


More information about the Gcc-bugs mailing list