This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Make tree-ssa-strlen.c handle partial unterminated strings
- From: Andi Kleen <andi at firstfloor dot org>
- To: gcc-patches at gcc dot gnu dot org
- Cc: richard dot sandiford at linaro dot org
- Date: Fri, 05 May 2017 08:50:04 -0700
- Subject: Re: Make tree-ssa-strlen.c handle partial unterminated strings
- Authentication-results: sourceware.org; auth=none
- References: <87efw3sebf.fsf@linaro.org>
Richard Sandiford <richard.sandiford@linaro.org> writes:
> tree-ssa-strlen.c looks for cases in which a string is built up using
> operations like:
>
> memcpy (a, "foo", 4);
> memcpy (a + 3, "bar", 4);
> int x = strlen (a);
>
> As a side-effect, it optimises the non-final memcpys so that they don't
> include the nul terminator.
>
> However, after removing some "& ~0x1"s from tree-ssa-dse.c, the DSE pass
> does this optimisation itself (because it can tell that later memcpys
> overwrite the terminators). The strlen pass wasn't able to handle these
> pre-optimised calls in the same way as the unoptimised ones.
>
> This patch adds support for tracking unterminated strings.
Would that be useful as a warning too? If the pass can figure out
the final string can be not null terminated when passed somewhere else,
warn, because it's likely a bug in the program.
-Andi