aboutsummaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-09-01 16:02:19 -0600
committerMartin Sebor <msebor@redhat.com>2020-09-01 16:03:25 -0600
commit0c344a649d803a83ed35f629d292b98143935ffa (patch)
tree069c12b4eb9f1263b68f13d0a2027908cb58204f /gcc/builtins.c
parentb1c59b31ef7adc832405209e9e2a77212284abd7 (diff)
downloadgcc-0c344a649d803a83ed35f629d292b98143935ffa.zip
gcc-0c344a649d803a83ed35f629d292b98143935ffa.tar.gz
gcc-0c344a649d803a83ed35f629d292b98143935ffa.tar.bz2
Use the determined lower bound of the range of offsets in a PLUS_EXPR.
gcc/ChangeLog: * builtins.c (compute_objsize): Only replace the upper bound of a POINTER_PLUS offset when it's less than the lower bound. gcc/testsuite/ChangeLog: * gcc.dg/Wstringop-overflow.c: Remove xfails. * gcc.dg/Wstringop-overflow-42.c: New test. * gcc.dg/Wstringop-overread-4.c: New test.
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index bc35b07..97f1a18 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -4367,12 +4367,17 @@ compute_objsize (tree ptr, int ostype, access_ref *pref,
offset to the maximum. */
offset_int orng[2];
tree off = gimple_assign_rhs2 (stmt);
- if (!get_range (off, SIGNED, orng, rvals)
- || !wi::les_p (orng[0], orng[1]))
+ if (!get_range (off, SIGNED, orng, rvals))
{
orng[0] = wi::to_offset (TYPE_MIN_VALUE (ptrdiff_type_node));
orng[1] = wi::to_offset (TYPE_MAX_VALUE (ptrdiff_type_node));
}
+ else if (wi::lts_p (orng[1], orng[0]))
+ /* The upper bound is less than the lower bound when the integer
+ operand is the result of signed integer conversion to sizetype,
+ as in P + OFF + CST where OFF > 0.
+ Correct just the upper bound. */
+ orng[1] = wi::to_offset (TYPE_MAX_VALUE (ptrdiff_type_node));
pref->offrng[0] += orng[0];
pref->offrng[1] += orng[1];