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]

[patch] fold-const.c (fold): Clean up use of variable "t".


Hi,

Attached is a patch to clean up use of variable "t".

I thought the use of variable "t" in fold() is a bit dirty.  Normally,
cases for different tree codes end with "return t;" to return the
original expression, but sometimes "t" is used as a temporary
variable.  It turns out that all those uses of "t" can be localized.
That is, once "t" is modified, we can prevent the new value from going
out of the scope where "t" is modified by returning from the function.

After cleaning up those use of "t", I noticed that tests like
"t == orig_t" would always be true because now nobody modifies "t", so
I removed those if statements whose those conditions.  Consequently,
"orig_t" became useless, so I removed that, too.

Now, some people may not like to declare a variable whose name is also
used in an outer scope, but IMHO that would be a separate problem as
addressing this problem would unnecessarily complicate the patch.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2004-03-19  Kazu Hirata  <kazu@cs.umass.edu>

	* fold-const.c (fold): Declare "t" locally if needed
	temporarily.  Remove "orig_t".

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.347
diff -u -r1.347 fold-const.c
--- fold-const.c	17 Mar 2004 05:30:55 -0000	1.347
+++ fold-const.c	18 Mar 2004 03:57:21 -0000
@@ -5394,7 +5394,7 @@
 tree
 fold (tree expr)
 {
-  tree t = expr, orig_t;
+  const tree t = expr;
   tree t1 = NULL_TREE;
   tree tem;
   tree type = TREE_TYPE (expr);
@@ -5415,8 +5415,6 @@
   if (kind == 'c')
     return t;
 
-  orig_t = t;
-
   if (code == NOP_EXPR || code == FLOAT_EXPR || code == CONVERT_EXPR)
     {
       tree subop;
@@ -5523,10 +5521,10 @@
 		  || (TREE_CODE (arg0) == BIT_AND_EXPR
 		      && integer_onep (TREE_OPERAND (arg0, 1)))))))
     {
-      t = fold (build (code == BIT_AND_EXPR ? TRUTH_AND_EXPR
-		       : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR
-		       : TRUTH_XOR_EXPR,
-		       type, arg0, arg1));
+      tree t = fold (build (code == BIT_AND_EXPR ? TRUTH_AND_EXPR
+			    : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR
+			    : TRUTH_XOR_EXPR,
+			    type, arg0, arg1));
 
       if (code == EQ_EXPR)
 	t = invert_truthvalue (t);
@@ -5543,6 +5541,7 @@
 	{
 	  tree arg01 = TREE_OPERAND (arg0, 1);
 	  tree arg02 = TREE_OPERAND (arg0, 2);
+	  tree t;
 	  if (! VOID_TYPE_P (TREE_TYPE (arg01)))
 	    arg01 = fold (build1 (code, type, arg01));
 	  if (! VOID_TYPE_P (TREE_TYPE (arg02)))
@@ -5744,8 +5743,7 @@
 	  /* Don't leave an assignment inside a conversion
 	     unless assigning a bitfield.  */
 	  tree prev = TREE_OPERAND (t, 0);
-	  if (t == orig_t)
-	    t = copy_node (t);
+	  tree t = copy_node (expr);
 	  TREE_OPERAND (t, 0) = TREE_OPERAND (prev, 1);
 	  /* First do the assignment, then return converted constant.  */
 	  t = build (COMPOUND_EXPR, TREE_TYPE (t), prev, fold (t));
@@ -5812,16 +5810,16 @@
 	{
 	  tree m = purpose_member (arg1, CONSTRUCTOR_ELTS (arg0));
 	  if (m)
-	    t = TREE_VALUE (m);
+	    return TREE_VALUE (m);
 	}
       return t;
 
     case RANGE_EXPR:
       if (TREE_CONSTANT (t) != wins)
 	{
-	  if (t == orig_t)
-	    t = copy_node (t);
+	  tree t = copy_node (expr);
 	  TREE_CONSTANT (t) = wins;
+	  return t;
 	}
       return t;
 
@@ -5851,20 +5849,21 @@
 		  int overflow = neg_double (TREE_INT_CST_LOW (arg0),
 					     TREE_INT_CST_HIGH (arg0),
 					     &low, &high);
-		  t = build_int_2 (low, high);
+		  tree t = build_int_2 (low, high);
 		  TREE_TYPE (t) = type;
 		  TREE_OVERFLOW (t)
 		    = (TREE_OVERFLOW (arg0)
 		       | force_fit_type (t, overflow));
 		  TREE_CONSTANT_OVERFLOW (t)
 		    = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0);
+		  return t;
 		}
 	    }
 	  else if (TREE_CODE (arg0) == REAL_CST)
 	    {
 	      if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg0)))
-		t = build_real (type,
-				REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
+		return build_real (type,
+				   REAL_VALUE_NEGATE (TREE_REAL_CST (arg0)));
 	    }
 	}
       else if (TREE_CODE (arg0) == NEGATE_EXPR)
@@ -5906,12 +5905,13 @@
     case BIT_NOT_EXPR:
       if (wins)
 	{
-	  t = build_int_2 (~ TREE_INT_CST_LOW (arg0),
-			   ~ TREE_INT_CST_HIGH (arg0));
+	  tree t = build_int_2 (~ TREE_INT_CST_LOW (arg0),
+				~ TREE_INT_CST_HIGH (arg0));
 	  TREE_TYPE (t) = type;
 	  force_fit_type (t, 0);
 	  TREE_OVERFLOW (t) = TREE_OVERFLOW (arg0);
 	  TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (arg0);
+	  return t;
 	}
       else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
 	return TREE_OPERAND (arg0, 0);
@@ -7276,7 +7276,8 @@
 	    if (REAL_VALUE_ISNAN (cst)
 		&& ! HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1))))
 	      {
-		t = (code == NE_EXPR) ? integer_one_node : integer_zero_node;
+		tree t =
+		  (code == NE_EXPR) ? integer_one_node : integer_zero_node;
 		return omit_one_operand (type, fold_convert (type, t), arg0);
 	      }
 
@@ -7853,6 +7854,8 @@
 		  && (integer_zerop (low_result)
 		      || integer_onep (low_result)))
 		{
+		  tree t;
+
 		  /* Make a 3-bit mask with the high-order bit being the
 		     value for `>', the next for '=', and the low for '<'.  */
 		  switch ((integer_onep (high_result) * 4)


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