This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH improve early strlen range folding (PR 83671)
- From: Richard Biener <richard dot guenther at gmail dot com>
- To: Martin Sebor <msebor at gmail dot com>
- Cc: Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 8 Jan 2018 12:28:30 +0100
- Subject: Re: [PATCH improve early strlen range folding (PR 83671)
- Authentication-results: sourceware.org; auth=none
- References: <9ab7f1fb-2407-7f59-244a-709fd5305c3e@gmail.com>
On Sat, Jan 6, 2018 at 11:04 PM, Martin Sebor <msebor@gmail.com> wrote:
> Bug 83671 - Fix for false positive reported by -Wstringop-overflow
> does not work at -O1, points out that the string length range
> optimization implemented as a solution for bug 83373 doesn't help
> at -O1. The root cause is that the fix was added to the strlen
> pass that doesn't run at -O1.
>
> The string length range computation doesn't depend on the strlen
> pass, and so the range can be set earlier, in gimple-fold, and
> its results made available even at -O1. The attached patch
> changes the gimple_fold_builtin_strlen() function to do that.
>
> While testing the change I came across a number of other simple
> strlen cases that currently aren't handled, some at -O1, others
> at all. I added code to handle some of the simplest of them
> and opened bugs to remind us/myself to get back to the rest in
> the future (pr83693 and pr83702). The significant enhancement
> is handling arrays of arrays with non-constant indices and
> pointers to such things, such as in:
>
> char a[2][7];
>
> void f (int i)
> {
> if (strlen (a[i]) > 6) // eliminated with the patch
> abort ();
> }
>
> Attached is a near-minimal patch to handle PR 83671.
Please don't use set_range_info form insinde fold_stmt (), this is
IMHO a layering violation.
Why not restrict -Wstrinop-overflow to -O2+?
Richard.
> Martin