On Tue, 12 Jun 2018, Martin Sebor wrote:

> On 06/11/2018 03:57 PM, Jeff Law wrote:
> > On 05/29/2018 08:57 PM, Martin Sebor wrote:
> > > Warning for a strncpy call whose bound is the same as the size
> > > of the source and suggesting to use the size of the source is
> > > less than helpful when both sizes are the same, as in:
> > > 
> > >   char a[4], b[4];
> > >   strncpy (a, b, sizeof b);
> > > 
> > > The attached patch suppresses the -Wsizeof-pointer-memaccess
> > > warning for these cases.  To do that even for VLAs (in some
> > > cases), the patch enhances operand_equal_p() to handle
> > > SAVE_EXPR to detect when VLA in sizeof VLA refers to the size
> > > of a variable-length array.
> > > 
> > > Is this okay for trunk and GCC 8?
> > > 
> > > Martin
> > > 
> > > gcc-85931.diff
> > > 
> > > 
> > > PR c/85931 -  -Wsizeof-pointer-memaccess for strncpy with size of source
> > > 
> > > gcc/c-family/ChangeLog:
> > > 
> > >   PR c/85931
> > >   * c-warn.c (sizeof_pointer_memaccess_warning): Avoid warning when
> > >   sizeof source and destination yields the same value.
> > > 
> > > gcc/ChangeLog:
> > > 
> > >   PR c/85931
> > >   * fold-const.c (operand_equal_p): Handle SAVE_EXPR.
> > > 
> > > gcc/testsuite/ChangeLog:
> > > 
> > >   PR c/85931
> > >   * gcc.dg/Wstringop-truncation-3.c: New test.
> > OK for the trunk.  Richi and Jakub have the final say for the branch.
> > 
> > I'm a bit surprised that you don't just use operand_equal_p for both the
> > INTEGER_CST and !INTEGER_CST cases when testing dstsz == srcsz
> 
> It seemed that since the CST case compared the values of the size
> expressions and the other case their lexicographic form they needed
> to be different.  But operand_equal_p() does value comparison for
> constants so the conditional can be simplified by using just it
> for both cases.  Thanks for the suggestion!  I've made that
> simplification and committed r261515.
> 
> Jakub/Richard, can you please review the commit and let me know
> if you have any concerns with backporting it to the GCC 8 branch?
> (I will proceed if I don't hear anything this week.)

I'm fine with backporting it.

Richard.

Reply via email to