This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
why does c_strlen() return a signed integer?
- From: Martin Sebor <msebor at gmail dot com>
- To: GCC Mailing List <gcc at gcc dot gnu dot org>
- Date: Thu, 23 Aug 2018 16:15:56 -0600
- Subject: why does c_strlen() return a signed integer?
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.
Thanks
Martin