]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/89720 - Spurious -Warray-bounds warning on a range with max...
authormsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 18 Mar 2019 23:48:50 +0000 (23:48 +0000)
committermsebor <msebor@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 18 Mar 2019 23:48:50 +0000 (23:48 +0000)
gcc/ChangeLog:

PR tree-optimization/89720
* tree-vrp.c (vrp_prop::check_mem_ref): Treat range with max < min
more conservatively, the same as anti-range.

gcc/testsuite/ChangeLog:

PR tree-optimization/89720
* gcc.dg/Warray-bounds-42.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@269785 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Warray-bounds-42.c [new file with mode: 0644]
gcc/tree-vrp.c

index a8d41e4130392dfa292aac80dade3f24e3283ef1..e0df9e02d7cd3f13ea056180eb0fd93c9c50aceb 100644 (file)
@@ -1,3 +1,9 @@
+2019-03-18  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/89720
+       * tree-vrp.c (vrp_prop::check_mem_ref): Treat range with max < min
+       more conservatively, the same as anti-range.
+
 2019-03-18  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/88945
index 267b2cd4858ed61e43729a135cb4949bb1773377..97bfd50c5ed8723351c6fb01a1a4b9c20be3ac90 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-18  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/89720
+       * gcc.dg/Warray-bounds-42.c: New test.
+
 2019-03-19  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR c++/89630
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-42.c b/gcc/testsuite/gcc.dg/Warray-bounds-42.c
new file mode 100644 (file)
index 0000000..005e145
--- /dev/null
@@ -0,0 +1,26 @@
+/* PR tree-optimization/89720 - Spurious -Warray-bounds warning on a range
+   with max < min
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+void f (char*, int);
+
+#if __SIZEOF_POINTER__ == 8
+
+void g (__INT64_TYPE__ i)
+{
+  char a[65536] = "";
+  char *p = a + (i & (__INT64_TYPE__)0xffffffff3fffffffLL);
+  f (p, *(p - 6));            /* { dg-bogus "\\\[-Warray-bounds" } */
+}
+
+#elif __SIZEOF_POINTER__ == 4
+
+void h (__INT32_TYPE__ i)
+{
+  char a[65536] = "";
+  char *p = a + (i & (__INT32_TYPE__)0x8fffffffLL);
+  f (p, *(p - 6));            /* { dg-bogus "\\\[-Warray-bounds" } */
+}
+
+#endif
index 1092fe045e2a37e9fe321cdd280077b2a94fc398..0a172719e5dfbaf8e5e5bfda5a059b8e96b05e54 100644 (file)
@@ -4546,9 +4546,9 @@ vrp_prop::check_mem_ref (location_t location, tree ref,
   const value_range *vr = NULL;
 
   /* Determine the offsets and increment OFFRANGE for the bounds of each.
-     The loop computes the the range of the final offset for expressions
-     such as (A + i0 + ... + iN)[CSTOFF] where i0 through iN are SSA_NAMEs
-     in some range.  */
+     The loop computes the range of the final offset for expressions such
+     as (A + i0 + ... + iN)[CSTOFF] where i0 through iN are SSA_NAMEs in
+     some range.  */
   while (TREE_CODE (arg) == SSA_NAME)
     {
       gimple *def = SSA_NAME_DEF_STMT (arg);
@@ -4583,26 +4583,21 @@ vrp_prop::check_mem_ref (location_t location, tree ref,
 
       if (vr->kind () == VR_RANGE)
        {
-         if (tree_int_cst_lt (vr->min (), vr->max ()))
+         offset_int min
+           = wi::to_offset (fold_convert (ptrdiff_type_node, vr->min ()));
+         offset_int max
+           = wi::to_offset (fold_convert (ptrdiff_type_node, vr->max ()));
+         if (min < max)
            {
-             offset_int min
-               = wi::to_offset (fold_convert (ptrdiff_type_node, vr->min ()));
-             offset_int max
-               = wi::to_offset (fold_convert (ptrdiff_type_node, vr->max ()));
-             if (min < max)
-               {
-                 offrange[0] += min;
-                 offrange[1] += max;
-               }
-             else
-               {
-                 offrange[0] += max;
-                 offrange[1] += min;
-               }
+             offrange[0] += min;
+             offrange[1] += max;
            }
          else
            {
-             /* Conservatively add [-MAXOBJSIZE -1, MAXOBJSIZE]
+             /* When MIN >= MAX, the offset is effectively in a union
+                of two ranges: [-MAXOBJSIZE -1, MAX] and [MIN, MAXOBJSIZE].
+                Since there is no way to represent such a range across
+                additions, conservatively add [-MAXOBJSIZE -1, MAXOBJSIZE]
                 to OFFRANGE.  */
              offrange[0] += arrbounds[0];
              offrange[1] += arrbounds[1];