This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: why does c_strlen() return a signed integer?
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: GCC Development <gcc at gcc dot gnu dot org>
- Date: Fri, 24 Aug 2018 11:35:18 +0200
- Subject: Re: why does c_strlen() return a signed integer?
- References: <0f9291c6-3809-729d-9c05-a0a44f2e842d@gmail.com>
On Fri, Aug 24, 2018 at 12:16 AM Martin Sebor <msebor@gmail.com> wrote:
>
> PR 87059 - internal compiler error: in set_value_range, at
> tree-vrp.c:289, is apparently due to an argument type mismatch
> in a MIN_EXPR introduced by expand_builtin_strncmp().
>
> The function calls c_strlen() to compute the length of the two
> string arguments to strncmp() and then replaces the third (bound)
> argument with a MIN (len, bound). The type mismatch is caused by
> len being the signed result of c_strlen(), while bound being
> the size_t argument (explicitly converted to sizetype by
> the function).
>
> My question is: why does c_strlen() return a ssizetype, a signed
> type, rather the more natural sizetype? I ask in part because
> changing expand_builtin_strncmp() to convert the bound to
> ssizetype has downstream effects in the test suite, in part
> because it seems unexpected for the function to return a signed
> type given that the result cannot be negative, and in part also
> because I see most callers explicitly convert the result to
> size_type_node.
You have to dig into history youself but yes, it doesn't make much sense.
Possibly to avoid negative values to overflow to large positive ones?
Richard.
> Thanks
> Martin