re PR other/83508 ([arm] c-c++-common/Wrestrict.c fails since r255836)
authorMartin Sebor <msebor@redhat.com>
Mon, 15 Jan 2018 06:15:09 +0000 (06:15 +0000)
committerJeff Law <law@gcc.gnu.org>
Mon, 15 Jan 2018 06:15:09 +0000 (23:15 -0700)
PR other/83508
* builtins.c (check_access): Avoid warning when the no-warning bit
is set.

PR other/83508
* gcc.dg/Wstringop-overflow-2.c: New test.

From-SVN: r256683

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wstringop-overflow-2.c [new file with mode: 0644]

index 0d908279e9c8f6e2452723114cc359ee52c8a04f..ffcf36af5398bdfaf699023318106bc8414a2d09 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-14  Martin Sebor  <msebor@redhat.com>
+
+       PR other/83508
+       * builtins.c (check_access): Avoid warning when the no-warning bit
+       is set.
+
 2018-01-14  Cory Fields  <cory-nospam-@coryfields.com>
 
        * tree-ssa-loop-im.c (sort_bbs_in_loop_postorder_cmp): Stabilize sort.
index a0d0a10d38fcdb3e3204f32e887d77bff6ba28a4..d9f1e476cb001657b43353b6fd28bffccb20fb33 100644 (file)
@@ -3154,6 +3154,9 @@ check_access (tree exp, tree, tree, tree dstwrite,
              || (tree_fits_uhwi_p (dstwrite)
                  && tree_int_cst_lt (dstwrite, range[0]))))
        {
+         if (TREE_NO_WARNING (exp))
+           return false;
+
          location_t loc = tree_nonartificial_location (exp);
          loc = expansion_point_location_if_in_system_header (loc);
 
@@ -3213,6 +3216,9 @@ check_access (tree exp, tree, tree, tree dstwrite,
 
          if (tree_int_cst_lt (maxobjsize, range[0]))
            {
+             if (TREE_NO_WARNING (exp))
+               return false;
+
              /* Warn about crazy big sizes first since that's more
                 likely to be meaningful than saying that the bound
                 is greater than the object size if both are big.  */
@@ -3234,6 +3240,9 @@ check_access (tree exp, tree, tree, tree dstwrite,
 
          if (dstsize != maxobjsize && tree_int_cst_lt (dstsize, range[0]))
            {
+             if (TREE_NO_WARNING (exp))
+               return false;
+
              if (tree_int_cst_equal (range[0], range[1]))
                warning_at (loc, opt,
                            "%K%qD specified bound %E "
@@ -3257,6 +3266,9 @@ check_access (tree exp, tree, tree, tree dstwrite,
       && dstwrite && range[0]
       && tree_int_cst_lt (slen, range[0]))
     {
+      if (TREE_NO_WARNING (exp))
+       return false;
+
       location_t loc = tree_nonartificial_location (exp);
 
       if (tree_int_cst_equal (range[0], range[1]))
index a7b0364526f73d272145155cd3c2639e57ff0426..37f54de8146ec18ecb2c57b753cd8182597c7e0b 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-10  Martin Sebor  <msebor@redhat.com>
+
+       PR other/83508
+       * gcc.dg/Wstringop-overflow-2.c: New test.
+
 2018-01-14  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/83811
diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-2.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-2.c
new file mode 100644 (file)
index 0000000..6e3e2ca
--- /dev/null
@@ -0,0 +1,30 @@
+/* PR tree-optimization/83508 - c-c++-common/Wrestrict.c fails since r255836
+   Test to verify that only one of -Wrestrict and -Wstringop-overflow is
+   issued for a problem where either would be appropriate.
+   { dg-do compile }
+   { dg-options "-O2 -Wrestrict -Wstringop-overflow" } */
+
+#define DIFF_MAX __PTRDIFF_MAX__
+
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __SIZE_TYPE__ size_t;
+
+void sink (void*);
+
+void f (ptrdiff_t i, size_t n)
+{
+  if (i < DIFF_MAX - 2 || DIFF_MAX - 1 > i)
+    i = DIFF_MAX - 2;
+
+  if (n < 4 || 5 < n)
+    n = 4;
+
+  char a[8] = "012";
+
+  /* The following could very well be diagnosed by -Wstringop-overflow
+     instead but there's no way to verify that only one of the two
+     warnings is issued and the choice of -Wrestrict simply reflects
+     the fact that -Wrestrict runs before -Wstringop-overflow.  */
+  __builtin_strncpy (a + i, a, n);   /* { dg-warning "\\\[-Wrestrict]" } */
+  sink (a);
+}