On 10/28/19 4:36 PM, Martin Sebor wrote:
> While testing the patch for PR 92226 I posted earlier today
> I ran into a few cases where I expected the strlen range
> optimization to take place but it didn't.
> 
> In other instances this wouldn't be surprising because
> the optimization was only introduced for multi-character stores
> and with the expectation that it would be slowly extended to
> other functions over time.  But these cases were among those
> the optimization was meant to be in place for, so its absence
> is an oversight.  The attached near-trivial patch fills this
> gap.
> 
> As with all these changes, enabling the optimization also makes
> it possible to detect more instances of buffer overflow.
> 
> Tested on x86_64-linux.
> 
> Martin
> 
> PS There are quite a few remaining opportunities to make use of
> the strlen ranges in the pass.  Rather than enhancing the whole
> pass in one go I think it will be safer to do it one small step
> at a time, using little patchlets like in the attachment.
> 
> gcc-92226-2.diff
> 
> gcc/ChangeLog:
> 
>       * tree-ssa-strlen.c (get_addr_stridx): Add argument and use it.
>       (handle_store): Pass argument to get_addr_stridx.
> 
> gcc/testsuite/ChangeLog:
> 
>       * gcc.dg/strlenopt-89.c: New test.
>       * gcc.dg/strlenopt-90.c: New test.
>       * gcc.dg/Wstringop-overflow-20.c: New test.
OK.  And patches which do similar stuff (arranging to pass down the
range info) are pre-approved.

jeff

Reply via email to