This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] Cleanup variable names and comments in preparation for fixing string length computations


In a variety of instances Martin changed some variable names to be more
descriptive or avoid shadowing problems.  I've pulled those changes into
a distinct patch to cut down on the noise in the meat of the patch.

Bootstrapped and regression tested on x86_64-linux-gnu.  My tester will
spin this on the other targets overnight.

Installing on the trunk.

jeff
commit 10098590534b40db6929c59f195559b5417f1e06
Author: Jeff Law <law@torsion.usersys.redhat.com>
Date:   Fri Dec 21 10:30:57 2018 -0500

            * builtins.c (unterminated_array): Rename "data" to "lendata".  Fix
            a few comments.
            (expand_builtin_strnlen, expand_builtin_stpcpy_1): Likewise.
            (fold_builtin_strlen): Likewise.
            * gimple-fold.c (get_range_strlen): Likewise.  Also rename a couple
            instances of "type" to "optype" and "arg" to "fld".

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a63e7745536..f1f9d70f25b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,13 @@
 2018-12-23  Martin Sebor  <msebor@redhat.com>
 	    Jeff Law  <law@redhat.com>
 
+	* builtins.c (unterminated_array): Rename "data" to "lendata".  Fix
+	a few comments.
+	(expand_builtin_strnlen, expand_builtin_stpcpy_1): Likewise.
+	(fold_builtin_strlen): Likewise.
+	* gimple-fold.c (get_range_strlen): Likewise.  Also rename a couple
+	instances of "type" to "optype" and "arg" to "fld".
+
 	* builtins.c (unterminated_array): Use empty brace initialization
 	for c_strlen_data.
 	(c_strlen, expand_builtin_strnlen): Likewise.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 4a82f58d5f4..0eb3df9ccc1 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -575,25 +575,25 @@ unterminated_array (tree exp, tree *size /* = NULL */, bool *exact /* = NULL */)
 {
   /* C_STRLEN will return NULL and set DECL in the info
      structure if EXP references a unterminated array.  */
-  c_strlen_data data = { };
-  tree len = c_strlen (exp, 1, &data);
-  if (len == NULL_TREE && data.len && data.decl)
+  c_strlen_data lendata = { };
+  tree len = c_strlen (exp, 1, &lendata);
+  if (len == NULL_TREE && lendata.len && lendata.decl)
      {
        if (size)
 	{
-	  len = data.len;
-	  if (data.off)
+	  len = lendata.len;
+	  if (lendata.off)
 	    {
-	      /* Constant offsets are already accounted for in data.len, but
-		 not in a SSA_NAME + CST expression.  */
-	      if (TREE_CODE (data.off) == INTEGER_CST)
+	      /* Constant offsets are already accounted for in LENDATA.MINLEN,
+		 but not in a SSA_NAME + CST expression.  */
+	      if (TREE_CODE (lendata.off) == INTEGER_CST)
 		*exact = true;
-	      else if (TREE_CODE (data.off) == PLUS_EXPR
-		       && TREE_CODE (TREE_OPERAND (data.off, 1)) == INTEGER_CST)
+	      else if (TREE_CODE (lendata.off) == PLUS_EXPR
+		       && TREE_CODE (TREE_OPERAND (lendata.off, 1)) == INTEGER_CST)
 		{
 		  /* Subtract the offset from the size of the array.  */
 		  *exact = false;
-		  tree temp = TREE_OPERAND (data.off, 1);
+		  tree temp = TREE_OPERAND (lendata.off, 1);
 		  temp = fold_convert (ssizetype, temp);
 		  len = fold_build2 (MINUS_EXPR, ssizetype, len, temp);
 		}
@@ -605,7 +605,7 @@ unterminated_array (tree exp, tree *size /* = NULL */, bool *exact /* = NULL */)
 
 	  *size = len;
 	}
-       return data.decl;
+       return lendata.decl;
      }
 
   return NULL_TREE;
@@ -3083,8 +3083,8 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
 
   /* FIXME: Change c_strlen() to return sizetype instead of ssizetype
      so these conversions aren't necessary.  */
-  c_strlen_data data { };
-  tree len = c_strlen (src, 0, &data, 1);
+  c_strlen_data lendata = { };
+  tree len = c_strlen (src, 0, &lendata, 1);
   if (len)
     len = fold_convert_loc (loc, TREE_TYPE (bound), len);
 
@@ -3106,12 +3106,12 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
 	       strnlen (&a[i], sizeof a)
 	     where the value of i is unknown.  Unless i's value is
 	     zero, the call is unsafe because the bound is greater. */
-	  data.decl = unterminated_array (src, &len, &exact);
-	  if (!data.decl)
+	  lendata.decl = unterminated_array (src, &len, &exact);
+	  if (!lendata.decl)
 	    return NULL_RTX;
 	}
 
-      if (data.decl
+      if (lendata.decl
 	  && !TREE_NO_WARNING (exp)
 	  && ((tree_int_cst_lt (len, bound))
 	      || !exact))
@@ -3127,7 +3127,7 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
 			       "of at most %E of unterminated array"),
 			  exp, func, bound, len))
 	    {
-	      inform (DECL_SOURCE_LOCATION (data.decl),
+	      inform (DECL_SOURCE_LOCATION (lendata.decl),
 		      "referenced argument declared here");
 	      TREE_NO_WARNING (exp) = true;
 	      return NULL_RTX;
@@ -3160,12 +3160,12 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
   bool exact = true;
   if (!len || TREE_CODE (len) != INTEGER_CST)
     {
-      data.decl = unterminated_array (src, &len, &exact);
-      if (!data.decl)
+      lendata.decl = unterminated_array (src, &len, &exact);
+      if (!lendata.decl)
 	return NULL_RTX;
     }
 
-  if (data.decl
+  if (lendata.decl
       && !TREE_NO_WARNING (exp)
       && (wi::ltu_p (wi::to_wide (len), min)
 	  || !exact))
@@ -3181,13 +3181,13 @@ expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
 			   "the size of at most %E of unterminated array"),
 		      exp, func, min.to_uhwi (), max.to_uhwi (), len))
 	{
-	  inform (DECL_SOURCE_LOCATION (data.decl),
+	  inform (DECL_SOURCE_LOCATION (lendata.decl),
 		  "referenced argument declared here");
 	  TREE_NO_WARNING (exp) = true;
 	}
     }
 
-  if (data.decl)
+  if (lendata.decl)
     return NULL_RTX;
 
   if (wi::gtu_p (min, wi::to_wide (len)))
@@ -4083,14 +4083,14 @@ expand_builtin_stpcpy_1 (tree exp, rtx target, machine_mode mode)
 	 compile-time, not an expression containing a string.  This is
 	 because the latter will potentially produce pessimized code
 	 when used to produce the return value.  */
-      c_strlen_data data = { };
+      c_strlen_data lendata = { };
       if (!c_getstr (src, NULL)
-	  || !(len = c_strlen (src, 0, &data, 1)))
+	  || !(len = c_strlen (src, 0, &lendata, 1)))
 	return expand_movstr (dst, src, target,
 			      /*retmode=*/ RETURN_END_MINUS_ONE);
 
-      if (data.decl && !TREE_NO_WARNING (exp))
-	warn_string_no_nul (EXPR_LOCATION (exp), "stpcpy", src, data.decl);
+      if (lendata.decl && !TREE_NO_WARNING (exp))
+	warn_string_no_nul (EXPR_LOCATION (exp), "stpcpy", src, lendata.decl);
 
       lenp1 = size_binop_loc (loc, PLUS_EXPR, len, ssize_int (1));
       ret = expand_builtin_mempcpy_args (dst, src, lenp1,
@@ -8567,22 +8567,22 @@ fold_builtin_strlen (location_t loc, tree type, tree arg)
     return NULL_TREE;
   else
     {
-      c_strlen_data data = { };
-      tree len = c_strlen (arg, 0, &data);
+      c_strlen_data lendata = { };
+      tree len = c_strlen (arg, 0, &lendata);
 
       if (len)
 	return fold_convert_loc (loc, type, len);
 
-      if (!data.decl)
-	c_strlen (arg, 1, &data);
+      if (!lendata.decl)
+	c_strlen (arg, 1, &lendata);
 
-      if (data.decl)
+      if (lendata.decl)
 	{
 	  if (EXPR_HAS_LOCATION (arg))
 	    loc = EXPR_LOCATION (arg);
 	  else if (loc == UNKNOWN_LOCATION)
 	    loc = input_location;
-	  warn_string_no_nul (loc, "strlen", arg, data.decl);
+	  warn_string_no_nul (loc, "strlen", arg, lendata.decl);
 	}
 
       return NULL_TREE;
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index af509740bb3..0ba15149890 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -1335,16 +1335,16 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
 	}
       else
 	{
-	  c_strlen_data data = { };
-	  val = c_strlen (arg, 1, &data, eltsize);
+	  c_strlen_data lendata = { };
+	  val = c_strlen (arg, 1, &lendata, eltsize);
 
 	  /* If we potentially had a non-terminated string, then
 	     bubble that information up to the caller.  */
-	  if (!val && data.decl)
+	  if (!val && lendata.decl)
 	    {
-	      *nonstr = data.decl;
-	      *minlen = data.len;
-	      *maxlen = data.len;
+	      *nonstr = lendata.decl;
+	      *minlen = lendata.len;
+	      *maxlen = lendata.len;
 	      return type == 0 ? false : true;
 	    }
 	}
@@ -1358,20 +1358,21 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
 
 	  if (TREE_CODE (arg) == ARRAY_REF)
 	    {
-	      tree type = TREE_TYPE (TREE_OPERAND (arg, 0));
+	      tree optype = TREE_TYPE (TREE_OPERAND (arg, 0));
 
 	      /* Determine the "innermost" array type.  */
-	      while (TREE_CODE (type) == ARRAY_TYPE
-		     && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
-		type = TREE_TYPE (type);
+	      while (TREE_CODE (optype) == ARRAY_TYPE
+		     && TREE_CODE (TREE_TYPE (optype)) == ARRAY_TYPE)
+		optype = TREE_TYPE (optype);
 
 	      /* Avoid arrays of pointers.  */
-	      tree eltype = TREE_TYPE (type);
-	      if (TREE_CODE (type) != ARRAY_TYPE
+	      tree eltype = TREE_TYPE (optype);
+	      if (TREE_CODE (optype) != ARRAY_TYPE
 		  || !INTEGRAL_TYPE_P (eltype))
 		return false;
 
-	      val = TYPE_SIZE_UNIT (type);
+	      /* Fail when the array bound is unknown or zero.  */
+	      val = TYPE_SIZE_UNIT (optype);
 	      if (!val || integer_zerop (val))
 		return false;
 
@@ -1382,7 +1383,7 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
 	      *minlen = ssize_int (0);
 
 	      if (TREE_CODE (TREE_OPERAND (arg, 0)) == COMPONENT_REF
-		  && type == TREE_TYPE (TREE_OPERAND (arg, 0))
+		  && optype == TREE_TYPE (TREE_OPERAND (arg, 0))
 		  && array_at_struct_end_p (TREE_OPERAND (arg, 0)))
 		*flexp = true;
 	    }
@@ -1401,16 +1402,17 @@ get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
 	      if (array_at_struct_end_p (arg))
 		*flexp = true;
 
-	      arg = TREE_OPERAND (arg, 1);
+	      tree fld = TREE_OPERAND (arg, 1);
 
-	      tree type = TREE_TYPE (arg);
+	      tree optype = TREE_TYPE (fld);
 
-	      while (TREE_CODE (type) == ARRAY_TYPE
-		     && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE)
-		type = TREE_TYPE (type);
+	      /* Determine the "innermost" array type.  */
+	      while (TREE_CODE (optype) == ARRAY_TYPE
+		     && TREE_CODE (TREE_TYPE (optype)) == ARRAY_TYPE)
+		optype = TREE_TYPE (optype);
 
 	      /* Fail when the array bound is unknown or zero.  */
-	      val = TYPE_SIZE_UNIT (type);
+	      val = TYPE_SIZE_UNIT (optype);
 	      if (!val || integer_zerop (val))
 		return false;
 	      val = fold_build2 (MINUS_EXPR, TREE_TYPE (val), val,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]