summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>2018-01-07 04:19:35 +0000
committerlaw <law@138bc75d-0d04-0410-961f-82ee72b054a4>2018-01-07 04:19:35 +0000
commit209394793cce52892ec4d5364e3d63073b2a5d7b (patch)
tree089e39031abaa2049faac69072192fed7554808a
parent3b25b53c7f08068cce9651b742441d41b96515d7 (diff)
downloadgcc-209394793cce52892ec4d5364e3d63073b2a5d7b.tar.gz
2018-01-06 Martin Sebor <msebor@redhat.com>
PR tree-optimization/83640 * gimple-ssa-warn-restrict.c (builtin_access::builtin_access): Avoid subtracting negative offset from size. (builtin_access::overlap): Adjust offset bounds of the access to fall within the size of the object if possible. PR tree-optimization/83640 * gcc.dg/Wrestrict-6.c: New test. * gcc.dg/pr83640.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@256319 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/gimple-ssa-warn-restrict.c2
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/Wrestrict-6.c66
-rw-r--r--gcc/testsuite/gcc.dg/pr83640.c15
5 files changed, 95 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index bade4b29349..cd9971d0d1a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2018-01-06 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/83640
+ * gimple-ssa-warn-restrict.c (builtin_access::builtin_access): Avoid
+ subtracting negative offset from size.
+ (builtin_access::overlap): Adjust offset bounds of the access to fall
+ within the size of the object if possible.
+
2018-01-06 Richard Sandiford <richard.sandiford@linaro.org>
PR rtl-optimization/83699
diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c
index 066be1a0438..6384c5714ec 100644
--- a/gcc/gimple-ssa-warn-restrict.c
+++ b/gcc/gimple-ssa-warn-restrict.c
@@ -1371,8 +1371,6 @@ maybe_diag_overlap (location_t loc, gcall *call, builtin_access &acs)
return true;
}
- /* Issue "may overlap" diagnostics below. */
-
/* Use more concise wording when one of the offsets is unbounded
to avoid confusing the user with large and mostly meaningless
numbers. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2b9d7aeec2d..3b1548dde20 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-06 Martin Sebor <msebor@redhat.com>
+
+ PR tree-optimization/83640
+ * gcc.dg/Wrestrict-6.c: New test.
+ * gcc.dg/pr83640.c: New test.
+
2018-01-06 Richard Sandiford <richard.sandiford@linaro.org>
* gcc.target/aarch64/reg-alloc-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/Wrestrict-6.c b/gcc/testsuite/gcc.dg/Wrestrict-6.c
new file mode 100644
index 00000000000..c1bb373c5cd
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wrestrict-6.c
@@ -0,0 +1,66 @@
+/* PR tree-optimization/83640 - ice in generic_overlap, at
+ gimple-ssa-warn-restrict.c:814
+ Test to verify that a pointer offset range whose upper bound is less
+ than its lower bound (when interpreted as a signed integer) is handled
+ correctly.
+ { dg-do compile }
+ { dg-options "-O2 -Wrestrict" } */
+
+#include "range.h"
+
+extern char* strcpy (char*, const char*);
+extern char* stpcpy (char*, const char*);
+
+void sink (void*);
+
+void warn_2_smax_p2 (void)
+{
+ char a[7] = "01234";
+
+ char *d = a;
+
+ ptrdiff_t i = UR (2, DIFF_MAX + (size_t)2);
+
+ strcpy (d, d + i); /* { dg-warning "accessing between 0 and 4 bytes at offsets 0 and \\\[2, -\[0-9\]+] may overlap up to 2 bytes at offset 2" } */
+
+ sink (d);
+}
+
+void nowarn_3_smax_p2 (void)
+{
+ char a[7] = "12345";
+
+ char *d = a;
+
+ ptrdiff_t i = UR (3, DIFF_MAX + (size_t)2);
+
+ strcpy (d, d + i);
+
+ sink (d);
+}
+
+void warn_2u_smax_p2 (void)
+{
+ char a[7] = "23456";
+
+ char *d = a;
+
+ size_t i = UR (2, DIFF_MAX + (size_t)2);
+
+ strcpy (d, d + i); /* { dg-warning "accessing between 0 and 4 bytes at offsets 0 and \\\[2, -\[0-9\]+] may overlap up to 2 bytes at offset 2" } */
+
+ sink (d);
+}
+
+void nowarn_3u_smax_p2 (void)
+{
+ char a[7] = "34567";
+
+ char *d = a;
+
+ size_t i = UR (3, DIFF_MAX + (size_t)2);
+
+ strcpy (d, d + i);
+
+ sink (d);
+}
diff --git a/gcc/testsuite/gcc.dg/pr83640.c b/gcc/testsuite/gcc.dg/pr83640.c
new file mode 100644
index 00000000000..3b4d1be7278
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr83640.c
@@ -0,0 +1,15 @@
+/* PR tree-optimization/83640 - ice in generic_overlap, at
+ gimple-ssa-warn-restrict.c:814
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+char *foo (void);
+
+void
+bar (char *b, char *c)
+{
+ b = c;
+ c = foo ();
+ __builtin_strcat (c, "*/");
+ __builtin_strcat (c, b);
+}