aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-fold.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-06-25 20:33:28 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-06-25 14:33:28 -0600
commiteec5f615cbad2de5ff10fbaa8c92f68cc5c6be00 (patch)
tree6d97fc1ae9f1316ba96cf9579500332267bb075a /gcc/gimple-fold.c
parent2bcd87a7b5bf793a00e99a5d7fdef4277afa7dc6 (diff)
downloadgcc-eec5f615cbad2de5ff10fbaa8c92f68cc5c6be00.zip
gcc-eec5f615cbad2de5ff10fbaa8c92f68cc5c6be00.tar.gz
gcc-eec5f615cbad2de5ff10fbaa8c92f68cc5c6be00.tar.bz2
PR tree-optimization/85700 - Spurious -Wstringop-truncation warning with strncat
gcc/ChangeLog: PR tree-optimization/85700 * gimple-fold.c (gimple_fold_builtin_strncat): Adjust comment. * tree-ssa-strlen.c (is_strlen_related_p): Handle integer subtraction. (maybe_diag_stxncpy_trunc): Distinguish strncat from strncpy. gcc/testsuite/ChangeLog: PR tree-optimization/85700 * gcc.dg/Wstringop-truncation-4.c: New test. From-SVN: r262110
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r--gcc/gimple-fold.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index a01bce7..b025935 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -2051,10 +2051,12 @@ gimple_fold_builtin_strncat (gimple_stmt_iterator *gsi)
if (!nowarn && cmpsrc == 0)
{
tree fndecl = gimple_call_fndecl (stmt);
-
- /* To avoid certain truncation the specified bound should also
- not be equal to (or less than) the length of the source. */
location_t loc = gimple_location (stmt);
+
+ /* To avoid possible overflow the specified bound should also
+ not be equal to the length of the source, even when the size
+ of the destination is unknown (it's not an uncommon mistake
+ to specify as the bound to strncpy the length of the source). */
if (warning_at (loc, OPT_Wstringop_overflow_,
"%G%qD specified bound %E equals source length",
stmt, fndecl, len))