tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Avoid undesirable warning.
authorMartin Sebor <msebor@redhat.com>
Fri, 28 Dec 2018 19:26:14 +0000 (19:26 +0000)
committerJeff Law <law@gcc.gnu.org>
Fri, 28 Dec 2018 19:26:14 +0000 (12:26 -0700)
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Avoid
undesirable warning.

From-SVN: r267454

gcc/ChangeLog
gcc/tree-ssa-strlen.c

index 741c02d6cdaec143a49d258ca6399b49678ef802..e79809c50f672cdbdb247b533b2bcc30c5873fcb 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-28  Martin Sebor  <msebor@redhat.com>
+
+       * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Avoid
+       undesirable warning.
+
 2018-12-28  Thomas Schwinge  <thomas@codesourcery.com>
 
        * omp-expand.c (expand_omp_target): Restructure OpenACC vs. OpenMP
index 669c315dce2390570b95de928ab8fac1d7467eda..c74ce0feac5fbf513e3aa58bb8a3c6a7bd873a01 100644 (file)
@@ -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",