This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] avoid assuming known string length is constant (PR 83896)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Martin Sebor <msebor at gmail dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>, richard dot sandiford at linaro dot org
- Date: Tue, 16 Jan 2018 22:26:32 +0100
- Subject: Re: [PATCH] avoid assuming known string length is constant (PR 83896)
- Authentication-results: sourceware.org; auth=none
- References: <df25c3ab-2e13-38c2-3883-25a00edf4d96@gmail.com> <87r2qpwq6d.fsf@linaro.org>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Jan 16, 2018 at 07:37:30PM +0000, Richard Sandiford wrote:
> > -/* Check if RHS is string_cst possibly wrapped by mem_ref. */
> > +/* If RHS, either directly or indirectly, refers to a string of constant
> > + length, return it. Otherwise return a negative value. */
> > +
> > static int
> > get_string_len (tree rhs)
> > {
>
> I think this should be returning HOST_WIDE_INT given the unconstrained
> tree_to_shwi return. Same type change for rhslen in the caller.
>
> (Not my call, but it might be better to have a more specific function name,
> given that the file already had "get_string_length" before this function
> was added.)
Yeah, certainly for both.
> > @@ -2789,7 +2791,8 @@ get_string_len (tree rhs)
> > if (idx > 0)
> > {
> > strinfo *si = get_strinfo (idx);
> > - if (si && si->full_string_p)
> > + if (si && si->full_string_p
> > + && TREE_CODE (si->nonzero_chars) == INTEGER_CST)
> > return tree_to_shwi (si->nonzero_chars);
>
> tree_fits_shwi_p?
Surely that instead of TREE_CODE check, but even that will not make sure it
fits into host int, so yes, it should be HOST_WIDE_INT and the code should
make sure it is also >= 0.
Jakub