Hi,

> -fold_builtin_strlen (location_t loc, tree type, tree arg)
> +fold_builtin_strlen (location_t loc, tree fndecl, tree type, tree arg)
>  {
>    if (!validate_arg (arg, POINTER_TYPE))
>      return NULL_TREE;
>    else
>      {
> -      tree len = c_strlen (arg, 0);
> -
> +      tree nonstr = NULL_TREE;
> +      tree len = c_strlen (arg, 0, &nonstr);
>        if (len)
> -       return fold_convert_loc (loc, type, len);
> +       {
> +         if (loc == UNKNOWN_LOCATION && EXPR_HAS_LOCATION (arg))
> +           loc = EXPR_LOCATION (arg);
> +
> +         /* To avoid warning multiple times about unterminated
> +            arrays only warn if its length has been determined
> +            and is being folded to a constant.  */
> +         if (nonstr)
> +           warn_string_no_nul (loc, NULL_TREE, fndecl, nonstr);
> +
> +         return fold_convert_loc (loc, type, len);
> +       }
> 
>        return NULL_TREE;

If I see that right, this will do a wrong folding,
just to suppress duplicate warnings.

But it will re-introduce a path to PR87053, since c_strlen
is supposed to return the wrong value because nonstr
suggests the caller is able to handle this.

I think c_strlen should never return anything that is invalid.
Returning len and nonstr should be mutually exclusive events.


Bernd.

Reply via email to