This was extracted from Martin's work on the strlen range fixes. As the comment indicates, avoid warning for strncpy (a, b, N) where N == sizeof (a) and N == sizeof (b).
I didn't immediately see a testcase in Martin's changes. I'm pretty sure I've seen a few Fedora rawhide packages failing builds because of this issue. Bootstrapped & regression tested on x86_64. Installing on the trunk. My Fedora tester will pick it up at the next snapshot. My GCC tester will pick it up overnight. Jeff
commit b74ab41ec0b6f590d0c5ff803b42a05b21fb2218 Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4> Date: Fri Dec 28 19:26:14 2018 +0000 * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Avoid undesirable warning. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@267454 138bc75d-0d04-0410-961f-82ee72b054a4 diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 741c02d6cda..e79809c50f6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-12-28 Martin Sebor <mse...@redhat.com> + + * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Avoid + undesirable warning. + 2018-12-28 Thomas Schwinge <tho...@codesourcery.com> * omp-expand.c (expand_omp_target): Restructure OpenACC vs. OpenMP diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 669c315dce2..c74ce0feac5 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -2114,6 +2114,13 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt) if (wi::to_wide (dstsize) != cntrange[1]) return false; + /* Avoid warning for strncpy(a, b, N) calls where the following + equalities hold: + N == sizeof a && N == sizeof b */ + if (tree srcsize = compute_objsize (src, 1)) + if (wi::to_wide (srcsize) == cntrange[1]) + return false; + if (cntrange[0] == cntrange[1]) return warning_at (callloc, OPT_Wstringop_truncation, "%G%qD specified bound %E equals destination size",