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 Jeff