diff options
author | Martin Sebor <msebor@redhat.com> | 2018-02-22 17:35:29 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-02-22 10:35:29 -0700 |
commit | 5d0d5d6876afa8bc773e7503ec714ac1c08ae239 (patch) | |
tree | 6ddd58eb12d9e64c3ae7a6ca7afaab4501d2b47d /gcc/gimple-fold.c | |
parent | 73b8b82295fb286c2d5b01c200fcd6732a96c2a8 (diff) | |
download | gcc-5d0d5d6876afa8bc773e7503ec714ac1c08ae239.zip gcc-5d0d5d6876afa8bc773e7503ec714ac1c08ae239.tar.gz gcc-5d0d5d6876afa8bc773e7503ec714ac1c08ae239.tar.bz2 |
PR tree-optimization/84480 - bogus -Wstringop-truncation despite assignment with an inlined string literal
gcc/ChangeLog:
PR tree-optimization/84480
* gimple-fold.c (gimple_fold_builtin_strcpy): Move warnings
to maybe_diag_stxncpy_trunc. Call it.
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Integrate warnings
from gimple_fold_builtin_strcpy. Print inlining stack.
(handle_builtin_stxncpy): Print inlining stack.
* tree-ssa-strlen.h (maybe_diag_stxncpy_trunc): Declare.
gcc/testsuite/ChangeLog:
PR tree-optimization/84480
* c-c++-common/Wstringop-truncation.c: Adjust text of expected warnings.
* g++.dg/warn/Wstringop-truncation-1.C: New test.
From-SVN: r257910
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 0b75531..8257873 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -65,6 +65,7 @@ along with GCC; see the file COPYING3. If not see #include "intl.h" #include "calls.h" #include "tree-vector-builder.h" +#include "tree-ssa-strlen.h" /* Return true when DECL can be referenced from current unit. FROM_DECL (if non-null) specify constructor of variable DECL was taken from. @@ -1710,37 +1711,8 @@ gimple_fold_builtin_strncpy (gimple_stmt_iterator *gsi, if (tree_int_cst_lt (ssize, len)) return false; - if (!nonstring) - { - if (tree_int_cst_lt (len, slen)) - { - tree fndecl = gimple_call_fndecl (stmt); - gcall *call = as_a <gcall *> (stmt); - - warning_at (loc, OPT_Wstringop_truncation, - (tree_int_cst_equal (size_one_node, len) - ? G_("%G%qD output truncated copying %E byte " - "from a string of length %E") - : G_("%G%qD output truncated copying %E bytes " - "from a string of length %E")), - call, fndecl, len, slen); - } - else if (tree_int_cst_equal (len, slen)) - { - tree fndecl = gimple_call_fndecl (stmt); - gcall *call = as_a <gcall *> (stmt); - - warning_at (loc, OPT_Wstringop_truncation, - (tree_int_cst_equal (size_one_node, len) - ? G_("%G%qD output truncated before terminating nul " - "copying %E byte from a string of the same " - "length") - : G_("%G%qD output truncated before terminating nul " - "copying %E bytes from a string of the same " - "length")), - call, fndecl, len); - } - } + /* Diagnose truncation that leaves the copy unterminated. */ + maybe_diag_stxncpy_trunc (*gsi, src, len); /* OK transform into builtin memcpy. */ tree fn = builtin_decl_implicit (BUILT_IN_MEMCPY); |