RFC: allowing fold to change location of args (PR/41451)

Aldy Hernandez aldyh@redhat.com
Mon Oct 26 19:57:00 GMT 2009


> That wasn't my question.
> 
>      tem = fold_build2_loc (loc, code, type,
>                             fold_convert_loc (loc, TREE_TYPE (op0),
>                                               TREE_OPERAND (arg0, 1)), op1);
>      protected_set_expr_location (tem, loc);
> 
> here tem is built by calling fold_build2_loc.  So why is the location
> of tem not loc after that.  This sounds like the actual bug
> (and the protected_set_expr_location should be redundant).

Indeed, the culprit is fold_convert_loc which is not setting the location.

OK for trunk pending tests?

	PR bootstrap/41451
	* fold-const.c (fold_convert_loc): Return a new node if all we're
	going to change is the location.
	(fold_binary_loc): Do not call protected_set_expr_location if
	unecessary.

Index: fold-const.c
===================================================================
--- fold-const.c	(revision 153549)
+++ fold-const.c	(working copy)
@@ -2635,7 +2635,13 @@ fold_convert_loc (location_t loc, tree t
   tree tem;
 
   if (type == orig)
-    return arg;
+    {
+      if (!CAN_HAVE_LOCATION_P (arg) || EXPR_LOCATION (arg) == loc)
+	return arg;
+      arg = copy_node (arg);
+      SET_EXPR_LOCATION (arg, loc);
+      return arg;
+    }
 
   if (TREE_CODE (arg) == ERROR_MARK
       || TREE_CODE (type) == ERROR_MARK
@@ -10134,7 +10140,6 @@ fold_binary_loc (location_t loc,
 	  tem = fold_build2_loc (loc, code, type,
 			     fold_convert_loc (loc, TREE_TYPE (op0),
 					       TREE_OPERAND (arg0, 1)), op1);
-	  protected_set_expr_location (tem, loc);
 	  tem = build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0), tem);
 	  goto fold_binary_exit;
 	}
@@ -10144,7 +10149,6 @@ fold_binary_loc (location_t loc,
 	  tem = fold_build2_loc (loc, code, type, op0,
 			     fold_convert_loc (loc, TREE_TYPE (op1),
 					       TREE_OPERAND (arg1, 1)));
-	  protected_set_expr_location (tem, loc);
 	  tem = build2 (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0), tem);
 	  goto fold_binary_exit;
 	}



More information about the Gcc mailing list