From 5d0d5d6876afa8bc773e7503ec714ac1c08ae239 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Thu, 22 Feb 2018 17:35:29 +0000 Subject: 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 --- gcc/gimple-fold.c | 34 +++------------------------------- 1 file changed, 3 insertions(+), 31 deletions(-) (limited to 'gcc/gimple-fold.c') 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 (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 (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); -- cgit v1.1