gimple-fold.c (get_range_strlen): Minor logic cleanup.
authorMartin Sebor <msebor@redhat.com>
Mon, 31 Dec 2018 03:18:49 +0000 (03:18 +0000)
committerJeff Law <law@gcc.gnu.org>
Mon, 31 Dec 2018 03:18:49 +0000 (20:18 -0700)
* gimple-fold.c (get_range_strlen): Minor logic cleanup.  Add comments
on code's intent.

Co-Authored-By: Jeff Law <law@redhat.com>
From-SVN: r267483

gcc/ChangeLog
gcc/gimple-fold.c

index 1ee865e1de8ccf2372d1b0206b879936dc0ee44b..54585381cbe4e0611a31baa4f52182774a897120 100644 (file)
@@ -1,6 +1,9 @@
 2018-12-30  Martin Sebor  <msebor@redhat.com>
            Jeff Law  <law@redhat.com>
 
+       * gimple-fold.c (get_range_strlen): Minor logic cleanup.  Add comments
+       on code's intent.
+
        * gimple-fold.c (strlen_range_kind): New enum.
        (get_range_strlen): Update signature to use strlen_range_kind
        instead of type+fuzzy.
index 76fa328703c064cbe9115926c96f172a7d8fef87..fb43552bc3523ca4f2f61b41f99fb77c8bab6192 100644 (file)
@@ -1548,10 +1548,17 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited,
              if (!get_range_strlen (ops[i], length, visited, rkind,
                                     flexp, eltsize, nonstr))
                {
-                 if (rkind == SRK_LENRANGE_2)
-                   *maxlen = build_all_ones_cst (size_type_node);
-                 else
+                 if (rkind != SRK_LENRANGE_2)
                    return false;
+                 /* Set the upper bound to the maximum to prevent
+                    it from being adjusted in the next iteration but
+                    leave MINLEN and the more conservative MAXBOUND
+                    determined so far alone (or leave them null if
+                    they haven't been set yet).  That the MINLEN is
+                    in fact zero can be determined from MAXLEN being
+                    unbounded but the discovered minimum is used for
+                    diagnostics.  */
+                 *maxlen = build_all_ones_cst (size_type_node);
                }
            return true;
          }
@@ -1576,10 +1583,17 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited,
            if (!get_range_strlen (arg, length, visited, rkind, flexp,
                                   eltsize, nonstr))
              {
-               if (rkind == SRK_LENRANGE_2)
-                 *maxlen = build_all_ones_cst (size_type_node);
-               else
+               if (rkind != SRK_LENRANGE_2)
                  return false;
+               /* Set the upper bound to the maximum to prevent
+                  it from being adjusted in the next iteration but
+                  leave MINLEN and the more conservative MAXBOUND
+                  determined so far alone (or leave them null if
+                  they haven't been set yet).  That the MINLEN is
+                  in fact zero can be determined from MAXLEN being
+                  unbounded but the discovered minimum is used for
+                  diagnostics.  */
+               *maxlen = build_all_ones_cst (size_type_node);
              }
           }
         return true;