aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-01-10 21:40:14 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-01-10 14:40:14 -0700
commitc42d0aa0893cab444366c80fdd5b23bb45de6276 (patch)
treefafafff32b2c7dda509c5af6251cf14765cc834f /gcc/builtins.c
parente7c6abad7f0bcbf0e60d27bc8cff1087c5195f76 (diff)
downloadgcc-c42d0aa0893cab444366c80fdd5b23bb45de6276.zip
gcc-c42d0aa0893cab444366c80fdd5b23bb45de6276.tar.gz
gcc-c42d0aa0893cab444366c80fdd5b23bb45de6276.tar.bz2
PR tree-optimization/83671 - Fix for false positive reported by -Wstringop-overflow does not work with inlining
gcc/testsuite/ChangeLog: PR tree-optimization/83671 * gcc.dg/strlenopt-40.c: New test. * gcc.dg/strlenopt-41.c: New test. gcc/ChangeLog: PR tree-optimization/83671 * builtins.c (c_strlen): Unconditionally return zero for the empty string. Use -Warray-bounds for warnings. * gimple-fold.c (get_range_strlen): Handle non-constant lengths for non-constant array indices with COMPONENT_REF, arrays of arrays, and pointers to arrays. (gimple_fold_builtin_strlen): Determine and set length range for non-constant character arrays. From-SVN: r256457
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 1d6e69d..a0d0a10 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -621,6 +621,9 @@ c_strlen (tree src, int only_value)
return NULL_TREE;
}
+ if (!maxelts)
+ return ssize_int (0);
+
/* We don't know the starting offset, but we do know that the string
has no internal zero bytes. We can assume that the offset falls
within the bounds of the string; otherwise, the programmer deserves
@@ -651,7 +654,8 @@ c_strlen (tree src, int only_value)
if (only_value != 2
&& !TREE_NO_WARNING (src))
{
- warning_at (loc, 0, "offset %qwi outside bounds of constant string",
+ warning_at (loc, OPT_Warray_bounds,
+ "offset %qwi outside bounds of constant string",
eltoff);
TREE_NO_WARNING (src) = 1;
}