aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-05-16 02:30:38 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-05-15 20:30:38 -0600
commit7ad491c6368516f2fa649d215f1782011465bb60 (patch)
tree15808048f761f3c987381ce81093173c0965ad25
parente4a148963e82ff2f34c794de0ad7ad3fa2e7b123 (diff)
downloadgcc-7ad491c6368516f2fa649d215f1782011465bb60.zip
gcc-7ad491c6368516f2fa649d215f1782011465bb60.tar.gz
gcc-7ad491c6368516f2fa649d215f1782011465bb60.tar.bz2
PR tree-optimization/85753 - missing -Wrestrict on memcpy into a member array
gcc/ChangeLog: PR tree-optimization/85753 * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Handle RECORD_TYPE in addition to ARRAY_TYPE. gcc/testsuite/ChangeLog: PR tree-optimization/85753 * gcc.dg/Wrestrict-10.c: Adjust. * gcc.dg/Wrestrict-16.c: New test. From-SVN: r260280
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/gimple-ssa-warn-restrict.c40
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/Wrestrict-10.c2
-rw-r--r--gcc/testsuite/gcc.dg/Wrestrict-16.c88
5 files changed, 122 insertions, 20 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 53fcbb1..80097cb 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,11 @@
2018-05-15 Martin Sebor <msebor@redhat.com>
+ PR tree-optimization/85753
+ * gimple-ssa-warn-restrict.c (builtin_memref::builtin_memref): Handle
+ RECORD_TYPE in addition to ARRAY_TYPE.
+
+2018-05-15 Martin Sebor <msebor@redhat.com>
+
PR middle-end/85643
* calls.c (get_attr_nonstring_decl): Handle MEM_REF.
diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c
index 3d0664d..9f23f57 100644
--- a/gcc/gimple-ssa-warn-restrict.c
+++ b/gcc/gimple-ssa-warn-restrict.c
@@ -263,27 +263,29 @@ builtin_memref::builtin_memref (tree expr, tree size)
else
sizrange[1] = maxobjsize;
+ if (!DECL_P (base))
+ return;
+
+ /* If the offset could be in the range of the referenced object
+ constrain its bounds so neither exceeds those of the object. */
+ if (offrange[0] < 0 && offrange[1] > 0)
+ offrange[0] = 0;
+
+ offset_int maxoff = maxobjsize;
tree basetype = TREE_TYPE (base);
- if (DECL_P (base) && TREE_CODE (basetype) == ARRAY_TYPE)
+ if (TREE_CODE (basetype) == ARRAY_TYPE
+ && ref
+ && array_at_struct_end_p (ref))
+ ; /* Use the maximum possible offset for last member arrays. */
+ else if (tree basesize = TYPE_SIZE_UNIT (basetype))
+ maxoff = wi::to_offset (basesize);
+
+ if (offrange[0] >= 0)
{
- /* If the offset could be in range of the referenced object
- constrain its bounds so neither exceeds those of the object. */
- if (offrange[0] < 0 && offrange[1] > 0)
- offrange[0] = 0;
-
- offset_int maxoff = maxobjsize;
- if (ref && array_at_struct_end_p (ref))
- ; /* Use the maximum possible offset for last member arrays. */
- else if (tree basesize = TYPE_SIZE_UNIT (basetype))
- maxoff = wi::to_offset (basesize);
-
- if (offrange[0] >= 0)
- {
- if (offrange[1] < 0)
- offrange[1] = offrange[0] <= maxoff ? maxoff : maxobjsize;
- else if (offrange[0] <= maxoff && offrange[1] > maxoff)
- offrange[1] = maxoff;
- }
+ if (offrange[1] < 0)
+ offrange[1] = offrange[0] <= maxoff ? maxoff : maxobjsize;
+ else if (offrange[0] <= maxoff && offrange[1] > maxoff)
+ offrange[1] = maxoff;
}
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b6e0e78..00f3c62 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2018-05-15 Martin Sebor <msebor@redhat.com>
+ PR tree-optimization/85753
+ * gcc.dg/Wrestrict-10.c: Adjust.
+ * gcc.dg/Wrestrict-16.c: New test.
+
+2018-05-15 Martin Sebor <msebor@redhat.com>
+
PR middle-end/85643
* c-c++-common/attr-nonstring-7.c: New test.
diff --git a/gcc/testsuite/gcc.dg/Wrestrict-10.c b/gcc/testsuite/gcc.dg/Wrestrict-10.c
index a5a5ff1..c412e42 100644
--- a/gcc/testsuite/gcc.dg/Wrestrict-10.c
+++ b/gcc/testsuite/gcc.dg/Wrestrict-10.c
@@ -58,7 +58,7 @@ test_arr_strncat_2 (void)
void __attribute__ ((noclone, noinline))
test_arr_strcpy_1 (void)
{
- strcpy (&b.a[i], b.a);
+ strcpy (&b.a[i], b.a); /* { dg-warning "\\\[-Wrestrict" } */
}
void __attribute__ ((noclone, noinline))
diff --git a/gcc/testsuite/gcc.dg/Wrestrict-16.c b/gcc/testsuite/gcc.dg/Wrestrict-16.c
new file mode 100644
index 0000000..196d2c5
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wrestrict-16.c
@@ -0,0 +1,88 @@
+/* PR tree-optimization/85753 - missing -Wrestrict on memcpy into a member
+ array
+ { dg-do compile }
+ { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
+
+#define memcpy __builtin_memcpy
+
+char a[16];
+
+struct { char a[16]; } x;
+
+/* Exercise aggregate types. */
+
+void test_aggr_idx_nowarn (int i, int j)
+{
+ memcpy (&a[i], &a[j], 7);
+ memcpy (&x.a[i], &x.a[j], 7);
+}
+
+void test_aggr_idx_warn (int i, int j)
+{
+ memcpy (&a[i], &a[j], 9); /* { dg-warning "\\\[-Wrestrict" } */
+ memcpy (&x.a[i], &x.a[j], 9); /* { dg-warning "\\\[-Wrestrict" } */
+}
+
+void test_aggr_off_nowarn (int i, int j)
+{
+ memcpy (a + i, a + j, 5);
+ memcpy (x.a + i, x.a + j, 5);
+}
+
+void test_aggr_off_warn (int i, int j)
+{
+ memcpy (a + i, a + j, 9); /* { dg-warning "\\\[-Wrestrict" } */
+ memcpy (x.a + i, x.a + j, 9); /* { dg-warning "\\\[-Wrestrict" } */
+}
+
+
+void sink (void*);
+
+#define T(call) sink (call)
+
+
+/* Also exercise basic types. */
+
+#ifdef __UINT32_TYPE__
+
+__UINT32_TYPE__ i32;
+
+void test_basic_32 (int i, int j)
+{
+ char *p = (char*)&i32;
+
+ T (memcpy (&p[i], &p[j], 1));
+ T (memcpy (&p[i], &p[j], 2));
+ T (memcpy (&p[i], &p[j], 3)); /* { dg-warning "\\\[-Wrestrict" } */
+
+ T (memcpy (p + i, p + j, 1));
+ T (memcpy (p + i, p + j, 2));
+ T (memcpy (p + i, p + j, 3)); /* { dg-warning "\\\[-Wrestrict" } */
+}
+
+#endif
+
+#ifdef __UINT64_TYPE__
+
+__UINT64_TYPE__ i64;
+
+void test_basic_64 (int i, int j)
+{
+ char *p = (char*)&i64;
+
+ T (memcpy (&p[i], &p[j], 1));
+ T (memcpy (&p[i], &p[j], 2));
+ T (memcpy (&p[i], &p[j], 3));
+ T (memcpy (&p[i], &p[j], 5)); /* { dg-warning "\\\[-Wrestrict" } */
+ T (memcpy (&p[i], &p[j], 6)); /* { dg-warning "\\\[-Wrestrict" } */
+ T (memcpy (&p[i], &p[j], 7)); /* { dg-warning "\\\[-Wrestrict" } */
+
+ T (memcpy (p + i, p + j, 1));
+ T (memcpy (p + i, p + j, 2));
+ T (memcpy (p + i, p + j, 3));
+ T (memcpy (p + i, p + j, 5)); /* { dg-warning "\\\[-Wrestrict" } */
+ T (memcpy (p + i, p + j, 6)); /* { dg-warning "\\\[-Wrestrict" } */
+ T (memcpy (p + i, p + j, 7)); /* { dg-warning "\\\[-Wrestrict" } */
+}
+
+#endif