[4/4] - Replace uses of old get_range_strlen with the new one.

This change switches the remaining get_range_strlen() callers
to use the new overload of the function that takes a strlen_data_t
argument.  There are no functional changes here.
[4/4] - Replace uses of old get_range_strlen with the new one.

gcc/ChangeLog:

	* builtins.c (check_access): Use new get_range_strlen.
	(check_strncat_sizes): Ditto.
	(expand_builtin_strncat): Ditto.
	* calls.c (maybe_warn_nonstring_arg): Ditto.
	* gimple-fold.h (get_range_strlen): Remove unused overload.
	* gimple-fold.c (get_range_strlen): Ditto.
	(gimple_fold_builtin_strlen): Use new get_range_strlen.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 3e31af4..daa520b 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -3235,8 +3235,10 @@ check_access (tree exp, tree, tree, tree dstwrite,
 	     the upper bound given by MAXREAD add one to it for
 	     the terminating nul.  Otherwise, set it to one for
 	     the same reason, or to MAXREAD as appropriate.  */
-	  get_range_strlen (srcstr, range, /* eltsize = */ 1,
-			    /* strict = */ false );
+	  strlen_data_t lendata (/* eltsize = */ 1);
+	  get_range_strlen (srcstr, &lendata);
+	  range[0] = lendata.minlen;
+	  range[1] = lendata.maxsize;
 	  if (range[0] && (!maxread || TREE_CODE (maxread) == INTEGER_CST))
 	    {
 	      if (maxread && tree_int_cst_le (maxread, range[0]))
@@ -4107,8 +4109,8 @@ check_strncat_sizes (tree exp, tree objsize)
 
   /* Try to determine the range of lengths that the source expression
      refers to.  */
-  tree lenrange[2];
-  get_range_strlen (src, lenrange, /* eltsize = */ 1, /* strict = */ false);
+  strlen_data_t lendata (/* eltsize = */ 1);
+  get_range_strlen (src, &lendata);
 
   /* Try to verify that the destination is big enough for the shortest
      string.  */
@@ -4122,8 +4124,8 @@ check_strncat_sizes (tree exp, tree objsize)
     }
 
   /* Add one for the terminating nul.  */
-  tree srclen = (lenrange[0]
-		 ? fold_build2 (PLUS_EXPR, size_type_node, lenrange[0],
+  tree srclen = (lendata.minlen
+		 ? fold_build2 (PLUS_EXPR, size_type_node, lendata.minlen,
 				size_one_node)
 		 : NULL_TREE);
 
@@ -4177,11 +4179,13 @@ expand_builtin_strncat (tree exp, rtx)
   /* Try to determine the range of lengths that the source expression
      refers to.  Since the lengths are only used for warning and not
      for code generation disable strict mode below.  */
-  tree lenrange[2];
-  if (slen)
-    lenrange[0] = lenrange[1] = slen;
-  else
-    get_range_strlen (src, lenrange, /* eltsize = */ 1, /* strict = */ false);
+  tree maxlen = slen;
+  if (!maxlen)
+    {
+      strlen_data_t lendata (/* eltsize = */ 1);
+      get_range_strlen (src, &lendata);
+      maxlen = lendata.maxsize;
+    }
 
   /* Try to verify that the destination is big enough for the shortest
      string.  First try to determine the size of the destination object
@@ -4189,8 +4193,8 @@ expand_builtin_strncat (tree exp, rtx)
   tree destsize = compute_objsize (dest, warn_stringop_overflow - 1);
 
   /* Add one for the terminating nul.  */
-  tree srclen = (lenrange[0]
-		 ? fold_build2 (PLUS_EXPR, size_type_node, lenrange[0],
+  tree srclen = (maxlen
+		 ? fold_build2 (PLUS_EXPR, size_type_node, maxlen,
 				size_one_node)
 		 : NULL_TREE);
 
diff --git a/gcc/calls.c b/gcc/calls.c
index 617757e6..2c1cd1b 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -1556,12 +1556,11 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
   /* The bound argument to a bounded string function like strncpy.  */
   tree bound = NULL_TREE;
 
-  /* The range of lengths of a string argument to one of the comparison
+  /* The longest known or possible string argument to one of the comparison
      functions.  If the length is less than the bound it is used instead.
-     Since the lengths are only used for warning and not for code
-     generation disable strict mode in the calls to get_range_strlen
-     below.  */
-  tree lenrng[2] = { NULL_TREE, NULL_TREE };
+     Since the length is only used for warning and not for code generation
+     disable strict mode in the calls to get_range_strlen below.  */
+  tree maxlen = NULL_TREE;
 
   /* It's safe to call "bounded" string functions with a non-string
      argument since the functions provide an explicit bound for this
@@ -1581,12 +1580,15 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
 	   and to adjust the range of the bound of the bounded ones.  */
 	for (unsigned argno = 0;
 	     argno < MIN (nargs, 2)
-	     && !(lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST); argno++)
+	       && !(maxlen && TREE_CODE (maxlen) == INTEGER_CST); argno++)
 	  {
 	    tree arg = CALL_EXPR_ARG (exp, argno);
 	    if (!get_attr_nonstring_decl (arg))
-	      get_range_strlen (arg, lenrng, /* eltsize = */ 1,
-				/* strict = */ false);
+	      {
+		strlen_data_t lendata (/* eltsize = */ 1);
+		get_range_strlen (arg, &lendata);
+		maxlen = lendata.maxsize;
+	      }
 	  }
       }
       /* Fall through.  */
@@ -1607,9 +1609,11 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
       {
 	tree arg = CALL_EXPR_ARG (exp, 0);
 	if (!get_attr_nonstring_decl (arg))
-	  get_range_strlen (arg, lenrng, /* eltsize = */ 1,
-			    /* strict = */ false);
-
+	  {
+	    strlen_data_t lendata (/* eltsize = */ 1);
+	    get_range_strlen (arg, &lendata);
+	    maxlen = lendata.maxsize;
+	  }
 	if (nargs > 1)
 	  bound = CALL_EXPR_ARG (exp, 1);
 	break;
@@ -1650,28 +1654,28 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
 	}
     }
 
-  if (lenrng[1] && !integer_all_onesp (lenrng[1]))
+  if (maxlen && !integer_all_onesp (maxlen))
     {
       /* Add one for the nul.  */
-      lenrng[1] = const_binop (PLUS_EXPR, TREE_TYPE (lenrng[1]),
-			       lenrng[1], size_one_node);
+      maxlen = const_binop (PLUS_EXPR, TREE_TYPE (maxlen), maxlen,
+			    size_one_node);
 
       if (!bndrng[0])
 	{
 	  /* Conservatively use the upper bound of the lengths for
 	     both the lower and the upper bound of the operation.  */
-	  bndrng[0] = lenrng[1];
-	  bndrng[1] = lenrng[1];
+	  bndrng[0] = maxlen;
+	  bndrng[1] = maxlen;
 	  bound = void_type_node;
 	}
       else
 	{
 	  /* Replace the bound on the operation with the upper bound
 	     of the length of the string if the latter is smaller.  */
-	  if (tree_int_cst_lt (lenrng[1], bndrng[0]))
-	    bndrng[0] = lenrng[1];
-	  else if (tree_int_cst_lt (lenrng[1], bndrng[1]))
-	    bndrng[1] = lenrng[1];
+	  if (tree_int_cst_lt (maxlen, bndrng[0]))
+	    bndrng[0] = maxlen;
+	  else if (tree_int_cst_lt (maxlen, bndrng[1]))
+	    bndrng[1] = maxlen;
 	}
     }
 
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index bfa9f17..94d98d5 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -1660,52 +1660,6 @@ get_range_strlen (tree arg, strlen_data_t *pdata)
   return !integer_all_onesp (pdata->maxlen);
 }
 
-/* Determine the minimum and maximum value or string length that ARG
-   refers to and store each in the first two elements of MINMAXLEN.
-   For expressions that point to strings of unknown lengths that are
-   character arrays, use the upper bound of the array as the maximum
-   length.  For example, given an expression like 'x ? array : "xyz"'
-   and array declared as 'char array[8]', MINMAXLEN[0] will be set
-   to 0 and MINMAXLEN[1] to 7, the longest string that could be
-   stored in array.
-   Return true if the range of the string lengths has been obtained
-   from the upper bound of an array at the end of a struct.  Such
-   an array may hold a string that's longer than its upper bound
-   due to it being used as a poor-man's flexible array member.
-
-   STRICT is true if it will handle PHIs and COND_EXPRs conservatively
-   and false if PHIs and COND_EXPRs are to be handled optimistically,
-   if we can determine string length minimum and maximum; it will use
-   the minimum from the ones where it can be determined.
-   STRICT false should be only used for warning code.
-   When non-null, clear *NONSTR if ARG refers to a constant array
-   that is known not be nul-terminated.  Otherwise set it to
-   the declaration of the constant non-terminated array.
-
-   ELTSIZE is 1 for normal single byte character strings, and 2 or
-   4 for wide characer strings.  ELTSIZE is by default 1.  */
-
-void
-get_range_strlen (tree arg, tree minmaxlen[2], unsigned eltsize,
-		  bool strict /* = true */, tree *nonstr /* = NULL */)
-{
-  strlen_data_t data (eltsize);
-
-  get_range_strlen (arg, &data);
-  bool unbounded = integer_all_onesp (data.maxlen);
-
-  if (strict && unbounded)
-    minmaxlen[0] = minmaxlen[1] = NULL_TREE;
-  else
-    {
-      minmaxlen[0] = unbounded ? ssize_int (0) : data.minlen;
-      minmaxlen[1] = data.maxlen;
-    }
-
-  if (nonstr)
-    *nonstr = data.nonstr;
-}
-
 /* Return the maximum value for ARG given TYPE (see StrlenType).
    For ARG of pointer types, NONSTR indicates if the caller is
    prepared to handle unterminated strings.   For integer ARG
@@ -3703,30 +3657,25 @@ gimple_fold_builtin_strlen (gimple_stmt_iterator *gsi)
   gimple *stmt = gsi_stmt (*gsi);
   tree arg = gimple_call_arg (stmt, 0);
 
-  /* NONSTR is set to non-null if ARG refers to an unterminated array.
-     Bail if the argument is unterminated, is a flexible array member
-     or if the length or its range cannot be determined.  */
-  tree nonstr;
-  tree lenrange[2];
-  get_range_strlen (arg, lenrange, /* eltsize = */ 1,
-		    /* strict = */ true, &nonstr);
-  if (nonstr
-      || !lenrange[0] || TREE_CODE (lenrange[0]) != INTEGER_CST
-      || !lenrange[1] || TREE_CODE (lenrange[1]) != INTEGER_CST
-      || integer_all_onesp (lenrange[1]))
+  /* Bail if the argument is unterminated, or if the length
+     or its range cannot be determined.  */
+  strlen_data_t lendata (/* eltsize = */ 1);
+  if (!get_range_strlen (arg, &lendata)
+      || TREE_CODE (lendata.minlen) != INTEGER_CST
+      || TREE_CODE (lendata.maxlen) != INTEGER_CST)
     return false;
 
-  if (tree_int_cst_equal (lenrange[0], lenrange[1]))
+  if (tree_int_cst_equal (lendata.minlen, lendata.maxlen))
     {
-      lenrange[0] = force_gimple_operand_gsi (gsi, lenrange[0], true, NULL,
-					      true, GSI_SAME_STMT);
-      replace_call_with_value (gsi, lenrange[0]);
+      tree len = force_gimple_operand_gsi (gsi, lendata.minlen, true,
+					   NULL, true, GSI_SAME_STMT);
+      replace_call_with_value (gsi, len);
       return true;
     }
 
-  /* Set the strlen() range to [0, LENRANGE[1]]*/
+  /* Set the strlen() range to [0, LENDATA.MAXLEN].  */
   if (tree lhs = gimple_call_lhs (stmt))
-    set_strlen_range (lhs, wi::to_wide (lenrange[1]));
+    set_strlen_range (lhs, wi::to_wide (lendata.maxlen));
 
   return false;
 }
diff --git a/gcc/gimple-fold.h b/gcc/gimple-fold.h
index 5e5c24b..5c33bde 100644
--- a/gcc/gimple-fold.h
+++ b/gcc/gimple-fold.h
@@ -93,9 +93,6 @@ enum StrlenType {
   IntegerValue
 };
 
-extern void get_range_strlen (tree, tree[2], unsigned = 1, bool = true,
-			      tree * = NULL)
-  ATTRIBUTE_NONNULL (1) ATTRIBUTE_NONNULL (2);
 extern void gimplify_and_update_call_from_tree (gimple_stmt_iterator *, tree);
 extern bool fold_stmt (gimple_stmt_iterator *);
 extern bool fold_stmt (gimple_stmt_iterator *, tree (*) (tree));

Reply via email to