aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-06-12 18:05:13 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-06-12 12:05:13 -0600
commite3329a782fc0e51b9a4ddfc6938a484ec4b03084 (patch)
tree54f2c40c75f1eaadb4e09b9210721c95bda1b3a4 /gcc/builtins.c
parent47feeb36526b106053ad8d4fc7a64c23ce16f5de (diff)
downloadgcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.zip
gcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.tar.gz
gcc-e3329a782fc0e51b9a4ddfc6938a484ec4b03084.tar.bz2
PR tree-optimization/85259 - Missing -Wstringop-overflow= since r256683
gcc/ChangeLog: PR tree-optimization/85259 * builtins.c (compute_objsize): Handle constant offsets. * gimple-ssa-warn-restrict.c (maybe_diag_offset_bounds): Return true iff a warning has been issued. * gimple.h (gimple_nonartificial_location): New function. * tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Call gimple_nonartificial_location and handle -Wno-system-headers. (handle_builtin_stxncpy): Same. gcc/testsuite/ChangeLog: PR tree-optimization/85259 * gcc.dg/Wstringop-overflow-5.c: New test. * gcc.dg/Wstringop-overflow-6.c: New test. From-SVN: r261518
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 8707e0c..6b3e6b2 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -3326,10 +3326,29 @@ compute_objsize (tree dest, int ostype)
{
/* compute_builtin_object_size fails for addresses with
non-constant offsets. Try to determine the range of
- such an offset here and use it to adjus the constant
+ such an offset here and use it to adjust the constant
size. */
tree off = gimple_assign_rhs2 (stmt);
- if (TREE_CODE (off) == SSA_NAME
+ if (TREE_CODE (off) == INTEGER_CST)
+ {
+ if (tree size = compute_objsize (dest, ostype))
+ {
+ wide_int wioff = wi::to_wide (off);
+ wide_int wisiz = wi::to_wide (size);
+
+ /* Ignore negative offsets for now. For others,
+ use the lower bound as the most optimistic
+ estimate of the (remaining) size. */
+ if (wi::sign_mask (wioff))
+ ;
+ else if (wi::ltu_p (wioff, wisiz))
+ return wide_int_to_tree (TREE_TYPE (size),
+ wi::sub (wisiz, wioff));
+ else
+ return size_zero_node;
+ }
+ }
+ else if (TREE_CODE (off) == SSA_NAME
&& INTEGRAL_TYPE_P (TREE_TYPE (off)))
{
wide_int min, max;